You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
985 B
53 lines
985 B
# -*- coding: utf-8 -*-
|
|
"""Defines fixtures available to all tests."""
|
|
|
|
import logging
|
|
|
|
import pytest
|
|
from webtest import TestApp
|
|
|
|
from harambee_led_bord.app import create_app
|
|
from harambee_led_bord.database import db as _db
|
|
|
|
from .factories import UserFactory
|
|
|
|
|
|
@pytest.fixture
|
|
def app():
|
|
"""Create application for the tests."""
|
|
_app = create_app("tests.settings")
|
|
_app.logger.setLevel(logging.CRITICAL)
|
|
ctx = _app.test_request_context()
|
|
ctx.push()
|
|
|
|
yield _app
|
|
|
|
ctx.pop()
|
|
|
|
|
|
@pytest.fixture
|
|
def testapp(app):
|
|
"""Create Webtest app."""
|
|
return TestApp(app)
|
|
|
|
|
|
@pytest.fixture
|
|
def db(app):
|
|
"""Create database for the tests."""
|
|
_db.app = app
|
|
with app.app_context():
|
|
_db.create_all()
|
|
|
|
yield _db
|
|
|
|
# Explicitly close DB connection
|
|
_db.session.close()
|
|
_db.drop_all()
|
|
|
|
|
|
@pytest.fixture
|
|
def user(db):
|
|
"""Create user for the tests."""
|
|
user = UserFactory(password="myprecious")
|
|
db.session.commit()
|
|
return user
|
|
|