Last active
September 11, 2015 13:13
-
-
Save eugena/4ab48b25f71230672222 to your computer and use it in GitHub Desktop.
Test mixins for django
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RedirectChainAnalysisMixin(object): | |
""" | |
A mixin to check if a redirect chain of response is correct | |
Must be used with Django TestCase object | |
""" | |
def chain_check(self, response, needed): | |
""" | |
Checks a chain | |
response (object) | |
needed (tuple or dict) | |
usage: | |
self.assertTrue(self.chain_check(response, ('index', 'login', ))) | |
""" | |
prefix = '%s://%s' % (response.request.get('wsgi.url_scheme'), response.request.get('SERVER_NAME')) | |
return response.redirect_chain == [('%s/%s' % (prefix, x), 302) for x in needed] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment