minor improvements
This commit is contained in:
parent
b8edb958d3
commit
1adafc1fc7
@ -12,28 +12,28 @@ def app():
|
||||
"SECRET_KEY": "This is my very secret key",
|
||||
"TESTING": True
|
||||
}
|
||||
app = create_app(test_config)
|
||||
_app = create_app(test_config)
|
||||
|
||||
# other setup can go here
|
||||
|
||||
yield app
|
||||
yield _app
|
||||
|
||||
# clean up / reset resources here
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def db(app):
|
||||
with app.app_context():
|
||||
def db(_app):
|
||||
with _app.app_context():
|
||||
yield _db
|
||||
_db.drop_all()
|
||||
_db.create_all()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
def client(_app):
|
||||
return _app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def runner(app):
|
||||
return app.test_cli_runner()
|
||||
def runner(_app):
|
||||
return _app.test_cli_runner()
|
||||
@ -2,13 +2,14 @@ from the_works.models import Genre
|
||||
import pytest
|
||||
|
||||
|
||||
def test_genre_all(client, db, mocker):
|
||||
def test_genre_all(client, mocker):
|
||||
"""Test view all() from genre.py."""
|
||||
|
||||
# mock database function
|
||||
# Note: The original method returns an sqlalchemy.engine.Result.ScalarResult, not a list, but the template code
|
||||
# uses the return value in a way that works for both ScalarResult and list
|
||||
mocker.patch("the_works.database.db.session.scalars", return_value=[
|
||||
# mocker.patch("the_works.database.db.session.scalars", return_value=[
|
||||
mocker.patch("flask_sqlalchemy.SQLAlchemy.session.scalars", return_value=[
|
||||
Genre(ID=4, Genre="bla"),
|
||||
Genre(ID=26, Genre="blubb")
|
||||
])
|
||||
@ -23,11 +24,11 @@ def test_genre_all(client, db, mocker):
|
||||
assert response.status_code == 405
|
||||
|
||||
|
||||
def test_genre_create(client, db, mocker):
|
||||
def test_genre_create(client, mocker):
|
||||
"""Test view create() from genre.py."""
|
||||
|
||||
# mock database function
|
||||
mocker.patch("the_works.database.db.session.add")
|
||||
mocker.patch("flask_sqlalchemy.SQLAlchemy.session.add")
|
||||
|
||||
# test a POST request with good data
|
||||
response = client.post("/genre/create", data={"form_Genre": "Testname"}, follow_redirects=True)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user