Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Testing web apps
Lecture: The rest of the tests

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now there's more tests to write for this application of course there are. I added a few more, I wrote them earlier and just dropped them in for you.
0:10 You've already seen all the three cases that we're going to use and it would just be more of the same
0:14 but I want to give you a little bit more to work with. So here's our account test that we've been working with
0:18 we've got out vm test, our ViewModels test we've got our view test, and now we've got our two innovation tests down here at the end
0:26 working with our pytest ficture. So nothing changes there, but I just added some more. Remember that test for the package details
0:34 in the earlier section? Just in concept. So, here it is in code. So here is one that, we'll find a successful one.
0:42 We'll simulate it actually existing in the database called sqlalchemy and we're going to run through it here and mock out the database interaction
0:50 but then we're going to get that data and process it here. Right, get a response and verify that SQLAlchemy is in the data.
0:57 We're also going to do a missing one. This is important to test. We want to make sure that if for some reason
1:02 we try to get package by id, but it's not there we get a status code 404 as opposed to crashing or just trying to show something that's not right.
1:11 Over to the ohm test, super simple we're just doing integration type tests here. On the first one, just making sure that the title's in there
1:19 and then here we're directly calling a function so this should help power the Int and this should be much more V with our naming commission here.
1:26 And this is verifying that the model that we get back is what we expected. We also have a sitemap test one.
1:33 I'm going to save that for later, but let's look at this as well. So far what I've been doing is saying running the test here and it would be nice
1:41 if I could just say run all the tests. One way that we can do that as well as configure a couple of things to work better, as we'll see
1:47 is create this all test. This is very, very analogous to our all models up here. In fact, it's basically doing the same thing.
1:56 So it's going to import all the tests into one file and then we just point pytest at that and that's a simple and easy thing to do.
2:02 So let's go down here and we'll see we're just importing star from all the tests. And then I pointed our run configuration to run that file.
2:13 Okay, so now if we run it you'll see we have a bunch more tests that run. How cool is that? So a bunch of stuff is happening there.
2:20 It's going to be fun to dig into it with you but just run it like this. This imports of 'em, remember if you add
2:25 a whole new category of tests, so in a file be sure to throw it in here as well.


Talk Python's Mastodon Michael Kennedy's Mastodon