Django: Getting Started Transcripts
Chapter: HTML Templates
Lecture: Unit testing HTML templates

Login or purchase this course to watch this video and the rest of the course contents.
0:00 unit tests don't usually exercise the rendered content too much and as this chapter has concentrated
0:06 on the template engine, there isn't much new to see here. As I mentioned in the previous chapter.
0:12 Tests can either be in the app or at the project level. I prefer to keep them together. So I'll be creating a new test file called Test home Inside.
0:21 I'll test that each of the pages I've created returned to 200 code and seeing as the sample example still fun to say had a context dictionary.
0:32 I'll show you that you can access it inside of the test. Here is a test case for the home app like in the previous chapter.
0:41 This isn't a file that's name starts with test and is found in the tests directory and the test case sweet inherits from the test case class.
0:51 There are three groups of tests here. All three use the client object to get a URL And then validate that the response
0:59 code was 200. The only new thing here is accessing the context. The sample view had a context dictionary with three books in it.
1:09 A rendered templates, context is available in the response objects context attribute all I'm doing
1:16 here is making sure there is a key called books inside of it but you could do some intensive tests if you like.
1:23 This allows you to do pretty exhaustive testing on a view without caring how its contents
1:28 are rendered, leaving the testing of presentation to an outside tool like selenium.
1:36 I'll just open the terminal now and run the test to tests run successfully,


Talk Python's Mastodon Michael Kennedy's Mastodon