Skip to content

Commit

Permalink
Fix failing tests by comparing regex by their pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Feb 25, 2015
1 parent 32fa174 commit f67e593
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/tween_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,44 @@
from pyramid_swagger.tween import validate_outgoing_response


def assert_eq_regex_lists(left, right):
assert [r.pattern for r in left] == [r.pattern for r in right]


def test_default_exclude_paths():
assert get_exclude_paths(Mock(settings={})) \
== [re.compile(r) for r in DEFAULT_EXCLUDED_PATHS]
assert_eq_regex_lists(
get_exclude_paths(Mock(settings={})),
[re.compile(r) for r in DEFAULT_EXCLUDED_PATHS]
)


def test_exclude_path_with_string():
path_string = r'/foo/'
assert get_exclude_paths(
Mock(settings={'pyramid_swagger.exclude_paths': path_string})) \
== [re.compile(r) for r in [path_string]]
registry = Mock(settings={'pyramid_swagger.exclude_paths': path_string})
assert_eq_regex_lists(
get_exclude_paths(registry),
[re.compile(r) for r in [path_string]]
)


def test_exclude_path_with_overrides():
paths = [r'/foo/', r'/bar/']
compiled = get_exclude_paths(
Mock(settings={'pyramid_swagger.exclude_paths': paths}))
assert compiled == [re.compile(r) for r in paths]
assert_eq_regex_lists(
compiled,
[re.compile(r) for r in paths]
)


def test_exclude_path_with_old_setting():
# TODO(#63): remove deprecated `skip_validation` setting in v2.0.
paths = [r'/foo/', r'/bar/']
assert get_exclude_paths(
Mock(settings={'pyramid_swagger.skip_validation': paths})) \
== [re.compile(r) for r in paths]
assert_eq_regex_lists(
get_exclude_paths(
Mock(settings={'pyramid_swagger.skip_validation': paths})),
[re.compile(r) for r in paths]
)


def test_response_charset_missing_raises_5xx():
Expand Down

0 comments on commit f67e593

Please sign in to comment.