Add test messages on fail
This commit is contained in:
parent
76a9d2f268
commit
da3f6f5d02
|
@ -9,17 +9,18 @@ BASE_URL="http://localhost:5000"
|
||||||
class WebTestCase(object):
|
class WebTestCase(object):
|
||||||
def assertPostReq(self, url, data = {}):
|
def assertPostReq(self, url, data = {}):
|
||||||
req = requests.post(url, data=data)
|
req = requests.post(url, data=data)
|
||||||
self.assertEqual(req.status_code, 200)
|
self.assertEqual(req.status_code, 200, msg="Post request unsuccessful")
|
||||||
return req
|
return req
|
||||||
|
|
||||||
def assertGetReq(self, url, params = {}):
|
def assertGetReq(self, url, params = {}):
|
||||||
req = requests.get(url, params=params)
|
req = requests.get(url, params=params)
|
||||||
self.assertEqual(req.status_code, 200)
|
self.assertEqual(req.status_code, 200, msg="Get request unsuccessful")
|
||||||
return req
|
return req
|
||||||
|
|
||||||
def assertGetStatusReq(self, expected_status, url, params = {}):
|
def assertGetStatusReq(self, expected_status, url, params = {}):
|
||||||
req = requests.get(url, params=params, allow_redirects=False)
|
req = requests.get(url, params=params, allow_redirects=False)
|
||||||
self.assertEqual(req.status_code, expected_status)
|
self.assertEqual(req.status_code, expected_status, msg="Returned status code does not match the expected one")
|
||||||
|
|
||||||
return req
|
return req
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,11 +40,17 @@ class SchortRegressionTests(unittest.TestCase, WebTestCase):
|
||||||
short_url = req.text
|
short_url = req.text
|
||||||
self.assertNotEqual(short_url, BASE_URL + "/", msg="Created short link cannot be equal to the root URL")
|
self.assertNotEqual(short_url, BASE_URL + "/", msg="Created short link cannot be equal to the root URL")
|
||||||
|
|
||||||
|
def test_empty_wish_id(self):
|
||||||
|
"""Test a request with no wishId as all"""
|
||||||
|
req = self.assertPostReq(BASE_URL + "/", data={"url" : "https://github.com/sqozz/schort"})
|
||||||
|
self.assertEqual(req.status_code, 200, msg="Could not handle a request without wishId in the parameter-list")
|
||||||
|
|
||||||
|
|
||||||
class SchortShortLinkCase(object):
|
class SchortShortLinkCase(object):
|
||||||
pass
|
pass
|
||||||
shortID = ""
|
shortID = ""
|
||||||
shortDest = ""
|
shortDest = ""
|
||||||
|
req = None
|
||||||
|
|
||||||
def test_resolve(self):
|
def test_resolve(self):
|
||||||
"""Test basic resolving capabilites of schort"""
|
"""Test basic resolving capabilites of schort"""
|
||||||
|
@ -74,20 +81,21 @@ class SchortCustomIdTests(unittest.TestCase, SchortShortLinkCase, WebTestCase):
|
||||||
"""Test short link creation with a custom supplied wish-id"""
|
"""Test short link creation with a custom supplied wish-id"""
|
||||||
short_url = self.req.text
|
short_url = self.req.text
|
||||||
self.assertEqual(short_url, BASE_URL + "/" + self.shortID)
|
self.assertEqual(short_url, BASE_URL + "/" + self.shortID)
|
||||||
|
self.assertEqual(self.req.status_code, 200)
|
||||||
|
|
||||||
class SchortRandomIdTests(unittest.TestCase, SchortShortLinkCase, WebTestCase):
|
class SchortRandomIdTests(unittest.TestCase, SchortShortLinkCase, WebTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Set up a short url with a randomly assigned id"""
|
"""Set up a short url with a randomly assigned id"""
|
||||||
self.shortDest = "https://github.com/sqozz/schort"
|
self.shortDest = "https://github.com/sqozz/schort"
|
||||||
req = requests.post(BASE_URL + "/", data={"url" : self.shortDest})
|
self.req = requests.post(BASE_URL + "/", data={"url" : self.shortDest})
|
||||||
aquiredId = parse.urlparse(req.text)
|
aquiredId = parse.urlparse(self.req.text)
|
||||||
aquiredId = aquiredId.path.replace("/", "", 1)
|
aquiredId = aquiredId.path.replace("/", "", 1)
|
||||||
self.shortID = aquiredId
|
self.shortID = aquiredId
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
"""Test short link creation with a randomly assigned id"""
|
"""Test short link creation with a randomly assigned id"""
|
||||||
self.assertNotEqual(len(self.shortID), 0)
|
self.assertNotEqual(len(self.shortID), 0)
|
||||||
|
self.assertEqual(self.req.status_code, 200, msg="Link creation was unsuccessful")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
Loading…
Reference in a new issue