def test_missing_required_fields(): ctx = {} response, code = api.method_handler({'body': {}, 'headers': {}}, ctx, None) assert code == api.INVALID_REQUEST assert ctx == {} assert 'Field <login> is required.' in response assert 'Field <token> is required.' in response assert 'Field <arguments> is required.' in response assert 'Field <method> is required.' in response
def test_invalid_method(user_token): data = { 'account': 'test', 'login': '******', 'token': user_token, 'method': 'foo', 'arguments': {} } ctx = {} response, code = api.method_handler({ 'body': data, 'headers': {} }, ctx, None) assert response == api.ERRORS[api.INVALID_REQUEST] assert code == api.INVALID_REQUEST assert ctx == {}
def test_invalid_token(): data = { 'account': 'test', 'login': '******', 'token': 'invalid_token', 'method': 'online_score', 'arguments': {} } ctx = {} response, code = api.method_handler({ 'body': data, 'headers': {} }, ctx, None) assert response == api.ERRORS[api.FORBIDDEN] assert code == api.FORBIDDEN assert ctx == {}
def test_multiple_errors(user_token): data = { 'account': 42, 'login': '******', 'token': user_token, 'method': '', 'arguments': {} } ctx = {} response, code = api.method_handler({ 'body': data, 'headers': {} }, ctx, None) assert 'Error in <account> field. Expected str.' in response assert 'Field <method> is non-nullable.' in response assert code == api.INVALID_REQUEST assert ctx == {}
def get_response(self, request): return api.method_handler({ "body": request, "headers": self.headers }, self.context, self.store)
def test_invalid_request(): ctx = {} response, code = api.method_handler({'main': {}, 'headers': {}}, ctx, None) assert response == api.ERRORS[api.INVALID_REQUEST] assert code == api.INVALID_REQUEST assert ctx == {}