diff --git a/CHANGELOG.md b/CHANGELOG.md index 5676a31..9b5b295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,6 @@ All notable changes to WuttJamaican will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## v0.13.1 (2024-08-27) - -### Fix - -- add common `DataTestCase` for use in other packages - ## v0.13.0 (2024-08-26) ### Feat diff --git a/pyproject.toml b/pyproject.toml index fcba871..af34925 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" [project] name = "WuttJamaican" -version = "0.13.1" +version = "0.13.0" description = "Base package for Wutta Framework" readme = "README.md" authors = [{name = "Lance Edgar", email = "lance@edbob.org"}] diff --git a/src/wuttjamaican/testing.py b/src/wuttjamaican/testing.py index cb81ad7..a51f3b5 100644 --- a/src/wuttjamaican/testing.py +++ b/src/wuttjamaican/testing.py @@ -30,27 +30,22 @@ import tempfile import warnings from unittest import TestCase -from wuttjamaican.conf import WuttaConfig - -class FileTestCase(TestCase): +class FileConfigTestCase(TestCase): """ - Base class for test suites which (may) write temporary files, for - sake of testing the config constructor etc. It inherits from - :class:`python:unittest.TestCase`. + Common base class for test suites which write temporary files, for + sake of testing the config constructor etc. - This class creates a temporary folder on setup, and removes it on - teardown. See below for features exposed to work with the folder. + This inherits from :class:`python:unittest.TestCase` and adds the + following features: + + Creates a temporary folder on setup, and removes it on teardown. + Adds the :meth:`write_file()` method to help with creating + temporary files. .. attribute:: tempdir Path to the temporary folder created during setup. - - .. note:: - - If you subclass this and need to override setup/teardown, - please be sure to call the corresponding methods for this - class. """ def setUp(self): @@ -59,6 +54,8 @@ class FileTestCase(TestCase): def setup_files(self): """ + Setup logic specific to the ``FileConfigTestCase``. + This creates the temporary folder. """ self.tempdir = tempfile.mkdtemp() @@ -76,6 +73,8 @@ class FileTestCase(TestCase): def teardown_files(self): """ + Teardown logic specific to the ``FileConfigTestCase``. + This removes the temporary folder. """ shutil.rmtree(self.tempdir) @@ -106,73 +105,3 @@ class FileTestCase(TestCase): Note that this will be created *underneath* :attr:`tempdir`. """ return tempfile.mkdtemp(dir=self.tempdir) - - -# TODO: deprecate / remove this -FileConfigTestCase = FileTestCase - - -class DataTestCase(FileTestCase): - """ - Base class for test suites requiring a full (typical) database. - - It inherits from :class:`FileTestCase` so also has the - file-related methods. - - This uses a SQLite in-memory database and creates all tables for - the app model. The running test has these attributes: - - .. attribute:: config - - Reference to the config object. - - .. attribute:: app - - Reference to the app handler. - - .. attribute:: session - - Open session for the test DB. - - .. note:: - - If you subclass this and need to override setup/teardown, - please be sure to call the corresponding methods for this - class. - - However you do *not* need to call the file-related setup or - teardown methods, as this class handles that automatically. - """ - - def setUp(self): - """ """ - self.setup_db() - - def setup_db(self): - """ - Perform config/app/db setup operations for the test. - """ - self.setup_files() - self.config = self.make_config(defaults={ - 'wutta.db.default.url': 'sqlite://', - }) - self.app = self.config.get_app() - - # init db - model = self.app.model - model.Base.metadata.create_all(bind=self.config.appdb_engine) - self.session = self.app.make_session() - - def tearDown(self): - """ """ - self.teardown_db() - - def teardown_db(self): - """ - Perform config/app/db teardown operations for the test. - """ - self.teardown_files() - - def make_config(self, **kwargs): - """ """ - return WuttaConfig(**kwargs) diff --git a/tests/test_app.py b/tests/test_app.py index 54ab540..cf16d84 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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 FileTestCase +from wuttjamaican.testing import FileConfigTestCase -class TestAppHandler(FileTestCase): +class TestAppHandler(FileConfigTestCase): def setUp(self): self.setup_files() diff --git a/tests/test_conf.py b/tests/test_conf.py index 89af3be..fb9e730 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -10,10 +10,10 @@ import pytest from wuttjamaican import conf from wuttjamaican.exc import ConfigurationError from wuttjamaican.app import AppHandler -from wuttjamaican.testing import FileTestCase +from wuttjamaican.testing import FileConfigTestCase -class TestWuttaConfig(FileTestCase): +class TestWuttaConfig(FileConfigTestCase): def test_contstructor_basic(self): config = conf.WuttaConfig() @@ -505,7 +505,7 @@ class TestGenericDefaultFiles(TestCase): self.assertEqual(len(files), 0) -class TestGetConfigPaths(FileTestCase): +class TestGetConfigPaths(FileConfigTestCase): 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(FileTestCase): +class TestMakeConfig(FileConfigTestCase): # nb. we use appname='wuttatest' in this suite to avoid any # "valid" default config files, env vars etc. which may be present diff --git a/tests/test_people.py b/tests/test_people.py index 0ced117..c2cd2a1 100644 --- a/tests/test_people.py +++ b/tests/test_people.py @@ -1,7 +1,9 @@ # -*- coding: utf-8; -*- +from unittest import TestCase + from wuttjamaican import people as mod -from wuttjamaican.testing import DataTestCase +from wuttjamaican.conf import WuttaConfig try: import sqlalchemy as sa @@ -10,29 +12,41 @@ except ImportError: else: - class TestPeopleHandler(DataTestCase): + class TestPeopleHandler(TestCase): - def make_handler(self): - return mod.PeopleHandler(self.config) + 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 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 = handler.get_person(None) + person = self.handler.get_person(None) self.assertIsNone(person) # person is returned as-is - person = handler.get_person(myperson) + person = self.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 = handler.get_person(myuser) + person = self.handler.get_person(myuser) self.assertIs(person, myperson)