source: mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py @ 8433

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py@8433
Revision 8433, 5.6 KB checked in by mnagni, 7 years ago (diff)

Two main new features:
1) the migration generate a report. The report is sent by mail to the subscribers defined in the settings.py
2) require to display a missing observation adds a message on the page and hides the some fields in the html form
3) a new javascript library (commons.js)

Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 7 Mar 2012
30
31@author: Maurizio Nagni
32'''
33from unittest import TestCase
34from libs.commons_db import DbManager
35from libs.migration.MigrationEPB import MigrationEPBFactory
36from libs.migration.processor.loadResources import LoadResources
37from libs.migration.db.classes import MigrationObject
38from libs.migration.processor.commons import DO_BADC, DS_pUBLISHED, DS_PUBLISHED,\
39    DO_NEODC
40from MolesManager.moles3epb import Moles3EPBFactory
41from libs.migration.processor.migrationProcess import MigrationProcess
42from testconfig import MIGRATION_DB_CONNECTION,\
43    MIGRATION_DB_SCRIPT, MOLES3_DB_SCRIPT, MOLES3_DB_CONNECTION, INFO_DB_CONNECTION
44from libs.migration.InfodbEPB import InfodbEPBFactory
45from MolesManager.settings import EVENTS_DB
46from libs.migration.client import EPBRepo, generateMigrationReport
47from django.core.mail import send_mail
48
49class LoadResourceTest(TestCase):
50    '''
51    classdocs
52    '''
53   
54    def setUp(self):
55        migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT, sql_echo=True)
56        #migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT)     
57
58        molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, sql_echo=True, session_event_manager=EVENTS_DB)
59        #molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, session_event_manager=EVENTS_DB)         
60       
61       
62        #infoDB = DbManager(INFO_DB_CONNECTION, sql_echo=True)
63        infoDB = DbManager(INFO_DB_CONNECTION)       
64        infoFactory = InfodbEPBFactory(infoDB)
65       
66        moles3Factory = Moles3EPBFactory(molesDB)
67        migrationFactory = MigrationEPBFactory(migrationDB)
68
69        self.epbRepo = EPBRepo(moles3Factory.createEPB() , \
70                               migrationFactory.createEPB(), \
71                               infoFactory.createEPB())
72
73        if False:
74            lr = LoadResources(self.epbRepo)
75            ex = lr.process()
76            for e in ex:
77                print e
78               
79        self.mp = MigrationProcess(self.epbRepo)
80
81    def testMigrationProcess(self):                       
82        #dataEntity.doc_status = DS_pUBLISHED
83        #dataEntity.doc_name = 'dataent_csip.atom'
84       
85        #Has a DOI
86        #dataEntity.doc_status = DS_PUBLISHED
87        #dataEntity.doc_name = 'DE_095e8da2-cf02-11e0-8b7a-00e081470265.atom'
88       
89        #Has 3 DOI
90        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_chobs.atom')
91       
92        #IASI
93        self.processDataEntity(DO_NEODC, DS_pUBLISHED, 'dataent_12417810458627666.atom')
94        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_VIRTEM.atom')
95        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12162569915925921.atom')
96             
97        #ECMWF
98        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-ERA.atom')
99        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-OP.atom')
100        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12458543158227759.atom')               
101        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-E40.atom')
102        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-TRJ.atom')
103       
104       
105        self.processDataEntity(DO_NEODC, DS_pUBLISHED, 'dataent_11750994700119761.atom')
106        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_ECMWF-TRJ.atom')
107        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_UGAMPO3.atom')
108        self.processDataEntity(DO_BADC, DS_pUBLISHED, 'dataent_12282368470627062.atom')                       
109       
110        #self.processDataEntity()             
111
112       
113    def processDataEntity(self, doc_owner = None, doc_status = None, doc_name = None):
114        dataEntity = None
115        if doc_owner is not None and doc_status is not None and doc_name is not None:
116            dataEntity = MigrationObject()
117            dataEntity.doc_owner = doc_owner       
118            dataEntity.doc_status = doc_status
119            dataEntity.doc_name = doc_name
120        ex = self.mp.process(dataEntity)
121        generateMigrationReport(ex)
122
Note: See TracBrowser for help on using the repository browser.