squeaknode/tests/server/conftest.py
Jonathan Zernik 77bec59911
Allow post squeaks (#4)
* Remove login_required and user id from blog posts.

* Remove login_required for blog endpoints.

* Rename update endpoint to show

* Remove auth.

* Tests passing.

* Remove unused auth fixture

* Remove users table from db
2020-03-17 18:07:47 -07:00

44 lines
1.1 KiB
Python

import os
import tempfile
import pytest
from squeaknode.server import create_app
from squeaknode.server.db import get_db
from squeaknode.server.db import init_db
# read in SQL for populating test data
with open(os.path.join(os.path.dirname(__file__), "data.sql"), "rb") as f:
_data_sql = f.read().decode("utf8")
@pytest.fixture
def app():
"""Create and configure a new app instance for each test."""
# create a temporary file to isolate the database for each test
db_fd, db_path = tempfile.mkstemp()
# create the app with common test config
app = create_app({"TESTING": True, "DATABASE": db_path})
# create the database and load test data
with app.app_context():
init_db()
get_db().executescript(_data_sql)
yield app
# close and remove the temporary database
os.close(db_fd)
os.unlink(db_path)
@pytest.fixture
def client(app):
"""A test client for the app."""
return app.test_client()
@pytest.fixture
def runner(app):
"""A test runner for the app's Click commands."""
return app.test_cli_runner()