Skip to content

Commit

Permalink
Use assertRaises for cleaner code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni authored and nyalldawson committed Jun 2, 2020
1 parent fabdb64 commit bcf71e0
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions tests/src/python/test_qgsserver_wfs.py
Expand Up @@ -189,7 +189,7 @@ def test_wfs_getcapabilities_100_url(self):
self.assertEqual(
"onlineResource=\"my_wfs_advertised_url\"" in item, True)

def result_compare(self, file_name, error_msg_header, header, body, expectEqual=True):
def result_compare(self, file_name, error_msg_header, header, body):
self.assert_headers(header, body)
response = header + body
reference_path = self.testdata_path + file_name
Expand All @@ -202,11 +202,7 @@ def result_compare(self, file_name, error_msg_header, header, body, expectEqual=
self.assertXMLEqual(response, expected, msg="%s\n" %
(error_msg_header))

# If do not expect equal and pass the line above, should throw and assertion error.
if not expectEqual:
self.assertFalse(True, msg='It should get different result for %s.' % error_msg_header)

def wfs_getfeature_post_compare(self, requestid, request, expectEqual=True):
def wfs_getfeature_post_compare(self, requestid, request):
project = self.testdata_path + "test_project_wfs.qgs"
assert os.path.exists(project), "Project file not found: " + project

Expand All @@ -218,8 +214,7 @@ def wfs_getfeature_post_compare(self, requestid, request, expectEqual=True):
'wfs_getfeature_{}.txt'.format(requestid),
"GetFeature in POST for '{}' failed.".format(requestid),
header,
body,
expectEqual
body
)

def test_getfeature_post(self):
Expand Down Expand Up @@ -481,7 +476,9 @@ def test_getfeature_post(self):
tests.append(('nobbox_post', template.format("")))

for id, req in expectNotEqualTests:
self.wfs_getfeature_post_compare(id, req, expectEqual=False)
errorMsg = 'Expect different XML response for %s' % id
with self.assertRaises(AssertionError, msg=errorMsg):
self.wfs_getfeature_post_compare(id, req)

for id, req in tests:
self.wfs_getfeature_post_compare(id, req)
Expand Down

0 comments on commit bcf71e0

Please sign in to comment.