diff --git a/django_lostplaces/lostplaces/tests/views/__init__.py b/django_lostplaces/lostplaces/tests/views/__init__.py index 3b83e11..12f6d09 100644 --- a/django_lostplaces/lostplaces/tests/views/__init__.py +++ b/django_lostplaces/lostplaces/tests/views/__init__.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import re from django.test import TestCase @@ -87,7 +88,7 @@ class ViewTestCase(TestCase): self.assertEqual( response['location'], redirect_to, - msg='Expecting the response to redirect to %s, where redirected to %s instea' % ( + msg='Expecting the response to redirect to %s, where redirected to %s instead' % ( str(redirect_to), str(response['location']) ) @@ -113,6 +114,84 @@ class ViewTestCase(TestCase): def assertHttpMethodNotAllowed(self, response): self.assertHttpCode(response, 405) + +class GlobalTemplateTestCaseMixin: + + def assertGlobal(self, response): + self.assertLogo(response) + self.assertMenu(response) + self.assertProfileMenu(response) + + def assertLogo(self, response): + """ + Looks for an image tag with with 'logo' or 'Logo' in the file name + all within an
tag. + """ + self.assertNotEqual( + None, + re.search( + """.*.*
""", + response.content.decode().replace('\n', '') + ), + msg='Expecting a header containing a logo with \'logo\' in the source name' + ) + + def assertMenu(self, response): + """ + Looks for an '""", + response.content.decode().replace('\n', '').lower() + ), + msg='Expecting an menu containing a link to the homepage and a link to the urbex codex' + ) + + def assertMenuItem(self, response, label=None, url=None): + """ + Checks for an additional menu item by label or url. Regex can be passed. + """ + if label is None and url is None: + raise ValueError("Either a label or url has to be provided") + + found_label = None + if label != None: + label = label.lower() + found_label = re.search( + """.*.*%s.*.*""" % label, + response.content.decode().replace('\n', '').lower() + ) + + found_url = None + if url != None: + url = url.lower() + found_url = re.search( + """.*.*.*""" % url, + response.content.decode().replace('\n', '') + ) + + self.assertTrue( + found_label != None and found_url != None, + msg='Expecting an menu item with either label \'%s\' or url \'%s\'' % ( + label, + url + ) + ) + + def assertProfileMenu(self, response): + """ + Looks for a logout or login+signup link within the an header tag + """ + self.assertNotEqual( + None, + re.search( + """.*(""", + response.content.decode().replace('\n', '').lower() + ), + msg='Expecting a profile menu containing either a logout link or a login and then a signup link' + ) class TaggableViewTestCaseMixin: