<s> import unittest <EOL> import json <EOL> import featherweight_api <EOL> def trivial_fn ( x ) : <EOL> """<STR_LIT>""" <EOL> return x * <NUM_LIT:2> <EOL> featherweight_api . register ( trivial_fn ) <EOL> class Test ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . app = featherweight_api . app . test_client ( ) <EOL> def test_try_failure_missing_fn ( self ) : <EOL> rv = self . app . get ( '<STR_LIT>' ) <EOL> assert rv . status_code == <NUM_LIT> <EOL> def test_try_failure ( self ) : <EOL> rv = self . app . get ( '<STR_LIT>' ) <EOL> assert rv . status_code == <NUM_LIT:200> <EOL> data = rv . data . decode ( '<STR_LIT:utf8>' ) <EOL> jsn = json . loads ( data ) <EOL> assert jsn [ '<STR_LIT:success>' ] == False , "<STR_LIT>" <EOL> def test_try_failure_bad_arg ( self ) : <EOL> rv = self . app . get ( '<STR_LIT>' ) <EOL> assert rv . status_code == <NUM_LIT:200> <EOL> data = rv . data . decode ( '<STR_LIT:utf8>' ) <EOL> jsn = json . loads ( data ) <EOL> assert jsn [ '<STR_LIT:success>' ] == False , "<STR_LIT>" <EOL> def test_try_success ( self ) : <EOL> rv = self . app . get ( '<STR_LIT>' ) <EOL> assert rv . status_code == <NUM_LIT:200> <EOL> data = rv . data . decode ( '<STR_LIT:utf8>' ) <EOL> jsn = json . loads ( data ) <EOL> assert jsn [ '<STR_LIT:success>' ] == True <EOL> assert jsn [ '<STR_LIT:result>' ] == <NUM_LIT> <EOL> def test_try_success_POST ( self ) : <EOL> data = json . dumps ( { '<STR_LIT:x>' : <NUM_LIT:11> } ) <EOL> rv = self . app . post ( '<STR_LIT>' , data = data , headers = { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } ) <EOL> assert rv . status_code == <NUM_LIT:200> <EOL> data = rv . data . decode ( '<STR_LIT:utf8>' ) <EOL> jsn = json . loads ( data ) <EOL> assert jsn [ '<STR_LIT:success>' ] == True <EOL> assert jsn [ '<STR_LIT:result>' ] == <NUM_LIT> </s>
