def test_it_should_return_missing_if_not_present(self): query = {} arg = Arg(multiple=False) request = make_json_request(query) result = parser.parse_json(request, name, arg) assert result is Missing
def test_it_should_return_empty_list_if_multiple_and_not_present(self): query = {} arg = Arg(multiple=True) request = make_json_request(query) result = parser.parse_json(request, name, arg) assert result is Missing
def test_it_should_return_empty_list_if_multiple_and_not_present(self): query = {} arg = Arg(multiple=True) request = make_json_request(query) result = parser.parse_json(request, name, arg) assert result == []
def test_it_should_get_multiple_values(self): query = {name: [value, value]} arg = Arg(multiple=True) request = make_json_request(query) result = parser.parse_json(request, name, arg) assert result == [value, value]
def test_it_should_get_single_values(self): query = {name: value} arg = Arg(multiple=False) request = make_json_request(query) result = parser.parse_json(request, name, arg) assert result == value
def test_it_should_get_multiple_values(self): query = {name: [value, value]} field = fields.List(fields.Field()) request = make_json_request(query) result = parser.parse_json(request, name, field) assert result == [value, value]
def test_it_should_return_empty_list_if_multiple_and_not_present(self): query = {} field = fields.List(fields.Field()) request = make_json_request(query) result = parser.parse_json(request, name, field) assert result is missing
def test_it_should_return_missing_if_not_present(self): query = {} field = fields.Field() request = make_json_request(query) result = parser.parse_json(request, name, field) assert result is missing
def test_it_should_handle_type_error_on_parse_json(self): field = fields.Field() request = make_request(body=tornado.concurrent.Future, headers={"Content-Type": "application/json"}) result = parser.parse_json(request, name, field) assert parser._cache["json"] == {} assert result is missing
def test_it_should_get_single_values(self): query = {name: value} field = fields.Field() request = make_json_request(query) result = parser.parse_json(request, name, field) assert result == value
def test_it_should_get_multiple_nested_values(self): query = {name: [{"id": 1, "name": "foo"}, {"id": 2, "name": "bar"}]} field = fields.List( fields.Nested({"id": fields.Field(), "name": fields.Field()}) ) request = make_json_request(query) result = parser.parse_json(request, name, field) assert result == [{"id": 1, "name": "foo"}, {"id": 2, "name": "bar"}]
def test_parsing_request_with_vendor_content_type(self): query = {name: value} field = fields.Field() request = make_json_request( query, content_type="application/vnd.api+json; charset=UTF-8") result = parser.parse_json(request, name, field) assert result == value
def test_it_should_handle_type_error_on_parse_json(self): request = make_request( body=tornado.concurrent.Future, headers={'Content-Type': 'application/json'}, ) result = parser.parse_json(request) assert parser._cache['json'] == {} assert result == {}
def test_it_should_return_none_if_not_present(self): query = {} arg = Arg(multiple=False) request = make_json_request(query) parser._parse_json_body(request) result = parser.parse_json(request, name, arg) assert result == None
def test_it_should_handle_type_error_on_parse_json(self): arg = Arg() request = make_request( body=tornado.concurrent.Future, headers={'Content-Type': 'application/json'}, ) result = parser.parse_json(request, name, arg) assert parser._cache['json'] == {} assert result is Missing
def test_parsing_clears_cache(self): request = make_json_request({'string': 'value', 'integer': [1, 2]}) string_result = parser.parse_json(request, 'string', Arg(str)) assert string_result == 'value' assert 'json' in parser._cache assert 'string' in parser._cache['json'] assert 'integer' in parser._cache['json'] attrs = {'string': Arg(str), 'integer': Arg(int, multiple=True)} parser.parse(attrs, request) assert parser._cache == {}
def test_it_should_get_multiple_nested_values(self): query = {name: [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]} field = fields.List( fields.Nested({ 'id': fields.Field(), 'name': fields.Field() })) request = make_json_request(query) result = parser.parse_json(request, name, field) assert result == [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]
def test_parsing_clears_cache(self): request = make_json_request({"string": "value", "integer": [1, 2]}) string_result = parser.parse_json(request, "string", fields.Str()) assert string_result == "value" assert "json" in parser._cache assert "string" in parser._cache["json"] assert "integer" in parser._cache["json"] attrs = {"string": fields.Str(), "integer": fields.List(fields.Int())} parser.parse(attrs, request) assert parser._cache == {}
def test_parsing_clears_cache(self): request = make_json_request({'string': 'value', 'integer': [1, 2]}) string_result = parser.parse_json(request, 'string', fields.Str()) assert string_result == 'value' assert 'json' in parser._cache assert 'string' in parser._cache['json'] assert 'integer' in parser._cache['json'] attrs = {'string': fields.Str(), 'integer': fields.List(fields.Int())} parser.parse(attrs, request) assert parser._cache == {}
def test_parsing_clears_cache(self): request = make_json_request({ 'string': 'value', 'integer': [1, 2] }) string_result = parser.parse_json(request, 'string', Arg(str)) assert string_result == 'value' assert 'json' in parser._cache assert 'string' in parser._cache['json'] assert 'integer' in parser._cache['json'] attrs = {'string': Arg(str), 'integer': Arg(int, multiple=True)} parser.parse(attrs, request) assert parser._cache == {}
def test_it_should_handle_value_error_on_parse_json(self): arg = Arg() request = make_request('this is json not') result = parser.parse_json(request, name, arg) assert parser._cache['json'] == {} assert result is Missing
def test_it_should_get_multiple_nested_values(self): query = {name: [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]} arg = Arg({'id': Arg(), 'name': Arg()}, multiple=True) request = make_json_request(query) result = parser.parse_json(request, name, arg) assert result == [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]
def test_parsing_request_with_vendor_content_type(self): query = {name: value} request = make_json_request(query, content_type='application/vnd.api+json; charset=UTF-8') result = parser.parse_json(request)[name] assert result == value
def test_it_should_handle_value_error_on_parse_json(self): field = fields.Field() request = make_request("this is json not") result = parser.parse_json(request, name, field) assert parser._cache["json"] == {} assert result is missing
def test_it_should_get_multiple_values(self): query = {name: [value, value]} request = make_json_request(query) result = parser.parse_json(request)[name] assert result == [value, value]
def test_it_should_get_multiple_nested_values(self): query = {name: [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]} request = make_json_request(query) result = parser.parse_json(request)[name] assert result == [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]
def test_it_should_return_missing_if_not_present(self): query = {} request = make_json_request(query) result = parser.parse_json(request) assert result == {}
def test_it_should_return_empty_list_if_multiple_and_not_present(self): query = {} request = make_json_request(query) result = parser.parse_json(request) assert result == {}
def test_it_should_handle_value_error_on_parse_json(self): request = make_request('this is json not') result = parser.parse_json(request) assert parser._cache['json'] == {} assert result == {}