flask_restplus.reqparse.Argument

Here are the examples of the python api flask_restplus.reqparse.Argument taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

33 Examples 7

Example 1

Project: flask-restplus Source File: test_reqparse.py
Function: test_passing_arguments_object
    def test_passing_arguments_object(self):
        req = Request.from_values('/bubble?foo=bar')
        parser = RequestParser()
        parser.add_argument(Argument('foo'))

        args = parser.parse_args(req)
        self.assertEqual(args['foo'], 'bar')

Example 2

Project: flask-restplus Source File: test_reqparse.py
Function: test_request_parser_copy
    def test_request_parser_copy(self):
        req = Request.from_values('/bubble?foo=101&bar=baz')
        parser = RequestParser()
        foo_arg = Argument('foo', type=int)
        parser.args.append(foo_arg)
        parser_copy = parser.copy()

        # Deepcopy should create a clone of the argument object instead of
        # copying a reference to the new args list
        self.assertFalse(foo_arg in parser_copy.args)

        # Args added to new parser should not be added to the original
        bar_arg = Argument('bar')
        parser_copy.args.append(bar_arg)
        self.assertFalse(bar_arg in parser.args)

        args = parser_copy.parse_args(req)
        self.assertEqual(args['foo'], 101)
        self.assertEqual(args['bar'], 'baz')

Example 3

Project: flask-restplus Source File: test_reqparse.py
Function: test_default_type
    @patch('flask_restplus.reqparse.six')
    def test_default_type(self, mock_six):
        arg = Argument('foo')
        sentinel = object()
        arg.type(sentinel)
        mock_six.text_type.assert_called_with(sentinel)

Example 4

Project: flask-restplus Source File: test_reqparse.py
Function: test_source
    def test_source(self):
        req = Mock(['args', 'headers', 'values'])
        req.args = {'foo': 'bar'}
        req.headers = {'baz': 'bat'}
        arg = Argument('foo', location=['args'])
        self.assertEqual(arg.source(req), MultiDict(req.args))

        arg = Argument('foo', location=['headers'])
        self.assertEqual(arg.source(req), MultiDict(req.headers))

Example 5

Project: flask-restplus Source File: test_reqparse.py
Function: test_option_case_sensitive
    def test_option_case_sensitive(self):
        arg = Argument('foo', choices=['bar', 'baz'], case_sensitive=True)
        self.assertEqual(True, arg.case_sensitive)

        # Insensitive
        arg = Argument('foo', choices=['bar', 'baz'], case_sensitive=False)
        self.assertEqual(False, arg.case_sensitive)

        # Default
        arg = Argument('foo', choices=['bar', 'baz'])
        self.assertEqual(True, arg.case_sensitive)

Example 6

Project: flask-restplus Source File: test_reqparse.py
Function: test_name
    def test_name(self):
        arg = Argument('foo')
        self.assertEqual(arg.name, 'foo')

Example 7

Project: flask-restplus Source File: test_reqparse.py
Function: test_dest
    def test_dest(self):
        arg = Argument('foo', dest='foobar')
        self.assertEqual(arg.dest, 'foobar')

Example 8

Project: flask-restplus Source File: test_reqparse.py
Function: test_location_url
    def test_location_url(self):
        arg = Argument('foo', location='url')
        self.assertEqual(arg.location, 'url')

Example 9

Project: flask-restplus Source File: test_reqparse.py
Function: test_location_url_list
    def test_location_url_list(self):
        arg = Argument('foo', location=['url'])
        self.assertEqual(arg.location, ['url'])

Example 10

Project: flask-restplus Source File: test_reqparse.py
Function: test_location_header
    def test_location_header(self):
        arg = Argument('foo', location='headers')
        self.assertEqual(arg.location, 'headers')

Example 11

Project: flask-restplus Source File: test_reqparse.py
Function: test_location_json
    def test_location_json(self):
        arg = Argument('foo', location='json')
        self.assertEqual(arg.location, 'json')

Example 12

Project: flask-restplus Source File: test_reqparse.py
Function: test_location_get_json
    def test_location_get_json(self):
        arg = Argument('foo', location='get_json')
        self.assertEqual(arg.location, 'get_json')

Example 13

Project: flask-restplus Source File: test_reqparse.py
Function: test_location_header_list
    def test_location_header_list(self):
        arg = Argument('foo', location=['headers'])
        self.assertEqual(arg.location, ['headers'])

Example 14

Project: flask-restplus Source File: test_reqparse.py
Function: test_type
    def test_type(self):
        arg = Argument('foo', type=int)
        self.assertEqual(arg.type, int)

Example 15

Project: flask-restplus Source File: test_reqparse.py
Function: test_default
    def test_default(self):
        arg = Argument('foo', default=True)
        self.assertEqual(arg.default, True)

Example 16

Project: flask-restplus Source File: test_reqparse.py
Function: test_default_help
    def test_default_help(self):
        arg = Argument('foo')
        self.assertEqual(arg.help, None)

Example 17

Project: flask-restplus Source File: test_reqparse.py
Function: test_required
    def test_required(self):
        arg = Argument('foo', required=True)
        self.assertEqual(arg.required, True)

Example 18

Project: flask-restplus Source File: test_reqparse.py
Function: test_ignore
    def test_ignore(self):
        arg = Argument('foo', ignore=True)
        self.assertEqual(arg.ignore, True)

Example 19

Project: flask-restplus Source File: test_reqparse.py
Function: test_operator
    def test_operator(self):
        arg = Argument('foo', operators=['>=', '<=', '='])
        self.assertEqual(arg.operators, ['>=', '<=', '='])

Example 20

Project: flask-restplus Source File: test_reqparse.py
Function: test_action_filter
    def test_action_filter(self):
        arg = Argument('foo', action='filter')
        self.assertEqual(arg.action, 'filter')

Example 21

Project: flask-restplus Source File: test_reqparse.py
Function: test_action
    def test_action(self):
        arg = Argument('foo', action='append')
        self.assertEqual(arg.action, 'append')

Example 22

Project: flask-restplus Source File: test_reqparse.py
Function: test_choices
    def test_choices(self):
        arg = Argument('foo', choices=[1, 2])
        self.assertEqual(arg.choices, [1, 2])

Example 23

Project: flask-restplus Source File: test_reqparse.py
Function: test_default_dest
    def test_default_dest(self):
        arg = Argument('foo')
        self.assertEqual(arg.dest, None)

Example 24

Project: flask-restplus Source File: test_reqparse.py
Function: test_default_operators
    def test_default_operators(self):
        arg = Argument('foo')
        self.assertEqual(arg.operators[0], '=')
        self.assertEqual(len(arg.operators), 1)

Example 25

Project: flask-restplus Source File: test_reqparse.py
Function: test_default_default
    def test_default_default(self):
        arg = Argument('foo')
        self.assertEqual(arg.default, None)

Example 26

Project: flask-restplus Source File: test_reqparse.py
Function: test_required_default
    def test_required_default(self):
        arg = Argument('foo')
        self.assertEqual(arg.required, False)

Example 27

Project: flask-restplus Source File: test_reqparse.py
Function: test_ignore_default
    def test_ignore_default(self):
        arg = Argument('foo')
        self.assertEqual(arg.ignore, False)

Example 28

Project: flask-restplus Source File: test_reqparse.py
Function: test_action_default
    def test_action_default(self):
        arg = Argument('foo')
        self.assertEqual(arg.action, 'store')

Example 29

Project: flask-restplus Source File: test_reqparse.py
Function: test_choices_default
    def test_choices_default(self):
        arg = Argument('foo')
        self.assertEqual(len(arg.choices), 0)

Example 30

Project: flask-restplus Source File: test_reqparse.py
Function: test_convert_default_type_with_null_input
    def test_convert_default_type_with_null_input(self):
        arg = Argument('foo')
        self.assertEqual(arg.convert(None, None), None)

Example 31

Project: flask-restplus Source File: test_reqparse.py
    def test_convert_with_null_input_when_not_nullable(self):
        arg = Argument('foo', nullable=False)
        self.assertRaises(ValueError, lambda: arg.convert(None, None))

Example 32

Project: flask-restplus Source File: test_reqparse.py
    def test_source_bad_location(self):
        req = Mock(['values'])
        arg = Argument('foo', location=['foo'])
        self.assertTrue(len(arg.source(req)) == 0)  # yes, basically you don't find it

Example 33

Project: flask-restplus Source File: test_reqparse.py
Function: test_source_default_location
    def test_source_default_location(self):
        req = Mock(['values'])
        req._get_child_mock = lambda **kwargs: MultiDict()
        arg = Argument('foo')
        self.assertEqual(arg.source(req), req.values)