@@ -178,18 +178,26 @@ What would happen if we changed the slug or an invalid date was given
178
178
in the URL? This shouldn't matter because we only check for the model
179
179
``pk ``.
180
180
181
- Let's write a test for this case to make sure the correct page is
182
- displayed in this case. Our test should look like this:
181
+ Let's write a couple more tests for this case to make sure the correct
182
+ page is displayed in this case, and for when the id does not exist. Our
183
+ tests should look like this:
183
184
184
185
.. code-block :: python
185
186
186
- def test_invalid_url (self ):
187
- entry = Entry.objects.create(title = " title" , body = " body" ,
188
- author = self .user)
189
- response = self .client.get(" /0000/00/00/{0} -invalid/" .format(entry.id))
187
+ def test_misdated_url (self ):
188
+ entry = Entry.objects.create(
189
+ title = " title" , body = " body" , author = self .user)
190
+ url = " /0000/00/00/{0} -misdated/" .format(entry.id)
191
+ response = self .client.get(url)
190
192
self .assertEqual(response.status_code, 200 )
191
- self .assertTemplateUsed(response,
192
- template_name = ' blog/entry_detail.html' )
193
+ self .assertTemplateUsed(
194
+ response, template_name = ' blog/entry_detail.html' )
195
+
196
+ def test_invalid_url (self ):
197
+ entry = Entry.objects.create(
198
+ title = " title" , body = " body" , author = self .user)
199
+ response = self .client.get(" /0000/00/00/0-invalid/" )
200
+ self .assertEqual(response.status_code, 404 )
193
201
194
202
Now let's run our tests and make sure they still pass.
195
203
0 commit comments