tests and config for pytest and coverage
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from flaskfdx import create_app
|
||||
from flaskfdx.db import get_db, init_db
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), 'data.sql'), 'rb') as f:
|
||||
_data_sql = f.read().decode('utf8')
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
db_fd, db_path = tempfile.mkstemp()
|
||||
|
||||
app = create_app({
|
||||
'TESTING': True,
|
||||
'DATABASE': db_path,
|
||||
})
|
||||
|
||||
with app.app_context():
|
||||
init_db()
|
||||
get_db().executescript(_data_sql)
|
||||
|
||||
yield app
|
||||
|
||||
os.close(db_fd)
|
||||
os.unlink(db_path)
|
||||
|
||||
@pytest.fixture
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
@pytest.fixture
|
||||
def runner(app):
|
||||
return app.test_client()
|
||||
@@ -0,0 +1,12 @@
|
||||
INSERT INTO users(userid, email, password)
|
||||
VALUES
|
||||
('123456', 'someguy@someplace.com', 'pbkdf2:sha256:260000$F4lu8Z6tY1f5Zzjg$2c2a94b0077f88a7a771af302ed48594c6fddeaeaeb689f7afb1f5d4cb3f439f'),
|
||||
('123457', 'otherguy@otherplace.com', 'pbkdf2:sha256:260000$8AqOuHzo0h7r7CAH$7800e7378720902d6ab996adb337e7ae2c68e64f49e73e3c88cefb1ea7615bd3');
|
||||
|
||||
INSERT INTO dsw(csa, date, wa, driver, totalod, nextod, delstops, delpkgs, pustops, pupkgs, van, miles, ils, dna, allstatus)
|
||||
VALUES
|
||||
('123456', '2021-09-10', 'ABC01', 'John Doe', '12:00', '05:00', '123', '234', '10', '100', '123456', '50', '99%', '', '2');
|
||||
|
||||
INSERT INTO totals(entity, date, prepkgs, prestops, prepustops, delstops, delpkgs, pustops, pupkgs, ils, dna, allstatus, sig, eve, appt)
|
||||
VALUES
|
||||
('contract', '2021-09-10', '500', '100', '1', '125', '499', '2', '100', '99%', '1', '5', '1', '1', '1');
|
||||
@@ -0,0 +1,9 @@
|
||||
from flaskfdx import create_app
|
||||
|
||||
def test_config():
|
||||
assert not create_app().testing
|
||||
assert create_app({'TESTING': True}).testing
|
||||
|
||||
def test_hello(client):
|
||||
response = client.get('/hello')
|
||||
assert response.data == b'Hello World!'
|
||||
Reference in New Issue
Block a user