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