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

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

Great improvement on how SA alchemy session is managed

Line 
1'''
2Created on 7 Mar 2012
3
4@author: mnagni
5'''
6from unittest import TestCase
7from libs.commons_db import DbManager
8from libs.migration.MigrationEPB import MigrationEPB, MigrationEPBFactory
9from libs.migration.processor.loadResources import LoadResources
10from libs.migration.db.classes import MigrationObject
11from libs.migration.processor.commons import DO_BADC, DS_pUBLISHED, DS_PUBLISHED
12from MolesManager.moles3epb import Moles3EPB, Moles3EPBFactory
13from libs.migration.processor.migrationProcess import MigrationProcess
14from testconfig import MIGRATION_DB_CONNECTION,\
15    MIGRATION_DB_SCRIPT, MOLES3_DB_SCRIPT, MOLES3_DB_CONNECTION, INFO_DB_CONNECTION
16from libs.migration.InfodbEPB import InfodbEPB
17from MolesManager.settings import EVENTS_DB
18from libs.migration.client import EPBRepo
19
20class LoadResourceTest(TestCase):
21    '''
22    classdocs
23    '''
24   
25    def setUp(self):
26        migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT, sql_echo=True)
27        #migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT)
28        #MigrationEPB.overrrideDBManager(migrationDB)     
29
30        molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, sql_echo=True, session_event_manager=EVENTS_DB)
31        #molesDB = DbManager(MOLES3_DB_CONNECTION, MOLES3_DB_SCRIPT, session_event_manager=EVENTS_DB)         
32       
33       
34        #infoDB = DbManager(INFO_DB_CONNECTION, sql_echo=True)
35        infoDB = DbManager(INFO_DB_CONNECTION)       
36        InfodbEPB.overrrideDBManager(infoDB)
37       
38        moles3Factory = Moles3EPBFactory(molesDB)
39        migrationFactory = MigrationEPBFactory(migrationDB)
40       
41        EPBRepo.moles3EPB = moles3Factory.createMoles3EPB() 
42        EPBRepo.migrationEPB = migrationFactory.createMigrationEPB()
43       
44        lr = LoadResources()
45        ex = lr.process()
46        for e in ex:
47            print e
48
49    def testMigrationProcess(self):       
50        mp = MigrationProcess()
51
52        dataEntity = MigrationObject()
53        dataEntity.doc_owner = DO_BADC
54               
55        #dataEntity.doc_status = DS_pUBLISHED
56        #dataEntity.doc_name = 'dataent_csip.atom'
57       
58        #Has a DOI
59        #dataEntity.doc_status = DS_PUBLISHED
60        #dataEntity.doc_name = 'DE_095e8da2-cf02-11e0-8b7a-00e081470265.atom'
61       
62        #Has 3 DOI
63        dataEntity.doc_status = DS_pUBLISHED
64        dataEntity.doc_name = 'dataent_chobs.atom'       
65               
66       
67        ex = mp.process(dataEntity)
68        #ex = []
69        #ex = mp.process()
70        for e in ex:
71            print e
72        #self._dropAllTables()
73       
74    def _dropAllTables(self):
75        session = Moles3EPB.getNewMolesSession()
76        f = open('dropAllTables.sql', 'r')
77        for line in f.readlines():
78            stripped = line.strip()
79            if len(stripped) > 0:
80                Moles3EPB.executeNative(line.strip(), session)
81        session.commit()
82        session.close()       
83       
84       
85       
Note: See TracBrowser for help on using the repository browser.