3
0
Fork 0

fix: add common DataTestCase for use in other packages

This commit is contained in:
Lance Edgar 2024-08-27 19:10:50 -05:00
parent 7ee8398718
commit 2edeac0d83
4 changed files with 98 additions and 41 deletions

View file

@ -15,10 +15,10 @@ from wuttjamaican import app
from wuttjamaican.progress import ProgressBase
from wuttjamaican.conf import WuttaConfig
from wuttjamaican.util import UNSPECIFIED
from wuttjamaican.testing import FileConfigTestCase
from wuttjamaican.testing import FileTestCase
class TestAppHandler(FileConfigTestCase):
class TestAppHandler(FileTestCase):
def setUp(self):
self.setup_files()

View file

@ -10,10 +10,10 @@ import pytest
from wuttjamaican import conf
from wuttjamaican.exc import ConfigurationError
from wuttjamaican.app import AppHandler
from wuttjamaican.testing import FileConfigTestCase
from wuttjamaican.testing import FileTestCase
class TestWuttaConfig(FileConfigTestCase):
class TestWuttaConfig(FileTestCase):
def test_contstructor_basic(self):
config = conf.WuttaConfig()
@ -505,7 +505,7 @@ class TestGenericDefaultFiles(TestCase):
self.assertEqual(len(files), 0)
class TestGetConfigPaths(FileConfigTestCase):
class TestGetConfigPaths(FileTestCase):
def test_winsvc(self):
myconf = self.write_file('my.conf', """
@ -523,7 +523,7 @@ winsvc.RattailFileMonitor = /path/to/other/file
self.assertEqual(files, [])
class TestMakeConfig(FileConfigTestCase):
class TestMakeConfig(FileTestCase):
# nb. we use appname='wuttatest' in this suite to avoid any
# "valid" default config files, env vars etc. which may be present

View file

@ -1,9 +1,7 @@
# -*- coding: utf-8; -*-
from unittest import TestCase
from wuttjamaican import people as mod
from wuttjamaican.conf import WuttaConfig
from wuttjamaican.testing import DataTestCase
try:
import sqlalchemy as sa
@ -12,41 +10,29 @@ except ImportError:
else:
class TestPeopleHandler(TestCase):
class TestPeopleHandler(DataTestCase):
def setUp(self):
self.config = WuttaConfig()
self.app = self.config.get_app()
self.handler = mod.PeopleHandler(self.config)
self.engine = sa.create_engine('sqlite://')
self.app.model.Base.metadata.create_all(bind=self.engine)
self.session = self.make_session()
def tearDown(self):
self.session.close()
self.app.model.Base.metadata.drop_all(bind=self.engine)
def make_session(self):
return self.app.make_session(bind=self.engine)
def make_handler(self):
return mod.PeopleHandler(self.config)
def test_get_person(self):
model = self.app.model
myperson = model.Person(full_name='Barny Rubble')
self.session.add(myperson)
self.session.commit()
handler = self.make_handler()
# empty obj is ignored
person = self.handler.get_person(None)
person = handler.get_person(None)
self.assertIsNone(person)
# person is returned as-is
person = self.handler.get_person(myperson)
person = handler.get_person(myperson)
self.assertIs(person, myperson)
# find person from user
myuser = model.User(username='barney', person=myperson)
self.session.add(myuser)
self.session.commit()
person = self.handler.get_person(myuser)
person = handler.get_person(myuser)
self.assertIs(person, myperson)