#19 Tests
* moves dummy data creation from BaseViewTestCase into BaseTestCase
This commit is contained in:
parent
6992484b7f
commit
bbbaeab4c7
@ -26,6 +26,11 @@ class BaseTestCase(TestCase):
|
|||||||
groups = None
|
groups = None
|
||||||
superuser = None
|
superuser = None
|
||||||
user = None
|
user = None
|
||||||
|
intervention = None
|
||||||
|
compensation = None
|
||||||
|
eco_account = None
|
||||||
|
comp_state = None
|
||||||
|
comp_action = None
|
||||||
|
|
||||||
superuser_pw = "root"
|
superuser_pw = "root"
|
||||||
user_pw = "root"
|
user_pw = "root"
|
||||||
@ -58,72 +63,6 @@ class BaseTestCase(TestCase):
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class BaseViewTestCase(BaseTestCase):
|
|
||||||
""" Wraps basic test functionality, reusable for every specialized ViewTestCase
|
|
||||||
|
|
||||||
"""
|
|
||||||
login_url = None
|
|
||||||
intervention = None
|
|
||||||
compensation = None
|
|
||||||
eco_account = None
|
|
||||||
comp_state = None
|
|
||||||
comp_action = None
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def setUpTestData(cls) -> None:
|
|
||||||
cls.create_users()
|
|
||||||
cls.create_groups()
|
|
||||||
cls.create_dummy_intervention()
|
|
||||||
cls.create_dummy_compensation()
|
|
||||||
cls.create_dummy_eco_account()
|
|
||||||
cls.login_url = reverse("simple-sso-login")
|
|
||||||
|
|
||||||
def assert_url_success(self, client: Client, urls: list):
|
|
||||||
""" Assert for all given urls a direct 200 response
|
|
||||||
|
|
||||||
Args:
|
|
||||||
client (Client): The performing client
|
|
||||||
urls (list): An iterable list of urls to be checked
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
for url in urls:
|
|
||||||
response = client.get(url)
|
|
||||||
self.assertEqual(response.status_code, 200, msg=f"Failed for {url}")
|
|
||||||
|
|
||||||
def assert_url_success_redirect(self, client: Client, urls: dict):
|
|
||||||
""" Assert for all given urls a 302 response to a certain location.
|
|
||||||
|
|
||||||
Assert the redirect being the expected behaviour.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
client (Client): The performing client
|
|
||||||
urls (dict): An iterable dict of (urls, redirect_to_url) pairs to be checked
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
for url, redirect_to in urls.items():
|
|
||||||
response = client.get(url, follow=True)
|
|
||||||
# Expect redirects to the landing page
|
|
||||||
self.assertEqual(response.redirect_chain[0], (redirect_to, 302), msg=f"Failed for {url}")
|
|
||||||
|
|
||||||
def assert_url_fail(self, client: Client, urls: list):
|
|
||||||
""" Assert for all given urls a direct 302 response
|
|
||||||
|
|
||||||
Args:
|
|
||||||
client (Client): The performing client
|
|
||||||
urls (list): An iterable list of urls to be checked
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
for url in urls:
|
|
||||||
response = client.get(url)
|
|
||||||
self.assertEqual(response.status_code, 302, msg=f"Failed for {url}")
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_dummy_intervention(cls):
|
def create_dummy_intervention(cls):
|
||||||
""" Creates an intervention which can be used for tests
|
""" Creates an intervention which can be used for tests
|
||||||
@ -238,6 +177,67 @@ class BaseViewTestCase(BaseTestCase):
|
|||||||
return cls.comp_action
|
return cls.comp_action
|
||||||
|
|
||||||
|
|
||||||
|
class BaseViewTestCase(BaseTestCase):
|
||||||
|
""" Wraps basic test functionality, reusable for every specialized ViewTestCase
|
||||||
|
|
||||||
|
"""
|
||||||
|
login_url = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls) -> None:
|
||||||
|
cls.create_users()
|
||||||
|
cls.create_groups()
|
||||||
|
cls.create_dummy_intervention()
|
||||||
|
cls.create_dummy_compensation()
|
||||||
|
cls.create_dummy_eco_account()
|
||||||
|
cls.login_url = reverse("simple-sso-login")
|
||||||
|
|
||||||
|
def assert_url_success(self, client: Client, urls: list):
|
||||||
|
""" Assert for all given urls a direct 200 response
|
||||||
|
|
||||||
|
Args:
|
||||||
|
client (Client): The performing client
|
||||||
|
urls (list): An iterable list of urls to be checked
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
for url in urls:
|
||||||
|
response = client.get(url)
|
||||||
|
self.assertEqual(response.status_code, 200, msg=f"Failed for {url}")
|
||||||
|
|
||||||
|
def assert_url_success_redirect(self, client: Client, urls: dict):
|
||||||
|
""" Assert for all given urls a 302 response to a certain location.
|
||||||
|
|
||||||
|
Assert the redirect being the expected behaviour.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
client (Client): The performing client
|
||||||
|
urls (dict): An iterable dict of (urls, redirect_to_url) pairs to be checked
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
for url, redirect_to in urls.items():
|
||||||
|
response = client.get(url, follow=True)
|
||||||
|
# Expect redirects to the landing page
|
||||||
|
self.assertEqual(response.redirect_chain[0], (redirect_to, 302), msg=f"Failed for {url}")
|
||||||
|
|
||||||
|
def assert_url_fail(self, client: Client, urls: list):
|
||||||
|
""" Assert for all given urls a direct 302 response
|
||||||
|
|
||||||
|
Args:
|
||||||
|
client (Client): The performing client
|
||||||
|
urls (list): An iterable list of urls to be checked
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
for url in urls:
|
||||||
|
response = client.get(url)
|
||||||
|
self.assertEqual(response.status_code, 302, msg=f"Failed for {url}")
|
||||||
|
|
||||||
|
|
||||||
class KonovaViewTestCase(BaseViewTestCase):
|
class KonovaViewTestCase(BaseViewTestCase):
|
||||||
""" Holds tests for all regular views, which are not app specific
|
""" Holds tests for all regular views, which are not app specific
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user