Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Testing web apps
Lecture: 3 types of web unit tests

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We're going to work with three different types of tests.
0:03 Now this, like I said is not a general course
0:07 on just unit testing or testing in general.
0:09 There may be other aspects of testing
0:11 that would make sense in this application
0:14 but we're going to focus on the ones that are special
0:17 to web applications and how to deal with those.
0:20 So, let's go from, I guess easiest is probably the way
0:22 to think of it, to more complicated and more holistic.
0:25 So one of them is, we might want to test the view model.
0:28 This is a super important part of validation
0:31 for almost all of our various methods.
0:35 So it gets the data in, it maybe normalizes it
0:38 we saw our registered email takes a potentially
0:42 space-filled upper case email always normalizes it to
0:46 just truncated, lowercase versions and so on.
0:50 We might want to test that. Also has deep validation in here
0:53 like this is what our validation is
0:55 and validation is an important this to test.
0:57 So what's special about this?
0:59 Well we have to come up with a request
1:02 a real Pyramid request object that we can give it
1:05 because it might use it in who knows how.
1:08 So we're going to have to come up with that
1:09 and that going to take some special techniques.
1:12 Also, we saw many of these view models
1:14 talk to the database, which means, we can't separate
1:17 the test here from actual having a live database.
1:21 Which is very much what you want to do.
1:23 So we're going to see how to address both of those issues.
1:26 Then we might want to test the view method which internally
1:29 probably works with a view model, but not necessarily.
1:32 And again, in order to call the view method
1:35 we have to pass a request.
1:37 So this setup here is not that different
1:39 between the two, but how you test the outcome probably is.
1:43 And then, we might want to test the entire website.
1:46 I want to take a URL, make sure the routing is set up
1:50 correctly, that it finds the right view method
1:52 passes that data over, runs through all the templates
1:55 and everything, and gets the right information back.
1:58 So we might want to spin up the entire web app.
2:01 Not on a server, but in process in our tests.
2:05 So, we're going to create this web app
2:08 and we're going to feed it a fake HTTP request.
2:12 Again, this might talk to the database
2:13 do other sorts of things we might like to avoid.
2:16 So these are the three types of tests that we have.
2:19 Maybe more fine grained or separate on the left here
2:22 we might also have just general unit tests
2:24 for algorithms and things like that.
2:26 And to the right, even more integrated we might
2:30 actually deploy our website to a server
2:32 and have something like Selenium
2:34 interact with it as if it were a web browser.
2:37 We're not going to focus on either of those
2:38 we're going to focus on these three
2:39 because of their special techniques
2:42 and the tools from Pyramid and elsewhere.
2:44 that we're going to use to solve.