Skip to content

Instantly share code, notes, and snippets.

@eugena
Last active September 11, 2015 13:13
Show Gist options
  • Save eugena/4ab48b25f71230672222 to your computer and use it in GitHub Desktop.
Save eugena/4ab48b25f71230672222 to your computer and use it in GitHub Desktop.
Test mixins for django
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