source: MILK/trunk/milk_server/milk_server/tests/functional/test_listatom.py @ 4779

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/MILK/trunk/milk_server/milk_server/tests/functional/test_listatom.py@4779
Revision 4779, 10.1 KB checked in by cbyrom, 12 years ago (diff)

Add new input to editor - to allow choice of publication state of the
atom doc. Ensure this state is maintained by including additional
lookups of collection info when retrieving atoms (NB, the state is
represented by the collection the doc is stored in - not its content).
Generalise method to get eXist client and put this in the Utilities
module for general re-use.

Line 
1"""
2Test cases for the ows retrieve controller
3
4NERC Data Grid Project
5"""
6__author__ = "C Byrom - Tessella"
7__date__ = "11/12/08"
8__copyright__ = "(C) 2008 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "b.n.lawrence@rl.ac.uk"
13__revision__ = '$Id: $'
14
15from milk_server.tests import *
16import logging, os
17import ndgUtils.lib.existdbclient as dbc
18import ndgutilstests.testconstants as tc
19from ndgutilstests.testutils import testUtils as tu
20from milk_server.controllers.atom_editor.editorconstants import *
21import ndgUtils.lib.lib.htmlUtilities as utils
22from ndgUtils.models.vocabtermdata import VocabTermData as VTD
23
24logging.basicConfig(level=logging.DEBUG,
25                        format='%(asctime)s %(filename)s:%(lineno)d %(levelname)s %(message)s')
26
27class TestListController(TestController):
28   
29    def setUp(self):
30        '''
31        set up data used in the tests.
32        '''
33        self.utils = tu('..' + os.sep + 'testData' + os.sep + 'exist.config')
34        self.createdAtom = self.utils.createAtomInEXist(tc.xmlString)
35       
36   
37    def tearDown(self):
38        self.utils.dbc.deleteAtomInExist(self.createdAtom)
39       
40   
41    def testInvalidURIIndex(self):
42        try:
43            url = url_for(controller='atom_editor/listatom', action='atomHome')
44            url += '/blah'
45            response = self.app.get(url)
46            self.fail('An exception should have been thrown here')
47        except Exception, e:
48            assert 'The resource could not be found' in e.message
49
50
51    def testAtomHome(self):
52        response = self.app.get(url_for(controller='atom_editor/listatom', \
53                                        action='atomHome'), status = 200)
54        self.assertTrue(response.body.find(ATOM_HOME_TITLE) > -1)
55
56
57    def testExampleGranulite(self):
58        response = self.app.get(url_for(controller='atom_editor/listatom', \
59                                        action='showExampleGranulite'), status = 200)
60        self.assertTrue(response.body.find(EXAMPLE_GRANULITE_TITLE) > -1)
61
62
63    def testListAtomHome(self):
64        response = self.app.get(url_for(controller='atom_editor/listatom', \
65                                        action='list'), status = 200)
66        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
67
68
69    def testListAtomSearchDataZero(self):
70        response = self.app.get(url_for(controller='atom_editor/listatom', \
71                                        action='list', searchData='0'), status = 200)
72        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
73        response2 = self.app.get(url_for(controller='atom_editor/listatom', \
74                                        action='list'), status = 200)
75        self.assertEquals(response2.body, response.body)
76           
77
78    def testListAtomSearchDataNonZero(self):
79        # NB, this will be ignored - in the absense of filter data specified,
80        # so should just return the standard home page
81        response = self.app.get(url_for(controller='atom_editor/listatom', \
82                                        action='list', searchData='1'), status = 200)
83        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
84        response2 = self.app.get(url_for(controller='atom_editor/listatom', \
85                                        action='list', searchData='0'), status = 200)
86        self.assertEquals(response.body, response2.body)
87
88
89    def testListAtomGranuleAssociationType(self):
90        response = self.app.get(url_for(controller='atom_editor/listatom', \
91                                        action='list', \
92                                        associationType=utils.GRANULE_ASSOCIATION), status = 200)
93        self.assertTrue(response.body.find(GRANULE_ASSOCIATION_TITLE) > -1)
94
95
96    def testListAtomDeploymentAssociationType(self):
97        response = self.app.get(url_for(controller='atom_editor/listatom', \
98                                        action='list', \
99                                        associationType=utils.DEPLOYMENT_ASSOCIATION), status = 200)
100        self.assertTrue(response.body.find(DEPLOYMENTS_ASSOCIATION_TITLE) > -1)
101
102
103    def testListAtomEntityAssociationType(self):
104        url = url_for(controller='atom_editor/listatom', \
105                      action='list', associationType=utils.ENTITY_ASSOCIATION)
106       
107        response = self.app.get(url, status = 200)
108        self.assertTrue(response.body.find(DEPLOYMENTS_DATA_ASSOCIATION_TITLE) > -1)
109
110
111    def testListAtomInvalidAssociationType(self):
112        # NB, this invalid type code will be ignored - 
113        # so should just return the standard home page
114        url = url_for(controller='atom_editor/listatom', \
115                                        action='list', \
116                                        associationType='69')
117        response = self.app.get(url)
118
119        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
120        url = url_for(controller='atom_editor/listatom', \
121                                        action='list')
122        url = url.replace('None','')
123        response2 = self.app.get(url, status = 200)
124        self.assertEquals(response2.body, response.body)
125
126
127    def testListAtomInvalidAssociatedAtomType(self):
128        # NB, this code determines whether listed data can be added to the
129        # associated atom - so will not affect the basic list set up
130        url = url_for(controller='atom_editor/listatom', \
131                      action='list', associatedAtomType='blah')
132       
133        response = self.app.get(url, status = 200)
134        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
135        url = url_for(controller='atom_editor/listatom', \
136                                        action='list')
137        url = url.replace('None','')
138        response2 = self.app.get(url, status = 200)
139        self.assertEquals(response2.body, response.body)
140
141
142    def testListAtomAssociatedAtomID(self):
143        # NB, this code determines the return, save url - which will not be displayed
144        # without search results - so will not affect the basic list set up
145        url = url_for(controller='atom_editor/listatom', \
146                      action='list', associatedAtomID='blah')
147       
148        response = self.app.get(url, status = 200)
149        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
150        url = url_for(controller='atom_editor/listatom', \
151                                        action='list')
152        url = url.replace('None','')
153        response2 = self.app.get(url, status = 200)
154        self.assertEquals(response2.body, response.body)
155
156
157    def testListAtomWithAtomTypeAndProviderWithResults(self):
158        # NB, we've created a granule in set up, so this will return at least
159        # one result
160        url = url_for(controller='atom_editor/listatom', \
161                      action='list', searchData='1')
162        v = VTD()
163        provider = v.getVTI(VTD.BADC_TERM)
164        atomType = v.getVTI(VTD.GRANULE_TERM)
165       
166        params = {'providerID': utils.getVocabTermDataSelectValue(provider), \
167                  'atomTypeID': utils.getVocabTermDataSelectValue(atomType)}
168       
169        response = self.app.get(url, params, status = 200)
170       
171        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
172
173        # simple check that we've actually returned something different to main
174        # list page
175        url = url_for(controller='atom_editor/listatom', \
176                                        action='list')
177        url = url.replace('None','')
178        response2 = self.app.get(url, status = 200)
179        self.assertNotEquals(response2.body, response.body)
180       
181        self.assertTrue(response.body.find('Results') > -1)
182        self.assertTrue(response.body.find(NO_SEARCH_RESULTS) == -1)
183
184
185    def testListAtomWithAtomTypeAndProviderAndTitleWithResults(self):
186        # NB, we've created a granule in set up, so this will return at least
187        # one result
188        url = url_for(controller='atom_editor/listatom', \
189                      action='list', searchData='1')
190        v = VTD()
191        provider = v.getVTI(VTD.BADC_TERM)
192        atomType = v.getVTI(VTD.GRANULE_TERM)
193       
194        params = {'providerID': utils.getVocabTermDataSelectValue(provider), \
195                  'atomTypeID': utils.getVocabTermDataSelectValue(atomType), \
196                  'title':tc.title}
197       
198        response = self.app.get(url, params, status = 200)
199       
200        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
201
202        # simple check that we've actually returned something different to main
203        # list page
204        url = url_for(controller='atom_editor/listatom', \
205                                        action='list')
206        url = url.replace('None','')
207        response2 = self.app.get(url, status = 200)
208        self.assertNotEquals(response2.body, response.body)
209       
210        self.assertTrue(response.body.find('Results') > -1)
211        self.assertTrue(response.body.find(NO_SEARCH_RESULTS) == -1)
212
213
214    def testListAtomWithAtomTypeAndProviderAndTitleWithNoResults(self):
215        # NB, we've created a granule in set up, so this will return at least
216        # one result
217        url = url_for(controller='atom_editor/listatom', \
218                      action='list', searchData='1')
219        v = VTD()
220        provider = v.getVTI(VTD.BADC_TERM)
221        atomType = v.getVTI(VTD.GRANULE_TERM)
222       
223        params = {'providerID': utils.getVocabTermDataSelectValue(provider), \
224                  'atomTypeID': utils.getVocabTermDataSelectValue(atomType), \
225                  'title':'bllllllllllrrrrrrrrrrrrrrr'}
226       
227        response = self.app.get(url, params, status = 200)
228       
229        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
230
231        # simple check that we've actually returned something different to main
232        # list page
233        url = url_for(controller='atom_editor/listatom', \
234                                        action='list')
235        url = url.replace('None','')
236        response2 = self.app.get(url, status = 200)
237        self.assertNotEquals(response2.body, response.body)
238       
239        self.assertTrue(response.body.find('Results') > -1)
240        self.assertTrue(response.body.find(NO_SEARCH_RESULTS) > -1)
241       
Note: See TracBrowser for help on using the repository browser.