2023-05-25 14:55:41 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2015-05-03 19:36:19 -05:00
|
|
|
|
|
|
|
import os
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2024-08-15 14:34:20 -05:00
|
|
|
from pyramid.config import Configurator
|
2015-05-03 19:36:19 -05:00
|
|
|
|
2024-08-15 14:34:20 -05:00
|
|
|
from rattail.exceptions import ConfigurationError
|
2024-08-28 00:35:15 -05:00
|
|
|
from rattail.testing import DataTestCase
|
2024-08-15 14:34:20 -05:00
|
|
|
from tailbone import app as mod
|
2015-05-03 19:36:19 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TestRattailConfig(TestCase):
|
|
|
|
|
|
|
|
config_path = os.path.abspath(
|
|
|
|
os.path.join(os.path.dirname(__file__), 'data', 'tailbone.conf'))
|
|
|
|
|
|
|
|
def test_settings_arg_must_include_config_path_by_default(self):
|
|
|
|
# error raised if path not provided
|
2024-08-15 14:34:20 -05:00
|
|
|
self.assertRaises(ConfigurationError, mod.make_rattail_config, {})
|
2015-05-03 19:36:19 -05:00
|
|
|
# get a config object if path provided
|
2024-08-15 14:34:20 -05:00
|
|
|
result = mod.make_rattail_config({'rattail.config': self.config_path})
|
2023-05-25 14:55:41 -05:00
|
|
|
# nb. cannot test isinstance(RattailConfig) b/c now uses wrapper!
|
|
|
|
self.assertIsNotNone(result)
|
|
|
|
self.assertTrue(hasattr(result, 'get'))
|
2024-08-15 14:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TestMakePyramidConfig(DataTestCase):
|
|
|
|
|
2024-08-28 00:35:15 -05:00
|
|
|
def make_config(self, **kwargs):
|
2024-08-15 14:34:20 -05:00
|
|
|
myconf = self.write_file('web.conf', """
|
|
|
|
[rattail.db]
|
|
|
|
default.url = sqlite://
|
|
|
|
""")
|
|
|
|
|
|
|
|
self.settings = {
|
|
|
|
'rattail.config': myconf,
|
|
|
|
'mako.directories': 'tailbone:templates',
|
|
|
|
}
|
|
|
|
return mod.make_rattail_config(self.settings)
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
model = self.app.model
|
|
|
|
model.Base.metadata.create_all(bind=self.config.appdb_engine)
|
|
|
|
|
|
|
|
# sanity check
|
|
|
|
pyramid_config = mod.make_pyramid_config(self.settings)
|
|
|
|
self.assertIsInstance(pyramid_config, Configurator)
|