#100DaysOfWeb in Python Transcripts
Chapter: Days 81-84: Unit testing web apps
Lecture: Concept: Functional tests

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The final type of test we want to look at are functional tests for testing the whole web application.
0:06 So remember, we're going to issue a fake HTTP request to the entire web framework, completely started up
0:14 and initialized the way our app is going to run. So it'll call, application initialize, the request
0:21 is going to go over to, in our case, the Pyramid web framework but it just as well could be Flask or Django and it's going to use the routing framework
0:27 to find the right view method and execute it and in return, a full on response. So this is the type of thing we're going to do
0:34 and it takes a little more structure and supporting concepts than we had before. So we're going to set up our app by importing the main method
0:42 creating the app, which gets, this is WSGI app that gets returned from our app start up and then we're actually going to use webtest to create
0:50 or to import the test app Wrapper, and we'll create an app object by wrapping that. This will let us issue direct HTTP requests
0:59 or simulated ones by saying, "I want this URL and I expect this status code, and if I don't get it, it's an error."
1:05 So this is going to run in the start up the setup, for this test case. And then for each test we want to run, there's no real arrange
1:12 not in the three As, we don't have to do anything there that's just the start up, the set up of this test class.
1:18 Then we're going to do the act, and that's simply getting a URL and specifying a status code. If it doesn't match that status code, that's an error.
1:26 Like if you get a 404 that's going to crash the test and fail it. And finally, we get a response back, this is like
1:32 an actual response object with an HTML body that's gone through all the templates and all that kind of stuff, so we can do things like assert
1:39 that certain bits of text are contained within it.

Talk Python's Mastodon Michael Kennedy's Mastodon