@@ -20,9 +20,9 @@ def setUp(self):
2020 def tearDown (self ):
2121 pass
2222
23- def jwtHeader (self ):
23+ def jwtHeader (self , identity = "test" ):
2424 with server .app .test_request_context ():
25- access_token = create_access_token ('test' )
25+ access_token = create_access_token (identity )
2626 return {'Authorization' : 'Bearer {}' .format (access_token )}
2727
2828 def test_getdocument_pdf (self ):
@@ -136,5 +136,109 @@ def test_country_aggregated_all_report_html(self):
136136 success = False
137137 self .assertEqual (200 , response .status_code , "Status code is not OK" )
138138 self .assertTrue (success , "Response is not a valid HTML" )
139- self .assertTrue (html .count ("Country name: " ) == 255 , "Generated HTML does not contain the expected number of countries" )
139+ self .assertEqual (html .count ("Country name: " ), 255 , "Generated HTML does not contain the expected number of countries" )
140140
141+ def test_country_aggregated_single_report_bad_html (self ):
142+ params = {
143+ "feature" : "4,5,6" ,
144+ "single_report" : 1
145+ }
146+ response = self .app .get ('/Country.html?' + urlencode (params ), headers = self .jwtHeader ())
147+ success = False
148+ html = None
149+ try :
150+ error = response .data .decode ("utf-8" )
151+ except :
152+ success = False
153+ self .assertEqual (500 , response .status_code , "Request didn't fail with internal server error" )
154+ self .assertEqual (error , "Failed to compile report" )
155+
156+ def test_country_aggregated_single_report_html (self ):
157+ params = {
158+ "feature" : "4,5,6" ,
159+ "single_report" : 1
160+ }
161+ response = self .app .get ('/Country_single.html?' + urlencode (params ), headers = self .jwtHeader ())
162+ success = False
163+ html = None
164+ try :
165+ html = response .data .decode ("utf-8" )
166+ success = "<html" in html
167+ except :
168+ success = False
169+ self .assertEqual (200 , response .status_code , "Status code is not OK" )
170+ self .assertTrue (success , "Response is not a valid HTML" )
171+ self .assertEqual (html .count ("Country name: " ), 3 , "Generated HTML does not contain the expected number of countries" )
172+ self .assertTrue ("Bolivia" in html , "Response does not contain Bolivia" )
173+ self .assertTrue ("Peru" in html , "Response does not contain Peru" )
174+ self .assertTrue ("Argentina" in html , "Response does not contain Argentina" )
175+
176+ def test_point_report_unpermitted_subreport_html (self ):
177+ params = {
178+ "feature" : "1"
179+ }
180+ response = self .app .get ('subdir/Point.html?' + urlencode (params ), headers = self .jwtHeader ())
181+ success = False
182+ html = None
183+ try :
184+ html = response .data .decode ("utf-8" )
185+ success = "<html" in html
186+ except :
187+ success = False
188+ self .assertEqual (200 , response .status_code , "Status code is not OK" )
189+ self .assertTrue (success , "Response is not a valid HTML" )
190+ self .assertTrue ("Point description: Example Point" in html , "Response does not contain 'Point description: Example Point'" )
191+ self .assertTrue ("Country name:" not in html , "Response contains 'Country name:'" )
192+
193+ def test_point_report_permitted_subreport_html (self ):
194+ params = {
195+ "feature" : "1" ,
196+ "COUNTRY_ID" : "5"
197+ }
198+ response = self .app .get ('subdir/Point.html?' + urlencode (params ), headers = self .jwtHeader ("admin" ))
199+ success = False
200+ html = None
201+ try :
202+ html = response .data .decode ("utf-8" )
203+ success = "<html" in html
204+ except :
205+ success = False
206+ self .assertEqual (200 , response .status_code , "Status code is not OK" )
207+ self .assertTrue (success , "Response is not a valid HTML" )
208+ self .assertTrue ("Point description: Example Point" in html , "Response does not contain 'Point description: Example Point'" )
209+ self .assertTrue ("Country name: Peru" in html , "Response does not contain 'Country name: Peru'" )
210+
211+ def test_point_report_precompiled_permit_subreports_html (self ):
212+ params = {
213+ "feature" : "1" ,
214+ "COUNTRY_ID" : "5"
215+ }
216+ os .environ ['PERMIT_SUBREPORTS' ] = '1'
217+ response = self .app .get ('subdir/Point.html?' + urlencode (params ), headers = self .jwtHeader ("admin" ))
218+ del os .environ ['PERMIT_SUBREPORTS' ]
219+ success = False
220+ html = None
221+ try :
222+ html = response .data .decode ("utf-8" )
223+ success = "<html" in html
224+ except :
225+ success = False
226+ self .assertEqual (200 , response .status_code , "Status code is not OK" )
227+ self .assertTrue (success , "Response is not a valid HTML" )
228+ self .assertTrue ("Point description: Example Point" in html , "Response does not contain 'Point description: Example Point'" )
229+ self .assertTrue ("Country name: Peru" in html , "Response does not contain 'Country name: Peru'" )
230+
231+ def test_static_report_html (self ):
232+ params = {
233+ }
234+ response = self .app .get ('Static.html?' + urlencode (params ), headers = self .jwtHeader ("admin" ))
235+ success = False
236+ html = None
237+ try :
238+ html = response .data .decode ("utf-8" )
239+ success = "<html" in html
240+ except :
241+ success = False
242+ self .assertEqual (200 , response .status_code , "Status code is not OK" )
243+ self .assertTrue (success , "Response is not a valid HTML" )
244+ self .assertTrue ("Static text" in html , "Response does not contain 'Static text'" )
0 commit comments