コード例 #1
0
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
    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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
    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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
    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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
    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
ファイル: test_tornadoparser.py プロジェクト: scprek/webargs
 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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
 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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
 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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
 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
ファイル: test_tornadoparser.py プロジェクト: venuatu/webargs
 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 == {}