Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Testing web apps
Lecture: Organizing your tests
0:00 We've gone through several rounds of reorganizing our code in our pyramid web application. And it may be sometimes hard to see the value in this
0:10 but as your app grows and grows the better organized it is the less weight you get put onto you conceptually to try to keep all that in your head.
0:22 So really important organization, makes a lot of sense. We saw that we did this with the templates we did this with controllers
0:28 we did this with the view models. Guess what? We're going to do it with tests as well. And because the tests usually have to do with either
0:37 a URL, the view model or the view method these are all grouped into controllers so far. So, it makes sense to go ahead and group them by controller.
0:47 So, it doesn't have to be this way but it certainly seems like a decent way to get started and you can do additional organizing if you want.
0:56 So we also have a HomeController and a PackageController so we have their respective tests as well.
1:02 We didn't write any for the CMS stuff yet so none of those. Now, another thing that's really helpful is if we have a site map in.
1:11 We'll talk about this at the end of this chapter having a site map. Which is basically just a XML document that lists
1:19 all of the publicly accessible URLs on your site even if they're not directly linked so that things like Google and Bing can find and search your site.
1:28 We could leverage that site map to cover a bunch of cases. You'd be really surprised how often you get hard failures
1:36 instead of what you might consider a soft failure if something goes wrong. If I request the package page but for some reason
1:42 the package query is wrong? Probably I'm going to get just nothing back in which case the template is going to crash
1:48 or something else is going to crash because the None type doesn't have whatever they're trying to do. So, simply requesting every page on your site
1:56 and just checking that those come back with success codes and not failure codes? That's really actually pretty valuable.
2:03 You can test a lot of semi important not super important things that way. All right, so we'll talk about that as well
2:10 but we're going to focus on testing the internal logic of these various controllers, view models and so on.
2:15 And here's an organization that will help us keep that all straight and clean.