<s> import json <EOL> from nose . tools import * <EOL> from tests import ( prepare_database , with_database , assert_json_equals , <EOL> TEST_1_LENGTH , <EOL> TEST_1_FP , <EOL> TEST_1_FP_RAW , <EOL> TEST_2_LENGTH , <EOL> TEST_2_FP , <EOL> TEST_2_FP_RAW , <EOL> ) <EOL> from werkzeug . wrappers import Request <EOL> from werkzeug . test import EnvironBuilder <EOL> from werkzeug . datastructures import MultiDict <EOL> from acoustid import tables <EOL> from acoustid . api import errors <EOL> from acoustid . api . v2 import ( <EOL> LookupHandler , <EOL> LookupHandlerParams , <EOL> SubmitHandler , <EOL> SubmitHandlerParams , <EOL> APIHandler , <EOL> APIHandlerParams , <EOL> ) <EOL> from acoustid . api . v2 . misc import ( <EOL> UserCreateAnonymousHandler , <EOL> UserLookupHandler , <EOL> ) <EOL> from acoustid . utils import provider <EOL> def test_ok ( ) : <EOL> handler = APIHandler ( ) <EOL> resp = handler . _ok ( { '<STR_LIT>' : [ { '<STR_LIT:id>' : <NUM_LIT:1> , '<STR_LIT:name>' : '<STR_LIT>' } ] } , '<STR_LIT>' ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = '<STR_LIT>' <EOL> assert_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> def test_error ( ) : <EOL> handler = APIHandler ( ) <EOL> resp = handler . _error ( <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = '<STR_LIT>' <EOL> assert_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> resp = handler . _error ( <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , status = <NUM_LIT> ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = '<STR_LIT>' <EOL> assert_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> @ with_database <EOL> def test_api_handler_params_jsonp ( conn ) : <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = APIHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( '<STR_LIT>' , params . format ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = APIHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( '<STR_LIT>' , params . format ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = APIHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( '<STR_LIT>' , params . format ) <EOL> @ with_database <EOL> def test_lookup_handler_params ( conn ) : <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = LookupHandlerParams ( ) <EOL> assert_raises ( errors . UnknownFormatError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = LookupHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = LookupHandlerParams ( ) <EOL> assert_raises ( errors . InvalidAPIKeyError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = LookupHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) } ) <EOL> params = LookupHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = LookupHandlerParams ( ) <EOL> assert_raises ( errors . InvalidFingerprintError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP } ) <EOL> params = LookupHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( '<STR_LIT>' , params . format ) <EOL> assert_equals ( <NUM_LIT:1> , params . application_id ) <EOL> assert_equals ( TEST_1_LENGTH , params . fingerprints [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , params . fingerprints [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> class WebServiceErrorHandler ( APIHandler ) : <EOL> params_class = APIHandlerParams <EOL> def _handle_internal ( self , params ) : <EOL> raise errors . InvalidAPIKeyError ( ) <EOL> class InternalErrorHandler ( APIHandler ) : <EOL> params_class = APIHandlerParams <EOL> def _handle_internal ( self , params ) : <EOL> return { '<STR_LIT>' : <NUM_LIT> / <NUM_LIT:0> } <EOL> @ with_database <EOL> def test_apihandler_ws_error ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = WebServiceErrorHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT:error>" , <EOL> "<STR_LIT:error>" : { <EOL> "<STR_LIT:message>" : "<STR_LIT>" , <EOL> "<STR_LIT:code>" : <NUM_LIT:4> , <EOL> } <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> handler = InternalErrorHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT:error>" , <EOL> "<STR_LIT:error>" : { <EOL> "<STR_LIT:message>" : "<STR_LIT>" , <EOL> "<STR_LIT:code>" : <NUM_LIT:5> , <EOL> } <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> @ with_database <EOL> def test_lookup_handler ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = LookupHandler ( connect = provider ( conn ) ) <EOL> handler = LookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> prepare_database ( conn , """<STR_LIT>""" , ( TEST_1_LENGTH , TEST_1_FP_RAW ) ) <EOL> handler = LookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : <NUM_LIT:1.0> , <EOL> } ] , <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP , '<STR_LIT>' : '<STR_LIT:1>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = LookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : <NUM_LIT:1.0> , <EOL> "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" } ] , <EOL> } ] , <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> prepare_database ( conn , "<STR_LIT>" ) <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP , '<STR_LIT>' : '<STR_LIT:2>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = LookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : <NUM_LIT:1.0> , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> } , { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> } , <EOL> } , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> } ] , <EOL> } , { <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:title>" : "<STR_LIT>" , <EOL> } , <EOL> } , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> } ] , <EOL> } ] , <EOL> } ] , <EOL> } ] <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> prepare_database ( conn , """<STR_LIT>""" , ( TEST_1_LENGTH , TEST_1_FP_RAW ) ) <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = LookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:id>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : <NUM_LIT:1.0> , <EOL> } ] , <EOL> } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> @ with_database <EOL> def test_submit_handler_params ( conn ) : <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . UnknownFormatError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . InvalidAPIKeyError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . InvalidUserAPIKeyError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . InvalidForeignIDError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . InvalidUUIDError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . InvalidUUIDError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . InvalidUUIDError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> assert_raises ( errors . MissingParameterError , params . parse , values , conn ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( <NUM_LIT:1> , len ( params . submissions ) ) <EOL> assert_equals ( [ '<STR_LIT>' , '<STR_LIT>' ] , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_LENGTH , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_2_LENGTH ) , <EOL> '<STR_LIT>' : TEST_2_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( <NUM_LIT:2> , len ( params . submissions ) ) <EOL> assert_equals ( [ '<STR_LIT>' ] , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_LENGTH , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( [ '<STR_LIT>' ] , params . submissions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_2_LENGTH , params . submissions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_2_FP_RAW , params . submissions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , params . submissions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> values = MultiDict ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , <EOL> '<STR_LIT>' : TEST_1_FP , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_2_LENGTH ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> params = SubmitHandlerParams ( ) <EOL> params . parse ( values , conn ) <EOL> assert_equals ( <NUM_LIT:1> , len ( params . submissions ) ) <EOL> assert_equals ( [ '<STR_LIT>' ] , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_LENGTH , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , params . submissions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> @ with_database <EOL> def test_submit_handler ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = SubmitHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> query = tables . submission . select ( ) . order_by ( tables . submission . c . id . desc ( ) ) . limit ( <NUM_LIT:1> ) <EOL> submission = conn . execute ( query ) . fetchone ( ) <EOL> assert_equals ( '<STR_LIT>' , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:1> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_LENGTH , submission [ '<STR_LIT>' ] ) <EOL> @ with_database <EOL> def test_submit_handler_with_meta ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:2>' , <EOL> '<STR_LIT>' : '<STR_LIT:3>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = SubmitHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> query = tables . submission . select ( ) . order_by ( tables . submission . c . id . desc ( ) ) . limit ( <NUM_LIT:1> ) <EOL> submission = conn . execute ( query ) . fetchone ( ) <EOL> assert_equals ( '<STR_LIT>' , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:1> , submission [ '<STR_LIT>' ] ) <EOL> row = conn . execute ( "<STR_LIT>" ) . fetchone ( ) <EOL> expected = { <EOL> '<STR_LIT:id>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT> <EOL> } <EOL> assert_equals ( expected , dict ( row ) ) <EOL> @ with_database <EOL> def test_submit_handler_puid ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = SubmitHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> query = tables . submission . select ( ) . order_by ( tables . submission . c . id . desc ( ) ) . limit ( <NUM_LIT:1> ) <EOL> submission = conn . execute ( query ) . fetchone ( ) <EOL> assert_equals ( None , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:1> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_LENGTH , submission [ '<STR_LIT>' ] ) <EOL> @ with_database <EOL> def test_submit_handler_foreignid ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( TEST_1_LENGTH ) , '<STR_LIT>' : TEST_1_FP , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = SubmitHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> expected = { "<STR_LIT:status>" : "<STR_LIT>" } <EOL> assert_json_equals ( expected , resp . data ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> query = tables . submission . select ( ) . order_by ( tables . submission . c . id . desc ( ) ) . limit ( <NUM_LIT:1> ) <EOL> submission = conn . execute ( query ) . fetchone ( ) <EOL> assert_equals ( None , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( None , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:1> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT:1> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( <NUM_LIT> , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_FP_RAW , submission [ '<STR_LIT>' ] ) <EOL> assert_equals ( TEST_1_LENGTH , submission [ '<STR_LIT>' ] ) <EOL> query = tables . foreignid_vendor . select ( ) . order_by ( tables . foreignid_vendor . c . id . desc ( ) ) . limit ( <NUM_LIT:1> ) <EOL> row = conn . execute ( query ) . fetchone ( ) <EOL> assert_equals ( <NUM_LIT:1> , row [ '<STR_LIT:id>' ] ) <EOL> assert_equals ( '<STR_LIT:foo>' , row [ '<STR_LIT:name>' ] ) <EOL> query = tables . foreignid . select ( ) . order_by ( tables . foreignid . c . id . desc ( ) ) . limit ( <NUM_LIT:1> ) <EOL> row = conn . execute ( query ) . fetchone ( ) <EOL> assert_equals ( <NUM_LIT:1> , row [ '<STR_LIT:id>' ] ) <EOL> assert_equals ( <NUM_LIT:1> , row [ '<STR_LIT>' ] ) <EOL> assert_equals ( '<STR_LIT>' , row [ '<STR_LIT:name>' ] ) <EOL> @ with_database <EOL> def test_user_create_anonumous_handler ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = UserCreateAnonymousHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> data = json . loads ( resp . data ) <EOL> assert_equals ( '<STR_LIT>' , data [ '<STR_LIT:status>' ] ) <EOL> query = tables . account . select ( ) . where ( tables . account . c . apikey == data [ '<STR_LIT:user>' ] [ '<STR_LIT>' ] ) <EOL> user = conn . execute ( query ) . fetchone ( ) <EOL> assert_true ( user ) <EOL> @ with_database <EOL> def test_user_lookup_handler ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = UserLookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> data = json . loads ( resp . data ) <EOL> assert_equal ( '<STR_LIT>' , data [ '<STR_LIT:status>' ] ) <EOL> assert_equal ( '<STR_LIT>' , data [ '<STR_LIT:user>' ] [ '<STR_LIT>' ] ) <EOL> @ with_database <EOL> def test_user_lookup_handler_missing ( conn ) : <EOL> values = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:user>' : '<STR_LIT>' } <EOL> builder = EnvironBuilder ( method = '<STR_LIT:POST>' , data = values ) <EOL> handler = UserLookupHandler ( connect = provider ( conn ) ) <EOL> resp = handler . handle ( Request ( builder . get_environ ( ) ) ) <EOL> assert_equals ( '<STR_LIT>' , resp . content_type ) <EOL> assert_equals ( '<STR_LIT>' , resp . status ) <EOL> data = json . loads ( resp . data ) <EOL> assert_equal ( '<STR_LIT:error>' , data [ '<STR_LIT:status>' ] ) <EOL> assert_equal ( <NUM_LIT:6> , data [ '<STR_LIT:error>' ] [ '<STR_LIT:code>' ] ) </s>
