fix: add docs, tests; tweak some handler method signatures

This commit is contained in:
Lance Edgar 2025-01-12 01:10:52 -06:00
parent e4a4e85cf6
commit d11e186df9
16 changed files with 345 additions and 15 deletions

16
tests/test_app.py Normal file
View file

@ -0,0 +1,16 @@
# -*- coding: utf-8; -*-
from wuttjamaican.testing import ConfigTestCase
from wutta_corepos import app as mod
from wutta_corepos.handler import CoreposHandler
class TestWuttaCoreposAppProvider(ConfigTestCase):
def make_provider(self):
return mod.WuttaCoreposAppProvider(self.config)
def test_get_report_handler(self):
handler = self.app.get_corepos_handler()
self.assertIsInstance(handler, CoreposHandler)

29
tests/test_conf.py Normal file
View file

@ -0,0 +1,29 @@
# -*- coding: utf-8; -*-
from unittest import TestCase
from wuttjamaican.conf import WuttaConfig
from wutta_corepos import conf as mod
class TestWuttaCoreposConfigExtension(TestCase):
def test_configure(self):
config = WuttaConfig()
# no engines by default
self.assertFalse(hasattr(config, 'core_office_op_engine'))
self.assertFalse(hasattr(config, 'core_office_trans_engine'))
self.assertFalse(hasattr(config, 'core_office_arch_engine'))
ext = mod.WuttaCoreposConfigExtension()
ext.configure(config)
self.assertIsNone(config.core_office_op_engine)
self.assertIsNone(config.core_office_trans_engine)
self.assertIsNone(config.core_office_arch_engine)
# but config can change that
config.setdefault('corepos.db.office_op.default.url', 'sqlite://')
ext.configure(config)
self.assertIsNotNone(config.core_office_op_engine)
self.assertEqual(str(config.core_office_op_engine.url), 'sqlite://')

66
tests/test_handler.py Normal file
View file

@ -0,0 +1,66 @@
# -*- coding: utf-8; -*-
from wuttjamaican.testing import ConfigTestCase
from wuttjamaican.exc import ConfigurationError
from wutta_corepos import handler as mod
class TestCoreposHandler(ConfigTestCase):
def make_handler(self):
return mod.CoreposHandler(self.config)
def test_get_office_url(self):
handler = self.make_handler()
# null by default
self.assertIsNone(handler.get_office_url())
# error if required
self.assertRaises(ConfigurationError, handler.get_office_url, require=True)
# config can specify (traliing slash is stripped)
self.config.setdefault('corepos.office.url', 'http://localhost/fannie/')
self.assertEqual(handler.get_office_url(), 'http://localhost/fannie')
self.assertEqual(handler.get_office_url(require=True), 'http://localhost/fannie')
def test_get_office_department_url(self):
handler = self.make_handler()
# null
self.assertIsNone(handler.get_office_department_url(7))
# typical
self.config.setdefault('corepos.office.url', 'http://localhost/fannie/')
self.assertEqual(handler.get_office_department_url(7), 'http://localhost/fannie/item/departments/DepartmentEditor.php?did=7')
def test_get_office_likecode_url(self):
handler = self.make_handler()
# null
self.assertIsNone(handler.get_office_likecode_url(7))
# typical
self.config.setdefault('corepos.office.url', 'http://localhost/fannie/')
self.assertEqual(handler.get_office_likecode_url(7), 'http://localhost/fannie/item/likecodes/LikeCodeEditor.php?start=7')
def test_get_office_product_url(self):
handler = self.make_handler()
# null
self.assertIsNone(handler.get_office_product_url('07430500132'))
# typical
self.config.setdefault('corepos.office.url', 'http://localhost/fannie/')
self.assertEqual(handler.get_office_product_url('07430500132'), 'http://localhost/fannie/item/ItemEditorPage.php?searchupc=07430500132')
def test_get_office_vendor_url(self):
handler = self.make_handler()
# null
self.assertIsNone(handler.get_office_vendor_url(7))
# typical
self.config.setdefault('corepos.office.url', 'http://localhost/fannie/')
self.assertEqual(handler.get_office_vendor_url(7), 'http://localhost/fannie/item/vendors/VendorIndexPage.php?vid=7')