Skip to content

fix invalid_url, add misdated_url tests #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions tutorials/09-readable-urls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,22 @@ Another Test

What would happen if we changed the slug or an invalid date was given in the URL? This shouldn't matter because we only check for the model ``id``.

Let's write a test for this case to make sure the correct page is displayed in this case. Our test should look like this:
Let's write a couple more tests for this case to make sure the correct page is displayed in this case, and for when the id does not exist. Our tests should look like this:

.. code-block:: python

def test_invalid_url(self):
entry = Entry.objects.create(title="title", body="body",
author=self.user)
response = self.client.get("/0000/00/00/{0}-invalid/".format(entry.id))
def test_misdated_url(self):
entry = Entry.objects.create(title="title", body="body", author=self.user)
response = self.client.get("/0000/00/00/{0}-misdated/".format(entry.id))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response,
template_name='blog/entry_detail.html')

def test_invalid_url(self):
entry = Entry.objects.create(title="title", body="body", author=self.user)
response = self.client.get("/0000/00/00/0-invalid/")
self.assertEqual(response.status_code, 404)

Now let's run our tests and make sure they still pass.


Expand Down