First commit, basic config (with db) and app handler
this has 100% test coverage and i intend to keep it that way. api docs have a good start but still need narrative. several more things must be added before i can seriously consider incorporating into rattail but this seemed a good save point
This commit is contained in:
commit
5c3c42d6b3
36 changed files with 3322 additions and 0 deletions
53
tests/test_app.py
Normal file
53
tests/test_app.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import orm
|
||||
|
||||
from wuttjamaican import app, db
|
||||
|
||||
|
||||
class TestAppHandler(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = MagicMock()
|
||||
self.app = app.AppHandler(self.config)
|
||||
|
||||
def test_init(self):
|
||||
self.assertIs(self.app.config, self.config)
|
||||
self.assertEqual(self.app.handlers, {})
|
||||
|
||||
def test_make_session(self):
|
||||
session = self.app.make_session()
|
||||
self.assertIsInstance(session, db.Session.class_)
|
||||
|
||||
def test_short_session(self):
|
||||
short_session = MagicMock()
|
||||
mockdb = MagicMock(short_session=short_session)
|
||||
|
||||
with patch.dict('sys.modules', **{'wuttjamaican.db': mockdb}):
|
||||
|
||||
with self.app.short_session(foo='bar') as s:
|
||||
short_session.assert_called_once_with(
|
||||
foo='bar', factory=self.app.make_session)
|
||||
|
||||
def test_get_setting(self):
|
||||
Session = orm.sessionmaker()
|
||||
engine = sa.create_engine('sqlite://')
|
||||
session = Session(bind=engine)
|
||||
session.execute(sa.text("""
|
||||
create table setting (
|
||||
name varchar(255) primary key,
|
||||
value text
|
||||
);
|
||||
"""))
|
||||
session.commit()
|
||||
|
||||
value = self.app.get_setting(session, 'foo')
|
||||
self.assertIsNone(value)
|
||||
|
||||
session.execute(sa.text("insert into setting values ('foo', 'bar');"))
|
||||
value = self.app.get_setting(session, 'foo')
|
||||
self.assertEqual(value, 'bar')
|
Loading…
Add table
Add a link
Reference in a new issue