<s> import json <EOL> def test_schema ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> empty_request = app_client . post ( '<STR_LIT>' , headers = headers , data = json . dumps ( { } ) ) <EOL> assert empty_request . status_code == <NUM_LIT> <EOL> assert empty_request . content_type == '<STR_LIT>' <EOL> empty_request_response = json . loads ( empty_request . data . decode ( ) ) <EOL> assert empty_request_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert empty_request_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> bad_type = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( { '<STR_LIT>' : <NUM_LIT> } ) ) <EOL> assert bad_type . status_code == <NUM_LIT> <EOL> assert bad_type . content_type == '<STR_LIT>' <EOL> bad_type_response = json . loads ( bad_type . data . decode ( ) ) <EOL> assert bad_type_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert bad_type_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> good_request = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( { '<STR_LIT>' : '<STR_LIT:version>' } ) ) <EOL> assert good_request . status_code == <NUM_LIT:200> <EOL> good_request_response = json . loads ( good_request . data . decode ( ) ) <EOL> assert good_request_response [ '<STR_LIT>' ] == '<STR_LIT:version>' <EOL> good_request_extra = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( { '<STR_LIT>' : '<STR_LIT:version>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> assert good_request_extra . status_code == <NUM_LIT:200> <EOL> good_request_extra_response = json . loads ( good_request . data . decode ( ) ) <EOL> assert good_request_extra_response [ '<STR_LIT>' ] == '<STR_LIT:version>' <EOL> wrong_type = app_client . post ( '<STR_LIT>' , headers = headers , data = json . dumps ( <NUM_LIT> ) ) <EOL> assert wrong_type . status_code == <NUM_LIT> <EOL> assert wrong_type . content_type == '<STR_LIT>' <EOL> wrong_type_response = json . loads ( wrong_type . data . decode ( ) ) <EOL> assert wrong_type_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_type_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> def test_schema_response ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT:200> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , <EOL> data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , <EOL> data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT:200> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT:200> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , <EOL> data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT:200> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT:200> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , <EOL> data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , data = None ) <EOL> assert request . status_code == <NUM_LIT:200> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , <EOL> data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> request = app_client . get ( '<STR_LIT>' , headers = { } , <EOL> data = None ) <EOL> assert request . status_code == <NUM_LIT> <EOL> def test_schema_in_query ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> good_request = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> query_string = { '<STR_LIT>' : '<STR_LIT:version>' , <EOL> '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> assert good_request . status_code == <NUM_LIT:200> <EOL> good_request_response = json . loads ( good_request . data . decode ( ) ) <EOL> assert good_request_response [ '<STR_LIT>' ] == '<STR_LIT:version>' <EOL> def test_schema_list ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> wrong_type = app_client . post ( '<STR_LIT>' , headers = headers , data = json . dumps ( <NUM_LIT> ) ) <EOL> assert wrong_type . status_code == <NUM_LIT> <EOL> assert wrong_type . content_type == '<STR_LIT>' <EOL> wrong_type_response = json . loads ( wrong_type . data . decode ( ) ) <EOL> assert wrong_type_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_type_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> wrong_items = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( [ <NUM_LIT> ] ) ) <EOL> assert wrong_items . status_code == <NUM_LIT> <EOL> assert wrong_items . content_type == '<STR_LIT>' <EOL> wrong_items_response = json . loads ( wrong_items . data . decode ( ) ) <EOL> assert wrong_items_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_items_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> def test_schema_map ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> valid_object = { <EOL> "<STR_LIT:foo>" : { <EOL> "<STR_LIT>" : "<STR_LIT:string>" <EOL> } , <EOL> "<STR_LIT:bar>" : { <EOL> "<STR_LIT>" : "<STR_LIT:string>" <EOL> } <EOL> } <EOL> invalid_object = { <EOL> "<STR_LIT:foo>" : <NUM_LIT> <EOL> } <EOL> wrong_type = app_client . post ( '<STR_LIT>' , headers = headers , data = json . dumps ( <NUM_LIT> ) ) <EOL> assert wrong_type . status_code == <NUM_LIT> <EOL> assert wrong_type . content_type == '<STR_LIT>' <EOL> wrong_type_response = json . loads ( wrong_type . data . decode ( ) ) <EOL> assert wrong_type_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_type_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> wrong_items = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( invalid_object ) ) <EOL> assert wrong_items . status_code == <NUM_LIT> <EOL> assert wrong_items . content_type == '<STR_LIT>' <EOL> wrong_items_response = json . loads ( wrong_items . data . decode ( ) ) <EOL> assert wrong_items_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_items_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> right_type = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( valid_object ) ) <EOL> assert right_type . status_code == <NUM_LIT:200> <EOL> def test_schema_recursive ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> valid_object = { <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : [ ] } , <EOL> { "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : [ ] } , <EOL> ] } , <EOL> { "<STR_LIT>" : [ ] } , <EOL> ] <EOL> } <EOL> invalid_object = { <EOL> "<STR_LIT>" : [ <NUM_LIT> ] <EOL> } <EOL> wrong_type = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( <NUM_LIT> ) ) <EOL> assert wrong_type . status_code == <NUM_LIT> <EOL> assert wrong_type . content_type == '<STR_LIT>' <EOL> wrong_type_response = json . loads ( wrong_type . data . decode ( ) ) <EOL> assert wrong_type_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_type_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> wrong_items = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( invalid_object ) ) <EOL> assert wrong_items . status_code == <NUM_LIT> <EOL> assert wrong_items . content_type == '<STR_LIT>' <EOL> wrong_items_response = json . loads ( wrong_items . data . decode ( ) ) <EOL> assert wrong_items_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert wrong_items_response [ '<STR_LIT>' ] . startswith ( "<STR_LIT>" ) <EOL> right_type = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( valid_object ) ) <EOL> assert right_type . status_code == <NUM_LIT:200> <EOL> def test_schema_format ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> wrong_type = app_client . post ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( "<STR_LIT>" ) ) <EOL> assert wrong_type . status_code == <NUM_LIT> <EOL> assert wrong_type . content_type == '<STR_LIT>' <EOL> wrong_type_response = json . loads ( wrong_type . data . decode ( ) ) <EOL> assert wrong_type_response [ '<STR_LIT:title>' ] == '<STR_LIT>' <EOL> assert "<STR_LIT>" in wrong_type_response [ '<STR_LIT>' ] <EOL> def test_schema_array ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> array_request = app_client . get ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( [ '<STR_LIT:list>' , '<STR_LIT:hello>' ] ) ) <EOL> assert array_request . status_code == <NUM_LIT:200> <EOL> assert array_request . content_type == '<STR_LIT:application/json>' <EOL> array_response = json . loads ( array_request . data . decode ( ) ) <EOL> assert array_response == [ '<STR_LIT:list>' , '<STR_LIT:hello>' ] <EOL> def test_schema_int ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> array_request = app_client . get ( '<STR_LIT>' , headers = headers , <EOL> data = json . dumps ( <NUM_LIT> ) ) <EOL> assert array_request . status_code == <NUM_LIT:200> <EOL> assert array_request . content_type == '<STR_LIT:application/json>' <EOL> array_response = json . loads ( array_request . data . decode ( ) ) <EOL> assert array_response == <NUM_LIT> <EOL> def test_global_response_definitions ( schema_app ) : <EOL> app_client = schema_app . app . test_client ( ) <EOL> resp = app_client . get ( '<STR_LIT>' ) <EOL> assert json . loads ( resp . data . decode ( ) ) == [ '<STR_LIT>' , '<STR_LIT:list>' ] </s>
