Split tests by cases
This commit is contained in:
parent
ef113b907f
commit
5c7b089080
|
@ -5,13 +5,7 @@ import requests
|
|||
|
||||
BASE_URL="http://localhost:5000"
|
||||
|
||||
class SchortFunctionalTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# maybe later
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
# maybe later
|
||||
class TestCase(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def assertPostReq(self, url, data = {}):
|
||||
|
@ -24,31 +18,43 @@ class SchortFunctionalTestCase(unittest.TestCase):
|
|||
self.assertEqual(req.status_code, 200)
|
||||
return req
|
||||
|
||||
|
||||
class SchortBasicTests(TestCase):
|
||||
def test_entry_page(self):
|
||||
"""HTML exists in root page"""
|
||||
req = self.assertGetReq(BASE_URL + "/")
|
||||
content = req.text
|
||||
self.assertNotEqual(len(content), 0, msg="Get request content was empty.")
|
||||
self.assertRegex(content, ".*\<html.*", msg="Didn't find an opening <html tag in the response.")
|
||||
self.assertRegex(content, ".*\<div.*", msg="Didn't find any opening <div tag in the response.")
|
||||
|
||||
class SchortCustomIdTests(TestCase):
|
||||
def test_custom_creation(self):
|
||||
'''Test user supplied wish-URLs'''
|
||||
"""Test user supplied wish-URLs"""
|
||||
wishId = "custom_user_supplied_url"
|
||||
req = self.assertPostReq(BASE_URL + "/", data={"url" : "https://github.com/sqozz/schort", "wishId" : "custom_user_supplied_url"})
|
||||
short_url = req.text
|
||||
self.assertEqual(short_url, BASE_URL + "/" + wishId)
|
||||
|
||||
def test_easy_api(self):
|
||||
'''
|
||||
Test if the api is intuitive/easy to implement
|
||||
def test_empty_wish_id(self):
|
||||
"""Test a request with an empty wish-URL"""
|
||||
req = self.assertPostReq(BASE_URL + "/", data={"url" : "https://github.com/sqozz/schort", "wishId" : ""})
|
||||
short_url = req.text
|
||||
self.assertNotEqual(short_url, BASE_URL + "/", msg="Created short link cannot be equal to the root URL")
|
||||
|
||||
While creating the custom_creation test, out of pure laziness, I left out the whishId parameter.
|
||||
For intuitive use of the API from a script, this shouldn't be neccessary.
|
||||
'''
|
||||
req = self.assertPostReq("http://localhost:5000/", data={"url" : "https://github.com/sqozz/schort"})
|
||||
class SchortRandomIdTests(TestCase):
|
||||
aquiredId = ""
|
||||
|
||||
def test_default(self):
|
||||
"""Test default usage of schort"""
|
||||
req = self.assertPostReq(BASE_URL + "/", data={"url" : "https://github.com/sqozz/schort", "wishId" : ""})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(SchortBasicTests))
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(SchortRandomIdTests))
|
||||
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(SchortCustomIdTests))
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
||||
# vim: noexpandtab:ts=2:sw=2:sts=2
|
||||
|
|
Loading…
Reference in a new issue