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

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

Add delete functionality to front tier of oai editor. Include
message to confirm the data has been completed, as a pop up, when
the operation is done. Update tests and simplify model + dal layer.

  • 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 testGetProviderInfoForUser(self):
144        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
145        self.files.append(fileName)
146        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2)
147        self.files.append(self.client.pic.backupFile)
148        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_3)
149        # NB, the backups are created very quickly so may end up with the same name
150        if self.client.pic.backupFile not in self.files:
151            self.files.append(self.client.pic.backupFile)
152
153        pis = self.client.getProviderInfoForUser(VALID_USER)
154        self.assertEquals(2, len(pis))
155        for pi in pis:
156            self.assertTrue(pi.name in VALID_PROVIDER_NAMES)
157
158
159    def testInvalidGetProviderInfoForUser(self):
160        pis = self.client.getProviderInfoForUser(INVALID_USER)
161        self.assertEquals([], pis)
162       
163
164    def testGetProviderInfoForAdminUser(self):
165        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_1)
166        self.files.append(fileName)
167        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_2)
168        self.files.append(self.client.pic.backupFile)
169        pi, fileName = self.client.createProviderInfo(PROVIDER_INFO_3)
170        # NB, the backups are created very quickly so may end up with the same name
171        if self.client.pic.backupFile not in self.files:
172            self.files.append(self.client.pic.backupFile)
173
174        pis = self.client.getProviderInfoForUser(VALID_ADMIN_USER)
175        self.assertEquals(3, len(pis))
176        for pi in pis:
177            self.assertTrue(pi.name in ALL_VALID_PROVIDER_NAMES)
178       
179    def tearDown(self):
180       
181        for file in self.files:
182            self.client._deleteProviderInfoFile(file)
183           
184        # lastly remove the directories
185        os.rmdir(self.client.backupDir)
186        os.rmdir(self.client.dataDir)
187           
188       
Note: See TracBrowser for help on using the repository browser.