Skip to content

Commit

Permalink
Added tests for APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
rozuur committed Jul 30, 2020
1 parent 044b545 commit b7a74a4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/api/test_core.py
@@ -0,0 +1,5 @@
def test_health(client, app):
url_prefix = app.config["API_URL_PREFIX"]
# test that viewing the page renders without template errors
assert client.get(f"/{url_prefix}/api/v1/core/health").status_code == 200
assert client.get(f"/{url_prefix}/api/v1/core/info").status_code == 200
34 changes: 34 additions & 0 deletions tests/conftest.py
@@ -0,0 +1,34 @@
import os
import tempfile

import pytest

from app import create_app
from config import Config


@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(Config)

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()
11 changes: 11 additions & 0 deletions tests/test_app.py
@@ -0,0 +1,11 @@
import pytest

from app import create_app
from config import Config


def test_creation():
conf = Config()
conf.API_URL_PREFIX = "invalid with spaces"
with pytest.raises(ValueError, match="url_prefix"):
create_app(conf)

0 comments on commit b7a74a4

Please sign in to comment.