source: TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/dal/testproviderinfodaowithfileclient.py @ 5238

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/trunk/OAIInfoEditor/oai_info_editor/tests/dal/testproviderinfodaowithfileclient.py@5238
Revision 5238, 4.7 KB checked in by cbyrom, 11 years ago (diff)

Add code to retrieve repository info by name - and add appropriate tests.

Line 
1'''
2 Test class for exercising the providerinfodao module
3 
4 @author: C Byrom, Tessella Apr 2009
5'''
6import unittest
7import logging, datetime
8from oai_info_editor.dal.providerinfodao import *
9from oai_info_editor.tests.testdata.testconstants import *
10
11
12class testProviderInfoDAO(unittest.TestCase):
13
14    def setUp(self):
15        '''
16        set up data used in the tests.
17        '''
18        self.dao = createDAOWithClient(client = FILE_CLIENT_TYPE, 
19                                       configFile = EDITOR_CONFIG_FILE)
20        self.files = []
21
22    def testCreateProviderInfoNoRecords(self):
23        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
24        self.files.append(fileName)
25        self.assertEquals(1, len(self.dao.client.pic.providerInfos))
26        self.assertEquals('1', self.dao.client.pic.version)
27       
28    def testCreateProviderInfo(self):
29        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
30        self.files.append(fileName)
31        self.assertEquals(1, len(self.dao.client.pic.providerInfos))
32        self.assertEquals('1', self.dao.client.pic.version)
33
34    def testInvalidUpdateProviderInfo(self):
35        self.assertRaises(ValueError, self.dao.updateProviderInfo, PROVIDER_INFO_3)
36
37    def testUpdateProviderInfo(self):
38        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
39        self.files.append(fileName)
40        self.assertEquals(1, len(self.dao.client.pic.providerInfos))
41        self.assertEquals('1', self.dao.client.pic.version)
42        pi = self.dao.updateProviderInfo(pi)
43        self.files.append(self.dao.client.pic.backupFile)
44        self.assertEquals(1, len(self.dao.client.pic.providerInfos))
45        self.assertEquals('2', self.dao.client.pic.version)
46
47
48    def testGetProviderInfo(self):
49        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
50        self.files.append(fileName)
51
52        pi = self.dao.getProviderInfo(PROVIDER_INFO_1.name)
53        self.assertEquals(VALID_PROVIDER_NAME_1, pi.name)
54
55    def testInvalidGetProviderInfo(self):
56        pi = self.dao.getProviderInfo(PROVIDER_INFO_1)
57        self.assertEquals(None, pi)
58
59
60    def testGetRepositoryInfo(self):
61        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2)
62        self.files.append(fileName)
63
64        ri = self.dao.getRepositoryInfo(PROVIDER_INFO_2.name, VALID_REP_NAME_1)
65        self.assertEquals(VALID_REP_NAME_1, ri.name)
66        self.assertEquals(VALID_REP_URL, ri.url)
67        self.assertEquals(VALID_DIF_DATA_FORMAT, ri.dataFormat)
68        self.assertEquals(VALID_SET_SPEC_1, ri.setSpec)
69        self.assertEquals(VALID_MODIFICATION_DATE, ri.modificationDate)
70        self.assertEquals('', ri.harvestTime)
71        self.assertEquals(False, ri.splitBySet)
72
73
74    def testInvalidGetProviderInfo(self):
75        ri = self.dao.getRepositoryInfo(PROVIDER_INFO_1, VALID_REP_NAME_1)
76        self.assertEquals(None, ri)
77
78
79    def testGetProviderInfoForUser(self):
80        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
81        self.files.append(fileName)
82        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2)
83        self.files.append(self.dao.client.pic.backupFile)
84        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_3)
85        # NB, the backups are created very quickly so may end up with the same name
86        if self.dao.client.pic.backupFile not in self.files:
87            self.files.append(self.dao.client.pic.backupFile)
88
89        pis = self.dao.getProviderInfoForUser(VALID_USER)
90        self.assertEquals(2, len(pis))
91        for pi in pis:
92            self.assertTrue(pi.name in VALID_PROVIDER_NAMES)
93
94
95    def testGetProviderInfoForAdminUser(self):
96        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
97        self.files.append(fileName)
98        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2)
99        self.files.append(self.dao.client.pic.backupFile)
100        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_3)
101        # NB, the backups are created very quickly so may end up with the same name
102        if self.dao.client.pic.backupFile not in self.files:
103            self.files.append(self.dao.client.pic.backupFile)
104
105        pis = self.dao.getProviderInfoForUser(VALID_ADMIN_USER)
106        self.assertEquals(3, len(pis))
107        for pi in pis:
108            self.assertTrue(pi.name in ALL_VALID_PROVIDER_NAMES)
109
110
111    def testInvalidGetProviderInfoForUser(self):
112        pis = self.dao.getProviderInfoForUser(INVALID_USER)
113        self.assertEquals([], pis)
114       
115
116    def tearDown(self):
117       
118        for file in self.files:
119            self.dao.client._deleteProviderInfoFile(file)
120           
121        # lastly remove the directories
122        os.rmdir(self.dao.client.backupDir)
123        os.rmdir(self.dao.client.dataDir)
Note: See TracBrowser for help on using the repository browser.