Hi Tim,
Now I'm going to recommend another testing tool: py.test :-)
I handle this type of situation by using py.test parametrization.
Usually I have a bunch of views that are all login-required, so I just
write a single test to check that a view returns redirect-to-login if
accessed anonymously, and then parametrize that test over all the urls
it should apply to. It looks something like this (parametrizing over
just two views):
@pytest.mark.parametrize(
'urlname,urlkwargs',
[('oneview', {}), ('otherview', {'id': 999})],
)
def test_login_required(client, urlname, urlkwargs):
url = reverse(urlname, kwargs=urlkwargs)
resp = client.get(url)
assert utils.redirects_to(resp) == reverse('accounts_login')
I use url-reversing in my tests; the parametrization would be slightly
simpler if you just used raw URLs. The `client` kwarg is a py.test
fixture that returns a WebTest client instance. `utils.redirects_to` is
just a helper that pulls out the `Location` header from the response,
and strips out everything but the path portion.
HTH,
Carl