-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup unit tests and attempt database mock
- Loading branch information
Showing
9 changed files
with
136 additions
and
22 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
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 |
---|---|---|
|
@@ -41,3 +41,4 @@ dependencies: | |
- wtforms-sqlalchemy | ||
- flask-dance | ||
- bootstrap-flask ~=2.3.0 | ||
- mock-alchemy~=0.2.6 |
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,38 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
from flask_login import FlaskLoginClient | ||
from mock_alchemy.mocking import UnifiedAlchemyMagicMock | ||
|
||
from usaon_vta_survey import app as my_app | ||
from usaon_vta_survey.models.tables import User | ||
|
||
|
||
@pytest.fixture() | ||
def app(): | ||
yield my_app | ||
|
||
|
||
@pytest.fixture() | ||
def client(app): | ||
return app.test_client() | ||
|
||
|
||
@pytest.fixture() | ||
def session_with_user(): | ||
session = UnifiedAlchemyMagicMock( | ||
data=[ | ||
( | ||
[mock.call.query(User), mock.call.get(1)], | ||
[User(id=1, email='[email protected]', name='foo bar', role_id='admin')], | ||
) | ||
] | ||
) | ||
return session | ||
|
||
|
||
@pytest.fixture() | ||
def client_logged_in(app, session_with_user): | ||
app.test_client_class = FlaskLoginClient | ||
user = session_with_user.query(User).get(1) | ||
return app.test_client(user=user) |
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,2 @@ | ||
def test_foo(): | ||
assert True |
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,5 @@ | ||
def test_logged_in(client_logged_in): | ||
actual = client_logged_in.get('/') | ||
# breakpoint() | ||
expected = ... | ||
assert actual == expected |
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,4 @@ | ||
def test_logged_out(client): | ||
actual = client.get('/').location | ||
expected = '/login?next=%2F' | ||
assert actual == expected |
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,7 @@ | ||
from usaon_vta_survey.constants.version import VERSION | ||
|
||
|
||
def test_version_matches(client): | ||
actual = client.get('/login', follow_redirects=True).text | ||
expected = VERSION | ||
assert expected in actual |