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

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

Add data access methods to retrieve all provider information and add
tests to exercise these new methods.

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 testGetAllProviderInfo(self):
61        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
62        self.files.append(fileName)
63
64        pis = self.dao.getAllProviderInfo()
65        self.assertEquals(1, len(pis))
66        self.assertEquals(PROVIDER_INFO_1, pis[0])
67
68
69    def testInvalidGetAllProviderInfo(self):
70        pis = self.dao.getAllProviderInfo()
71        self.assertEquals([], pis)
72
73
74    def testGetRepositoryInfo(self):
75        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2)
76        self.files.append(fileName)
77
78        ri = self.dao.getRepositoryInfo(PROVIDER_INFO_2.name, VALID_REP_NAME_1)
79        self.assertEquals(VALID_REP_NAME_1, ri.name)
80        self.assertEquals(VALID_REP_URL, ri.url)
81        self.assertEquals(VALID_DIF_DATA_FORMAT, ri.dataFormat)
82        self.assertEquals(VALID_SET_SPEC_1, ri.setSpec)
83        self.assertEquals(VALID_MODIFICATION_DATE, ri.modificationDate)
84        self.assertEquals('', ri.harvestTime)
85        self.assertEquals(False, ri.splitBySet)
86
87
88    def testInvalidGetProviderInfo(self):
89        ri = self.dao.getRepositoryInfo(PROVIDER_INFO_1, VALID_REP_NAME_1)
90        self.assertEquals(None, ri)
91
92
93    def testGetProviderInfoForUser(self):
94        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
95        self.files.append(fileName)
96        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2)
97        self.files.append(self.dao.client.pic.backupFile)
98        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_3)
99        # NB, the backups are created very quickly so may end up with the same name
100        if self.dao.client.pic.backupFile not in self.files:
101            self.files.append(self.dao.client.pic.backupFile)
102
103        pis = self.dao.getProviderInfoForUser(VALID_USER)
104        self.assertEquals(2, len(pis))
105        for pi in pis:
106            self.assertTrue(pi.name in VALID_PROVIDER_NAMES)
107
108
109    def testGetProviderInfoForAdminUser(self):
110        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_1)
111        self.files.append(fileName)
112        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_2)
113        self.files.append(self.dao.client.pic.backupFile)
114        pi, fileName = self.dao.createProviderInfo(PROVIDER_INFO_3)
115        # NB, the backups are created very quickly so may end up with the same name
116        if self.dao.client.pic.backupFile not in self.files:
117            self.files.append(self.dao.client.pic.backupFile)
118
119        pis = self.dao.getProviderInfoForUser(VALID_ADMIN_USER)
120        self.assertEquals(3, len(pis))
121        for pi in pis:
122            self.assertTrue(pi.name in ALL_VALID_PROVIDER_NAMES)
123
124
125    def testInvalidGetProviderInfoForUser(self):
126        pis = self.dao.getProviderInfoForUser(INVALID_USER)
127        self.assertEquals([], pis)
128       
129
130    def tearDown(self):
131       
132        for file in self.files:
133            self.dao.client._deleteProviderInfoFile(file)
134           
135        # lastly remove the directories
136        os.rmdir(self.dao.client.backupDir)
137        os.rmdir(self.dao.client.dataDir)
Note: See TracBrowser for help on using the repository browser.