Skip to content

Commit b841c38

Browse files
added tests
1 parent 8bf2317 commit b841c38

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from config import TestingConfig
2+
import os
3+
import tempfile
4+
5+
import pytest
6+
7+
from app import factory
8+
9+
10+
@pytest.fixture
11+
def app():
12+
"""Create and configure a new app instance for each test."""
13+
# create a temporary file to isolate the database for each test
14+
db_fd, db_path = tempfile.mkstemp()
15+
# create the app with common test config
16+
app = factory(config=TestingConfig)
17+
yield app
18+
# close and remove the temporary database
19+
os.close(db_fd)
20+
os.unlink(db_path)
21+
22+
23+
@pytest.fixture
24+
def client(app):
25+
"""A test client for the app."""
26+
return app.test_client()
27+
28+
29+
@pytest.fixture
30+
def runner(app):
31+
"""A test runner for the app's Click commands."""
32+
return app.test_cli_runner()

tests/test_default.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
4+
def test_home(client):
5+
"""
6+
Test the home page
7+
"""
8+
response = client.get('/')
9+
assert response.status_code == 200
10+
11+
12+
def test_about(client):
13+
"""
14+
Test the about page
15+
"""
16+
response = client.get('/about')
17+
assert response.status_code == 200
18+
19+
20+
def test_contact(client):
21+
"""
22+
Test the contact page
23+
"""
24+
response = client.get('/contact')
25+
assert response.status_code == 200

0 commit comments

Comments
 (0)