Skip to content

Commit

Permalink
Use existing routes_mapper fixture to fix tests
Browse files Browse the repository at this point in the history
WebOb 1.6 was just released, which includes a security measure to ensure
that `Location` headers do not contain newlines or carriage returns.
This means that locations need to be iterable objects (so they can be
used with `in`).

Rather than using a basic `Mock` for the `route_url` function, use the
existing `routes_mapper` fixture.
  • Loading branch information
nickstenning committed Mar 16, 2016
1 parent f0ab7c2 commit 994b52f
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions h/test/admin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def test_admins_add_returns_index_on_NoSuchUserError(make_admin, admins_index):


# The fixtures required to mock all of admins_remove()'s dependencies.
admins_remove_fixtures = pytest.mark.usefixtures('User')
admins_remove_fixtures = pytest.mark.usefixtures('User', 'routes_mapper')


@admins_remove_fixtures
Expand All @@ -245,7 +245,6 @@ def test_admins_remove_calls_get_by_username(User):
Mock(username="bob"),
Mock(username="frank")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()

admin.admins_remove(request)

Expand All @@ -258,7 +257,6 @@ def test_admins_remove_sets_admin_to_False(User):
Mock(username="bob"),
Mock(username="frank")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()
user = Mock(admin=True)
User.get_by_username.return_value = user

Expand All @@ -273,7 +271,6 @@ def test_admins_remove_returns_redirect_on_success(User):
Mock(username="bob"),
Mock(username="frank")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()

response = admin.admins_remove(request)

Expand All @@ -284,7 +281,6 @@ def test_admins_remove_returns_redirect_on_success(User):
def test_admins_remove_returns_redirect_when_too_few_admins(User):
User.admins.return_value = [Mock(username="fred")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()

response = admin.admins_remove(request)

Expand All @@ -295,7 +291,6 @@ def test_admins_remove_returns_redirect_when_too_few_admins(User):
def test_admins_remove_does_not_delete_last_admin(User):
User.admins.return_value = [Mock(username="fred")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()
user = Mock(admin=True)
User.get_by_username.return_value = user

Expand Down Expand Up @@ -386,7 +381,7 @@ def test_staff_add_returns_index_on_NoSuchUserError(make_staff, staff_index):


# The fixtures required to mock all of staff_remove()'s dependencies.
staff_remove_fixtures = pytest.mark.usefixtures('User')
staff_remove_fixtures = pytest.mark.usefixtures('User', 'routes_mapper')


@staff_remove_fixtures
Expand All @@ -395,7 +390,6 @@ def test_staff_remove_calls_get_by_username(User):
Mock(username="bob"),
Mock(username="frank")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()

admin.staff_remove(request)

Expand All @@ -408,7 +402,6 @@ def test_staff_remove_sets_staff_to_False(User):
Mock(username="bob"),
Mock(username="frank")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()
user = Mock(staff=True)
User.get_by_username.return_value = user

Expand All @@ -423,7 +416,6 @@ def test_staff_remove_returns_redirect_on_success(User):
Mock(username="bob"),
Mock(username="frank")]
request = DummyRequest(params={"remove": "fred"})
request.route_url = Mock()

response = admin.admins_remove(request)

Expand Down

0 comments on commit 994b52f

Please sign in to comment.