Skip to content

Commit 1e99d38

Browse files
committed
Extend test coverage
1 parent 0f57177 commit 1e99d38

File tree

10 files changed

+1322
-5
lines changed

10 files changed

+1322
-5
lines changed

tests/Country_single.jrxml

Lines changed: 533 additions & 0 deletions
Large diffs are not rendered by default.

tests/Static.jrxml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Created with Jaspersoft Studio version 6.21.3.final using JasperReports Library version 6.21.3-4a3078d20785ebe464f18037d738d12fc98c13cf -->
3+
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Static" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4c005fb8-607d-4b58-8a5a-3ae58396ac59">
4+
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
5+
<queryString>
6+
<![CDATA[]]>
7+
</queryString>
8+
<background>
9+
<band splitType="Stretch"/>
10+
</background>
11+
<title>
12+
<band height="79" splitType="Stretch"/>
13+
</title>
14+
<pageHeader>
15+
<band height="35" splitType="Stretch"/>
16+
</pageHeader>
17+
<columnHeader>
18+
<band height="61" splitType="Stretch"/>
19+
</columnHeader>
20+
<detail>
21+
<band height="125" splitType="Stretch">
22+
<textField>
23+
<reportElement x="136" y="4" width="100" height="30" uuid="2ebb22b3-61a1-4d6b-a668-6c929ec3e03d"/>
24+
<textFieldExpression><![CDATA["Static text"]]></textFieldExpression>
25+
</textField>
26+
</band>
27+
</detail>
28+
<columnFooter>
29+
<band height="45" splitType="Stretch"/>
30+
</columnFooter>
31+
<pageFooter>
32+
<band height="54" splitType="Stretch"/>
33+
</pageFooter>
34+
<summary>
35+
<band height="42" splitType="Stretch"/>
36+
</summary>
37+
</jasperReport>

tests/api_tests.py

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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'")

tests/config/default/documentConfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
},
77
"resources": {
88
"document_templates": [
9+
{
10+
"template": "Country_single",
11+
"table": "qwc_geodb.ne_10m_admin_0_countries",
12+
"primary_key": "ogc_fid",
13+
"parameter_name": "COUNTRY_ID"
14+
}
915
]
1016
}
1117
}

tests/config/default/permissions.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
{
22
"$schema": "https://github.com/qwc-services/qwc-services-core/raw/master/schemas/qwc-services-permissions.json",
3-
"users": [],
3+
"users": [{
4+
"name": "admin",
5+
"groups": [
6+
"restrictedthemes"
7+
],
8+
"roles": [
9+
"admin"
10+
]
11+
}],
412
"groups": [],
513
"roles": [
614
{
715
"role": "public",
816
"permissions": {
917
"document_templates": [
1018
"test_report",
11-
"Country"
19+
"Country",
20+
"Country_single",
21+
"subdir/Point",
22+
"Point",
23+
"Static"
24+
]
25+
}
26+
},
27+
{
28+
"role": "admin",
29+
"permissions": {
30+
"document_templates": [
31+
"subdir/Country_subreport"
1232
]
1333
}
1434
}

tests/logo.png

3.55 KB
Loading
40.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)