How to know that a POST is truly successful

31 views
Skip to first unread message

Randall Sindlinger

unread,
Jun 1, 2016, 5:21:50 PM6/1/16
to Mojolicious
I might be missing something trivial here... but how can I know that a POST was truly successful?

I'm writing some testing code with Test::Mojo and friends, and had this snippet
$t->ua->max_redirects(1); #post produces a redirect
$t
->post_ok("/relationship" => json => {identifer => 'test:roughlyEquivalent',
                                        description
=>  "Close, but not quite"})
   
->status_is(200, "Add test:roughlyEquivalent");

$t
->get_ok("/relationship/test:roughlyEquivalent")->status_is(200, "test:roughlyEquivalent now exists");


The status of the get_ok test failed, getting a 404.  It took me a while to see that I'd mis-typed "identifier" in the post_ok line.

It feels wrong that I can have a key misspelled, causing the insert to fail, and still get a success message back. 
Is there a deeper level of testing (or validation) available someplace?

Thanks,
-Randall

Dan Book

unread,
Jun 1, 2016, 5:48:46 PM6/1/16
to mojol...@googlegroups.com
The test is identifying that the post successfully occurred and the second test verifies it got a 200 OK response. If there is some other way you are indicating failure, you'll need to check that as well. You can access the response object after the post_ok call via $t->tx->res.

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Randall Sindlinger

unread,
Jun 2, 2016, 11:01:55 AM6/2/16
to Mojolicious
Thanks, Dan.  This is code I inherited, and it wasn't clear to me whether it was something inherent to Mojolicious or in the way the project was written.  Thanks for pointing me in the right direction.
-Randall
Reply all
Reply to author
Forward
0 new messages