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

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

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

  • Property svn:executable set to *
Line 
1'''
2 Test class for exercising the editor file client module
3 
4 @author: C Byrom, Tessella Apr 2009
5'''
6import unittest
7import logging, datetime
8from oai_info_editor.dal.editorfileclient import *
9from oai_info_editor.model.providerinfo import ProviderInfo
10from oai_info_editor.tests.testdata.testconstants import *
11from ndg.common.src.models.myconfig import myConfig
12
13class testEditorFileClient(unittest.TestCase):
14
15    def setUp(self):
16        '''
17        set up data used in the tests.
18        '''
19        self.client = EditorFileClient(configFile = myConfig(EDITOR_CONFIG_FILE))
20        self.files = []
21
22    def testInvalidConfigFile(self):
23        self.assertRaises(ValueError, myConfig, DUMMY_PIC_FILENAME)
24
25    def testIncompleteConfigFile(self):
26        self.assertRaises(ValueError, EditorFileClient, 
27                          configFile = myConfig(INVALID_EDITOR_CONFIG_FILE))
28
29    def testMissingConfigFile(self):
30        self.assertRaises(ValueError, myConfig, "blah")
31
32    def testCreateProviderInfo(self):
33        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
34        self.files.append(fileName)
35        self.assertEquals(1, len(self.client.pic.providerInfos))
36        self.assertEquals(VALID_PROVIDER_NAME_1, self.client.pic.providerInfos[0].name)
37        self.assertEquals('1', self.client.pic.version)
38        self.assertEquals('1', self.client.pic.providerInfos[0].repositoryInfos[0].version)
39       
40    def testCreateProviderInfoMultiple(self):
41        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
42        self.files.append(fileName)
43        self.assertEquals(1, len(self.client.pic.providerInfos))
44        self.assertEquals('1', self.client.pic.version)
45
46        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2)
47        self.files.append(self.client.pic.backupFile)
48        self.assertEquals(2, len(self.client.pic.providerInfos))
49        self.assertEquals('2', self.client.pic.version)
50
51        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_3)
52        # NB, the backups are created very quickly so may end up with the same name
53        if self.client.pic.backupFile not in self.files:
54            self.files.append(self.client.pic.backupFile)
55        self.assertEquals(self.files[0], self.client.pic.fileName)
56        self.assertEquals(3, len(self.client.pic.providerInfos))
57        self.assertEquals('3', self.client.pic.version)
58
59
60    def testInvalidUpdateProviderInfo(self):
61        self.assertRaises(ValueError, self.client.updateProviderInfo, PROVIDER_INFO_3)
62       
63       
64    def testUpdateProviderInfo(self):
65        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
66        self.files.append(fileName)
67        self.assertEquals(1, len(self.client.pic.providerInfos))
68        self.assertEquals('1', self.client.pic.version)
69
70        pi = self.client.updateProviderInfo(pi)
71        self.files.append(self.client.pic.backupFile)
72        self.assertEquals(1, len(self.client.pic.providerInfos))
73        self.assertEquals('2', self.client.pic.version)
74       
75       
76    def testUpdateProviderInfoChangeName(self):
77        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
78        self.files.append(fileName)
79        self.assertEquals(1, len(self.client.pic.providerInfos))
80        self.assertEquals('1', self.client.pic.version)
81        self.assertEquals(VALID_PROVIDER_NAME_1, pi.name)
82       
83        pi.name = VALID_PROVIDER_NAME_2
84        pi = self.client.updateProviderInfo(pi)
85        self.files.append(self.client.pic.backupFile)
86        self.assertEquals(1, len(self.client.pic.providerInfos))
87        self.assertEquals('2', self.client.pic.version)
88        self.assertEquals(VALID_PROVIDER_NAME_2, pi.name)
89        pi.name = VALID_PROVIDER_NAME_1
90       
91       
92    def testUpdateProviderInfoMultiple(self):
93        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
94        self.files.append(fileName)
95        self.assertEquals(1, len(self.client.pic.providerInfos))
96        self.assertEquals('1', self.client.pic.version)
97        self.assertEquals(VALID_DIF_DATA_FORMAT, pi.repositoryInfos[0].dataFormat)
98
99        pi.repositoryInfos[0].dataFormat = VALID_MDIP_DATA_FORMAT
100        pi = self.client.updateProviderInfo(pi)
101        self.files.append(self.client.pic.backupFile)
102        self.assertEquals('2', self.client.pic.version)
103        self.assertEquals(VALID_MDIP_DATA_FORMAT, pi.repositoryInfos[0].dataFormat)
104        self.assertEquals(1, len(self.client.pic.providerInfos))
105        self.assertEquals('2', self.client.pic.version)
106
107        pi.repositoryInfos[0].dataFormat = VALID_DC_DATA_FORMAT
108        pi = self.client.updateProviderInfo(pi)
109        # NB, the backups are created very quickly so may end up with the same name
110        if self.client.pic.backupFile not in self.files:
111            self.files.append(self.client.pic.backupFile)
112
113        self.assertEquals('3', self.client.pic.version)
114        self.assertEquals(VALID_DC_DATA_FORMAT, pi.repositoryInfos[0].dataFormat)
115        self.assertEquals(1, len(self.client.pic.providerInfos))
116        self.assertEquals('3', self.client.pic.version)
117
118       
119    def testDeleteProviderInfo(self):
120        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
121        self.files.append(fileName)
122        self.assertEquals(1, len(self.client.pic.providerInfos))
123        self.assertEquals('1', self.client.pic.version)
124        self.client.deleteProviderInfo(pi.name)
125        self.files.append(self.client.pic.backupFile)
126        self.assertEquals(0, len(self.client.pic.providerInfos))
127        self.assertEquals('2', self.client.pic.version)
128
129
130    def testGetProviderInfo(self):
131        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
132        self.files.append(fileName)
133
134        pi = self.client.getProviderInfo(PROVIDER_INFO_1.name)
135        self.assertEquals(PROVIDER_INFO_1, pi)
136
137
138    def testInvalidGetProviderInfo(self):
139        pi = self.client.getProviderInfo(PROVIDER_INFO_1)
140        self.assertEquals(None, pi)
141
142
143    def testGetRepositoryInfo(self):
144        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2)
145        self.files.append(fileName)
146
147        ri = self.client.getRepositoryInfo(PROVIDER_INFO_2.name, VALID_REP_NAME_1)
148        self.assertEquals(VALID_REP_NAME_1, ri.name)
149        self.assertEquals(VALID_REP_URL, ri.url)
150        self.assertEquals(VALID_DIF_DATA_FORMAT, ri.dataFormat)
151        self.assertEquals(VALID_SET_SPEC_1, ri.setSpec)
152        self.assertEquals(VALID_MODIFICATION_DATE, ri.modificationDate)
153        self.assertEquals('', ri.harvestTime)
154        self.assertEquals(False, ri.splitBySet)
155
156
157    def testInvalidGetProviderInfo(self):
158        ri = self.client.getRepositoryInfo(PROVIDER_INFO_1, VALID_REP_NAME_1)
159        self.assertEquals(None, ri)
160
161
162    def testGetProviderInfoForUser(self):
163        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
164        self.files.append(fileName)
165        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2)
166        self.files.append(self.client.pic.backupFile)
167        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_3)
168        # NB, the backups are created very quickly so may end up with the same name
169        if self.client.pic.backupFile not in self.files:
170            self.files.append(self.client.pic.backupFile)
171
172        pis = self.client.getProviderInfoForUser(VALID_USER)
173        self.assertEquals(2, len(pis))
174        for pi in pis:
175            self.assertTrue(pi.name in VALID_PROVIDER_NAMES)
176
177
178    def testInvalidGetProviderInfoForUser(self):
179        pis = self.client.getProviderInfoForUser(INVALID_USER)
180        self.assertEquals([], pis)
181       
182
183    def testGetProviderInfoForAdminUser(self):
184        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
185        self.files.append(fileName)
186        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2)
187        self.files.append(self.client.pic.backupFile)
188        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_3)
189        # NB, the backups are created very quickly so may end up with the same name
190        if self.client.pic.backupFile not in self.files:
191            self.files.append(self.client.pic.backupFile)
192
193        pis = self.client.getProviderInfoForUser(VALID_ADMIN_USER)
194        self.assertEquals(3, len(pis))
195        for pi in pis:
196            self.assertTrue(pi.name in ALL_VALID_PROVIDER_NAMES)
197
198
199       
200    def tearDown(self):
201       
202        for file in self.files:
203            self.client._deleteProviderInfoFile(file)
204           
205        # lastly remove the directories
206        os.rmdir(self.client.backupDir)
207        os.rmdir(self.client.dataDir)
208           
209       
Note: See TracBrowser for help on using the repository browser.