Skip to content

Commit 66c76af

Browse files
test config updated
1 parent bc1e2fc commit 66c76af

File tree

6 files changed

+80
-8
lines changed

6 files changed

+80
-8
lines changed

app/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from config import DevelopmentConfig
1+
from config import DevelopmentConfig, TestingConfig
22
from flask import Flask, render_template
33
from flask_mail import Mail
44
from flask_orator import Orator
@@ -13,6 +13,10 @@
1313
cache = Cache()
1414
login_manager = LoginManager()
1515

16+
DepotManager.configure(name='default', config={
17+
'depot.storage_path': 'storage/public'
18+
}, prefix='depot.')
19+
1620

1721
def 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)

config/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from config.database import database
3+
from config.database import database, test_database
44
from dotenv import load_dotenv
55

66
basedir = os.path.abspath(os.path.dirname(__name__))
@@ -37,7 +37,11 @@ class DevelopmentConfig(Config):
3737
class 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

config/database.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@
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+
}

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)