Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Testing web apps
Lecture: Special challenges of the web

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's focus on some of the special challenges we might have in testing web projects. Here is a POST view method that's going to handle
0:10 the postback, when we're doing registration. So, this is how users actually register on our site. And, you look at it, you can see there's things
0:16 we might want to test, this interaction with the ViewModel this error handling, the actual creation of the account.
0:23 But, look carefully. You'll see there are certain areas where this is much harder than just some sort of algorithmic thing.
0:32 We're creating a register ViewModel and, oh it takes a request. That's an actual Pyramid request.
0:38 With various dictionaries like the Post, Get, matchdict headers, URLs, all sorts of stuff. Hmmm, how do we create one of those?
0:48 That could be tricky. Validate. Remember the register ViewModel actually goes back to the database to make sure the user that's trying
0:54 to register isn't already registered. How do we talk to the database? We don't actually want to go to the database in our test.
1:01 What we want to do is run these tests in isolation. So, how do we make that still do something meaningful without actually going to the database.
1:08 That's really tricky. We're going to create an account. Well that's definitely going to go to the database, right.
1:13 Maybe it's also going to send like a welcome email who knows what that user service thing does.
1:18 It might do all kinds of things we don't want to happen. So, we don't want an email to get sent to a random person
1:24 every time these automatic tests run, right. We want to make sure that doesn't happen but we might want to verify that the email would
1:31 have been sent correctly. Similarly login, what does that mean? This redirect that probably throws an exception
1:37 but in a positive way, right, throws a HTTPFound exception for /account. So, all of these things are special challenges
1:45 of working with the web when we're doing testing.

Talk Python's Mastodon Michael Kennedy's Mastodon