Python-powered chat apps with Twilio and SendGrid Transcripts
Chapter: Using our database with the SQLAlchemy ORM
Lecture: Testing the API

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well, we wrote our code to insert record this order, but we haven't tested it yet. Let's go out and call it. Make sure the APP is running.
0:08 And first, before we go all the way back to Twilio and use studio to send messages over here. Let's just test this locally.
0:16 So I've got Postman fired up. We're gonna go to localhost:5000/api/order and they're going to post over the body here that we're expecting.
0:26 We have a customer which has a number, name and an email and a cake which has these things and a price.
0:33 So let's go over here and make sure we're doing a post. Send it over and see what we get.
0:38 Remember what's going to happen. We're going to save it to the parse it over save it to the database, and I'm going to print out the cake order.
0:45 Actually, let's print out the db_order and then we're just going to echo back what got sent over. So I'm going to restart this.
0:54 Okay, Moment of truth. Let's push the button. Also, before I push the button, we go over to the table and we double click it notice there's no data,
1:04 no users and no orders. Let's give it a test. Look at that. Awesome. Well, we got something back. That's a really good sign.
1:13 We received an order for a cake with this customer. And there's the price. We haven't done anything to tell them their order_id or
1:20 anything like that, but it looks like it might have worked. If we go back here, you can see something was printed out.
1:25 A database object was created and printed out. And if we go to the users,
1:30 you can see there's now one here with id 1 and there's an order or somewhere over here you can see the user ID.
1:39 There's our foreign key relationship. Is 1 fantastic? It went in with the date correctly. Auto incremental, ID know Fulfilled date.
1:47 Perfect. Exactly what? Like what we want. Let's do one more just to test this. Finding a new user versus an old one. So bacon was fun. But how about,
1:56 uh, chocolate or are topping And the price of that one is going to be 19. We're going to send it over and let's even let's put,
2:05 uh, change this to 504 There we go. A different number, but same email address send it again. Alright, Something good happened.
2:16 It looks like it worked. And if everything worked correctly, we should have two orders we do.
2:23 If we look, they should be associated with the same user_id. Awesome. And they are here. You can see the difference of the price.
2:29 And over here, just one user. Still, awesome. I think we've got it completely built. It looks like our api
2:36 is working and will be able to integrate that into twilio later.

Talk Python's Mastodon Michael Kennedy's Mastodon