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

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

Use htmlfill error rendering to simplify templates for atom create +
fix routes reference in tests + fix typo.

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