Django: Getting Started Transcripts
Chapter: Django Admin
Lecture: Writing an Admin model test

Login or purchase this course to watch this video and the rest of the course contents.
0:10 And here's the start of my test. I used the client built into the test suite to log into the site using the
0:17 user name and password of the admin created in the setup method. I then verify that the response object is true.
0:25 False would mean that the login failed. Next I make sure that nothing in my customization code is causing the page to 500
0:36 error simply by loading the page and checking that I get a 200 response. Now I'm going to dig into the admin representation of the author object.
0:53 To do that, first I need to create an author. Then on line 36 I'm creating an author admin object
1:01 using the admin site and the author model that I created on line 35. The look up field function takes an admin model,
1:16 a model, and the name of the field to look up. In this case I'm asking for the show books fields. This function unfortunately is not well documented.
1:27 If you dig into the django code you'll see that it returns a tuple containing a field object, attribute name, and value.
1:34 I'm only interested in the last part. Hence the underscores, the actual test part of this test validates that the URL query parameter is correct.
1:44 It does that by looking for a question mark author id. inside of the looked up value.
1:51 A better test would check the whole thing but this at least gives you the idea/ And there you go, all tests pass. Happiness is obtained.

Talk Python's Mastodon Michael Kennedy's Mastodon