-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The tests are only sample tests to get things started.
- Loading branch information
Showing
6 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,7 @@ | |
*.pyc | ||
*~ | ||
.coverage | ||
coverage.xml | ||
coverage | ||
reports/ | ||
build/ | ||
dist/ | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
import webtest | ||
from pyramid.scripting import prepare | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def app(): | ||
"""Fixtures that returns the Sambal WSGI app. | ||
We can inject env vars here if necessary, but only before the import. | ||
""" | ||
import sambal | ||
|
||
return sambal.app | ||
|
||
|
||
@pytest.fixture | ||
def testapp(app): | ||
"""Fixture that returns a Sambal WebTest app.""" | ||
return webtest.TestApp( | ||
app, | ||
extra_environ={ | ||
"HTTP_HOST": "example.com", | ||
}, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def app_request(app): | ||
"""Returns a real HTTP request for use with testing Sambal views.""" | ||
with prepare(registry=app.registry) as env: | ||
req = env["request"] | ||
req.host = "example.com" | ||
yield req |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def test_root(testapp): | ||
response = testapp.get("/", status=200) | ||
assert b"Sambal Login" in response.body | ||
|
||
|
||
def test_notfound(testapp): | ||
response = testapp.get("/does-not-exist/", status=404) | ||
assert response.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from unittest.mock import Mock | ||
|
||
from sambal.views.auth import login | ||
|
||
|
||
def test_login_view(app_request): | ||
"""A sample test that calls the login view directly. | ||
The 'real request' lacks a matched_route property required by the | ||
login view, which can be done in the test rather than fixture. | ||
""" | ||
app_request.matched_route = Mock() | ||
context = login(app_request) | ||
assert "form" in context | ||
assert "return_url" in context |