KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to write some tests for a Django application I'm working on but I haven't yet decided on the exact urls I want to use for each view. Therefore, I'm using named urls in the tests. For example, I have a url named dashboard: c = Client() resp = c.get(reverse('dashboard')) This view should only be available to logged in users. If the current user is anonymous, it should redirect them to the login page, which is also a named url. However, when it does this, it uses an additional GET parameter to keep track of the url it just came from, which results in the following: /login?next=dashboard When I then try to test this redirect, it fails because of these additional parameters: # It's expecting '/login' but gets '/login?next=dashboard' self.assertRedirects(resp, reverse('login')) Obviously, it works if I hard code them into the test: self.assertRedirects(resp, '/login?next=dashboard') But then, if I ever decide to change the URL for my dashboard view, I'd have to update every test that uses it. Is there something I can do to make it easier to handle these extra parameters? Any advice appreciated. Thanks.
Tags (comma-separated)
Save Edits
Cancel