gallery.accords-library.com/server/szurubooru/tests/conftest.py

61 lines
1.8 KiB
Python
Raw Normal View History

2016-04-15 12:36:00 +00:00
from datetime import datetime
import pytest
import sqlalchemy
from szurubooru import api, config, db
2016-04-15 12:36:00 +00:00
from szurubooru.util import misc
@pytest.fixture
def session():
2016-04-15 21:21:33 +00:00
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
2016-04-15 12:36:00 +00:00
engine = sqlalchemy.create_engine('sqlite:///:memory:')
session_maker = sqlalchemy.orm.sessionmaker(bind=engine)
session_instance = sqlalchemy.orm.scoped_session(session_maker)
db.Base.query = session_instance.query_property()
db.Base.metadata.create_all(bind=engine)
return session_instance
@pytest.fixture
def context_factory(session):
def factory(request=None, input=None, files=None, user=None):
ctx = api.Context()
ctx.input = input or {}
ctx.session = session
ctx.request = request or {}
ctx.files = files or {}
ctx.user = user or db.User()
return ctx
2016-04-15 12:36:00 +00:00
return factory
@pytest.fixture
def config_injector():
def injector(new_config_content):
config.config = new_config_content
return injector
@pytest.fixture
def user_factory():
def factory(name='dummy', rank='regular_user'):
user = db.User()
user.name = name
user.password = 'dummy'
user.password_salt = 'dummy'
user.password_hash = 'dummy'
user.email = 'dummy'
user.rank = rank
user.creation_time = datetime(1997, 1, 1)
user.avatar_style = db.User.AVATAR_GRAVATAR
return user
return factory
2016-04-15 18:40:12 +00:00
@pytest.fixture
def tag_factory():
def factory(names=None, category='dummy'):
tag = db.Tag()
tag.names = [db.TagName(name) for name in (names or ['dummy'])]
tag.category = category
tag.creation_time = datetime(1996, 1, 1)
return tag
return factory