Skip to content

Commit

Permalink
Improve a test with a matcher
Browse files Browse the repository at this point in the history
And also use route_url
  • Loading branch information
seanh committed Apr 6, 2021
1 parent 40c103a commit 1c64af8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tests/unit/checkmate/views/ui/admin_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from pyramid.httpexceptions import HTTPFound

from checkmate.views.ui.admin import AdminPagesViews, admin_login_failure
from tests.unit.matchers import temporary_redirect_to


class TestAdminPagesViews:
Expand All @@ -12,11 +12,10 @@ def test_get(self, pyramid_request, views):

assert response == {"session": "session_value"}

def test_logged_out_redirects_to_login(self, views):
def test_logged_out_redirects_to_login(self, pyramid_request, views):
response = views.logged_out()

assert isinstance(response, HTTPFound)
assert response.location == "http://example.com/ui/api/login"
assert response == temporary_redirect_to(pyramid_request.route_url("login"))

@pytest.fixture
def views(self, pyramid_request):
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/matchers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Objects that compare equal to other objects for testing."""

from h_matchers import Any
from pyramid.response import Response


def temporary_redirect_to(location):
"""Return a matcher for any `HTTP 302 Found` redirect to the given URL."""
return Any.instance_of(Response).with_attrs(
{"status_code": 302, "location": location}
)

0 comments on commit 1c64af8

Please sign in to comment.