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
0:01 of reorganizing our code in our pyramid web application.
0:05 And it may be sometimes hard to see the value in this
0:09 but as your app grows and grows the better organized it is
0:14 the less weight you get put onto you
0:18 conceptually to try to keep all that in your head.
0:21 So really important organization, makes a lot of sense.
0:24 We saw that we did this with the templates
0:26 we did this with controllers
0:27 we did this with the view models.
0:30 Guess what? We're going to do it with tests as well.
0:32 And because the tests usually have to do with either
0:36 a URL, the view model or the view method
0:40 these are all grouped into controllers so far.
0:43 So, it makes sense to go ahead and group them by controller.
0:46 So, it doesn't have to be this way
0:49 but it certainly seems like a decent way to get started
0:52 and you can do additional organizing if you want.
0:55 So we also have a HomeController and a PackageController
0:59 so we have their respective tests as well.
1:01 We didn't write any for the CMS stuff yet so none of those.
1:05 Now, another thing that's really helpful is if we have a site map in.
1:10 We'll talk about this at the end of this chapter
1:13 having a site map. Which is basically just a XML document that lists
1:18 all of the publicly accessible URLs on your site
1:22 even if they're not directly linked
1:23 so that things like Google and Bing can find
1:25 and search your site.
1:27 We could leverage that site map to cover a bunch of cases.
1:31 You'd be really surprised how often you get hard failures
1:35 instead of what you might consider a soft failure
1:37 if something goes wrong.
1:39 If I request the package page but for some reason
1:41 the package query is wrong?
1:43 Probably I'm going to get just nothing back
1:45 in which case the template is going to crash
1:47 or something else is going to crash because
1:49 the None type doesn't have whatever they're trying to do.
1:52 So, simply requesting every page on your site
1:55 and just checking that those come back with success codes
1:58 and not failure codes?
1:59 That's really actually pretty valuable.
2:02 You can test a lot of semi important
2:04 not super important things that way.
2:07 All right, so we'll talk about that as well
2:09 but we're going to focus on testing the internal logic
2:12 of these various controllers, view models and so on.
2:14 And here's an organization that will help us
2:17 keep that all straight and clean.