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,
0:03 but we haven't tested it yet.
0:04 Let's go out and call it.
0:05 Make sure the APP is running.
0:07 And first, before we go all the way back to Twilio and use studio to
0:11 send messages over here. Let's just test this locally.
0:15 So I've got Postman fired up.
0:17 We're gonna go to localhost:5000/api/order and they're going to post
0:22 over the body here that we're expecting.
0:25 We have a customer which has a number,
0:27 name and an email and a cake which has these things and a price.
0:32 So let's go over here and make sure we're doing a post.
0:34 Send it over and see what we get.
0:37 Remember what's going to happen. We're going to save it to the parse it over
0:39 save it to the database,
0:42 and I'm going to print out the cake order.
0:44 Actually, let's print out the db_order and then we're just going to echo
0:49 back what got sent over. So I'm going to restart this.
0:53 Okay, Moment of truth. Let's push the button.
0:57 Also, before I push the button,
0:59 we go over to the table and we double click it notice there's no data,
1:03 no users and no orders. Let's give it a test.
1:09 Look at that. Awesome. Well,
1:10 we got something back. That's a really good sign.
1:12 We received an order for a cake with this customer.
1:15 And there's the price. We haven't done anything to tell them their order_id or
1:19 anything like that, but it looks like it might have worked.
1:22 If we go back here, you can see something was printed out.
1:24 A database object was created and printed out.
1:27 And if we go to the users,
1:29 you can see there's now one here with id 1 and there's an order or somewhere over
1:36 here you can see the user ID.
1:38 There's our foreign key relationship. Is 1 fantastic?
1:42 It went in with the date correctly.
1:44 Auto incremental, ID know Fulfilled date.
1:46 Perfect. Exactly what? Like what we want.
1:48 Let's do one more just to test this.
1:50 Finding a new user versus an old one.
1:52 So bacon was fun. But how about,
1:55 uh, chocolate or are topping
1:58 And the price of that one is going to be 19.
2:01 We're going to send it over and let's even let's put,
2:04 uh, change this to 504 There we go.
2:10 A different number, but same email address
2:12 send it again. Alright, Something good happened.
2:15 It looks like it worked. And if everything worked correctly,
2:19 we should have two orders we do.
2:22 If we look, they should be associated with the same user_id.
2:25 Awesome. And they are here.
2:27 You can see the difference of the price.
2:28 And over here, just one user.
2:30 Still, awesome. I think we've got it completely built.
2:34 It looks like our api
2:35 is working and will be able to integrate that into twilio later.