Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Pyramid functional testing example
from contextlib import contextmanager
import tempfile
from unittest import mock
import factory
import pytest
from betterevidence import models
def engine(app_settings):
from betterevidence.models.meta import Base
from betterevidence.models import get_engine
engine = get_engine(app_settings)
return engine
def connection(engine):
connection = engine.connect()
yield connection
def transaction(connection):
transaction = connection.begin()
yield transaction
def session(app_settings, connection, transaction):
from sqlalchemy.orm import sessionmaker
Session = sessionmaker()
session = Session(bind=connection)
return session
def app_settings():
yield {"secret": "secret", "sqlalchemy.url": "sqlite://"}
def root_app_inner(app_settings):
from betterevidence import main
app = main({}, **app_settings)
app.registry["dbsession_factory"].kw["bind"] = connection
yield app
def root_app(root_app_inner, connection):
root_app_inner.registry["dbsession_factory"].kw["bind"] = connection
yield root_app_inner
def webtest(root_app, session):
from webtest import TestApp
return TestApp(root_app)
def test_sites_json_returns_empty_list_if_no_sites(self, webtest):
result = webtest.get("/sites.json")
assert result.json == []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment