示例#1
0
    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
示例#2
0
    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
示例#3
0
    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 == []
示例#4
0
    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]
示例#5
0
    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
示例#6
0
    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
示例#7
0
    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]
示例#8
0
    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
示例#9
0
    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
示例#10
0
 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
示例#11
0
    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
示例#12
0
    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]
示例#13
0
    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
示例#14
0
 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"}]
示例#15
0
    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
示例#16
0
 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 == {}
示例#17
0
    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
示例#18
0
 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
示例#19
0
    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
示例#20
0
 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 == {}
示例#21
0
 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'}]
示例#22
0
 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 == {}
示例#23
0
 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 == {}
示例#24
0
 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 == {}
示例#25
0
 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
示例#26
0
 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'}]
示例#27
0
 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
示例#28
0
 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'}]
示例#29
0
    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
示例#30
0
 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
示例#31
0
    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]
示例#32
0
 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'}]
示例#33
0
    def test_it_should_return_missing_if_not_present(self):
        query = {}
        request = make_json_request(query)
        result = parser.parse_json(request)

        assert result == {}
示例#34
0
    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 == {}
示例#35
0
 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 == {}