File: test_options.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (45 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pytest

from falcon.request import RequestOptions
from falcon.util import deprecation


class TestRequestOptions:
    def test_option_defaults(self):
        options = RequestOptions()

        assert options.keep_blank_qs_values
        assert not options.auto_parse_form_urlencoded
        assert not options.auto_parse_qs_csv
        assert not options.strip_url_path_trailing_slash

    @pytest.mark.parametrize(
        'option_name',
        [
            'keep_blank_qs_values',
            'auto_parse_form_urlencoded',
            'auto_parse_qs_csv',
            'strip_url_path_trailing_slash',
        ],
    )
    def test_options_toggle(self, option_name):
        options = RequestOptions()

        if option_name == 'auto_parse_form_urlencoded':
            with pytest.warns(deprecation.DeprecatedWarning):
                setattr(options, option_name, True)
        else:
            setattr(options, option_name, True)
        assert getattr(options, option_name)

        setattr(options, option_name, False)
        assert not getattr(options, option_name)

    def test_incorrect_options(self):
        options = RequestOptions()

        def _assign_invalid():
            options.invalid_option_and_attribute = True

        with pytest.raises(AttributeError):
            _assign_invalid()