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

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

Change MILK stack to use ndgCommon instead of ndgUtils.

Line 
1"""
2Test cases for the listatom 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 ndg.common.src.clients.xmldb.eXist.existdbclient as dbc
18import ndgutilstests.testconstants as tc
19from ndgutilstests.testutils import testUtils as tu
20from milk_server.controllers.atom_editor.editorconstants import *
21import ndg.common.src.lib.htmlUtilities as utils
22from ndg.common.src.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('home')
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('home'), status = 200)
53        self.assertTrue(response.body.find(ATOM_HOME_TITLE) > -1)
54
55
56    def testExampleGranulite(self):
57        response = self.app.get(url_for('example'), status = 200)
58        self.assertTrue(response.body.find(EXAMPLE_GRANULITE_TITLE) > -1)
59
60
61    def testListAtomHome(self):
62        response = self.app.get(url_for('list'), status = 200)
63        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
64
65
66    def testListAtomSearchDataZero(self):
67        response = self.app.get(url_for('list', searchData='0'), status = 200)
68        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
69        response2 = self.app.get(url_for('list'), status = 200)
70        self.assertEquals(response2.body, response.body)
71           
72
73    def testListAtomSearchDataNonZero(self):
74        # NB, this will be ignored - in the absense of filter data specified,
75        # so should just return the standard home page
76        response = self.app.get(url_for('list', searchData='1'), status = 200)
77        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
78        response2 = self.app.get(url_for('list', searchData='0'), status = 200)
79        self.assertEquals(response.body, response2.body)
80
81
82    def testListAtomGranuleAssociationType(self):
83        response = self.app.get(url_for('list', \
84                                        associationType=utils.GRANULE_ASSOCIATION), 
85                                        status = 200)
86        self.assertTrue(response.body.find(GRANULE_ASSOCIATION_TITLE) > -1)
87
88
89    def testListAtomDeploymentAssociationType(self):
90        response = self.app.get(url_for('list', \
91                                        associationType=utils.DEPLOYMENT_ASSOCIATION), 
92                                        status = 200)
93        self.assertTrue(response.body.find(DEPLOYMENTS_ASSOCIATION_TITLE) > -1)
94
95
96    def testListAtomEntityAssociationType(self):
97        url = url_for('list', associationType=utils.ENTITY_ASSOCIATION)
98       
99        response = self.app.get(url, status = 200)
100        self.assertTrue(response.body.find(DEPLOYMENTS_DATA_ASSOCIATION_TITLE) > -1)
101
102
103    def testListAtomInvalidAssociationType(self):
104        # NB, this invalid type code will be ignored - 
105        # so should just return the standard home page
106        url = url_for('list', associationType='69')
107        response = self.app.get(url)
108
109        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
110        url = url_for(controller='atom_editor/listatom', \
111                                        action='list')
112        url = url.replace('None','')
113        response2 = self.app.get(url, status = 200)
114        self.assertEquals(response2.body, response.body)
115
116
117    def testListAtomInvalidAssociatedAtomType(self):
118        # NB, this code determines whether listed data can be added to the
119        # associated atom - so will not affect the basic list set up
120        url = url_for('list', associatedAtomType='blah')
121       
122        response = self.app.get(url, status = 200)
123        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
124        url = url_for(controller='atom_editor/listatom', \
125                                        action='list')
126        url = url.replace('None','')
127        response2 = self.app.get(url, status = 200)
128        self.assertEquals(response2.body, response.body)
129
130
131    def testListAtomAssociatedAtomID(self):
132        # NB, this code determines the return, save url - which will not be displayed
133        # without search results - so will not affect the basic list set up
134        url = url_for('list', associatedAtomID='blah')
135       
136        response = self.app.get(url, status = 200)
137        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
138        url = url_for(controller='atom_editor/listatom', \
139                                        action='list')
140        url = url.replace('None','')
141        response2 = self.app.get(url, status = 200)
142        self.assertEquals(response2.body, response.body)
143
144
145    def testListAtomWithAtomTypeAndProviderWithResults(self):
146        # NB, we've created a granule in set up, so this will return at least
147        # one result
148        url = url_for('list', searchData='1')
149        v = VTD()
150        provider = v.getVTI(VTD.BADC_TERM)
151        atomType = v.getVTI(VTD.GRANULE_TERM)
152       
153        params = {'providerID': utils.getVocabTermDataSelectValue(provider), \
154                  'atomTypeID': utils.getVocabTermDataSelectValue(atomType)}
155       
156        response = self.app.get(url, params, status = 200)
157       
158        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
159
160        # simple check that we've actually returned something different to main
161        # list page
162        url = url_for(controller='atom_editor/listatom', \
163                                        action='list')
164        url = url.replace('None','')
165        response2 = self.app.get(url, status = 200)
166        self.assertNotEquals(response2.body, response.body)
167       
168        self.assertTrue(response.body.find('Results') > -1)
169        self.assertTrue(response.body.find(NO_SEARCH_RESULTS) == -1)
170
171
172    def testListAtomWithAtomTypeAndProviderAndTitleWithResults(self):
173        # NB, we've created a granule in set up, so this will return at least
174        # one result
175        url = url_for('list', searchData='1')
176        v = VTD()
177        provider = v.getVTI(VTD.BADC_TERM)
178        atomType = v.getVTI(VTD.GRANULE_TERM)
179       
180        params = {'providerID': utils.getVocabTermDataSelectValue(provider), \
181                  'atomTypeID': utils.getVocabTermDataSelectValue(atomType), \
182                  'title':tc.title}
183       
184        response = self.app.get(url, params, status = 200)
185       
186        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
187
188        # simple check that we've actually returned something different to main
189        # list page
190        url = url_for(controller='atom_editor/listatom', \
191                                        action='list')
192        url = url.replace('None','')
193        response2 = self.app.get(url, status = 200)
194        self.assertNotEquals(response2.body, response.body)
195       
196        self.assertTrue(response.body.find('Results') > -1)
197        self.assertTrue(response.body.find(NO_SEARCH_RESULTS) == -1)
198
199
200    def testListAtomWithAtomTypeAndProviderAndTitleWithNoResults(self):
201        # NB, we've created a granule in set up, so this will return at least
202        # one result
203        url = url_for('list', searchData='1')
204        v = VTD()
205        provider = v.getVTI(VTD.BADC_TERM)
206        atomType = v.getVTI(VTD.GRANULE_TERM)
207       
208        params = {'providerID': utils.getVocabTermDataSelectValue(provider), \
209                  'atomTypeID': utils.getVocabTermDataSelectValue(atomType), \
210                  'title':'bllllllllllrrrrrrrrrrrrrrr'}
211       
212        response = self.app.get(url, params, status = 200)
213       
214        self.assertTrue(response.body.find(LIST_ATOM_TITLE) > -1)
215
216        # simple check that we've actually returned something different to main
217        # list page
218        url = url_for(controller='atom_editor/listatom', \
219                                        action='list')
220        url = url.replace('None','')
221        response2 = self.app.get(url, status = 200)
222        self.assertNotEquals(response2.body, response.body)
223       
224        self.assertTrue(response.body.find('Results') > -1)
225        self.assertTrue(response.body.find(NO_SEARCH_RESULTS) > -1)
226       
Note: See TracBrowser for help on using the repository browser.