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