File tree Expand file tree Collapse file tree 6 files changed +80
-8
lines changed Expand file tree Collapse file tree 6 files changed +80
-8
lines changed Original file line number Diff line number Diff line change 1- from config import DevelopmentConfig
1+ from config import DevelopmentConfig , TestingConfig
22from flask import Flask , render_template
33from flask_mail import Mail
44from flask_orator import Orator
1313cache = Cache ()
1414login_manager = LoginManager ()
1515
16+ DepotManager .configure (name = 'default' , config = {
17+ 'depot.storage_path' : 'storage/public'
18+ }, prefix = 'depot.' )
19+
1620
1721def factory (config = DevelopmentConfig ) -> Flask :
1822 app = Flask (__name__ )
@@ -41,11 +45,9 @@ def factory(config=DevelopmentConfig) -> Flask:
4145 # initialize login_manager
4246 register_login_manager (app )
4347
44- # configure depotmanager
45- DepotManager .configure (name = 'default' , config = {
46- 'depot.storage_path' : 'storage/public'
47- }, prefix = 'depot.' )
48- app .wsgi_app = DepotManager .make_middleware (app .wsgi_app , mountpoint = "/public" )
48+ if config is not TestingConfig :
49+ # configure depotmanager
50+ app .wsgi_app = DepotManager .make_middleware (app .wsgi_app , mountpoint = "/public" )
4951
5052 # initialize celery
5153 celery .conf .update (app .config )
Original file line number Diff line number Diff line change 11import os
22
3- from config .database import database
3+ from config .database import database , test_database
44from dotenv import load_dotenv
55
66basedir = os .path .abspath (os .path .dirname (__name__ ))
@@ -37,7 +37,11 @@ class DevelopmentConfig(Config):
3737class TestingConfig (Config ):
3838 DEBUG = False
3939 TESTING = True
40- ORATOR_DATABASES = database
40+ ORATOR_DATABASES = test_database
41+ CELERY_BROKER_URL = os .getenv ('CELERY_BROKER_URL' )
42+ RESULT_BACKEND = os .getenv ('CELERY_RESULT_BACKEND' )
43+ REDIS_HOST = os .getenv ('REDIS_HOST' )
44+ REDIS_PORT = os .getenv ('REDIS_PORT' )
4145
4246
4347# create the production config
Original file line number Diff line number Diff line change 2424 'database' : os .getenv ('DB_DATABASE' ),
2525 },
2626}
27+
28+ test_database = {
29+ 'default' : 'sqlite' ,
30+
31+ 'sqlite' : {
32+ 'driver' : 'sqlite' ,
33+ 'database' : ':memory:' ,
34+ },
35+ }
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