File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments