From ae973881affca26f7e6216ca762feff2a4149a48 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 11 Jul 2024 18:19:38 -0500 Subject: [PATCH] fix: add `WuttaConfig.production()` method --- src/wuttjamaican/conf.py | 14 ++++++++++++++ tests/test_conf.py | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/wuttjamaican/conf.py b/src/wuttjamaican/conf.py index 7f270fb..6c3adf5 100644 --- a/src/wuttjamaican/conf.py +++ b/src/wuttjamaican/conf.py @@ -608,6 +608,20 @@ class WuttaConfig: """ return load_object(self.default_engine_maker_spec) + def production(self): + """ + Returns boolean indicating whether the app is running in + production mode. + + This value may be set e.g. in config file: + + .. code-block:: ini + + [wutta] + production = true + """ + return self.get_bool(f'{self.appname}.production', default=False) + class WuttaConfigExtension: """ diff --git a/tests/test_conf.py b/tests/test_conf.py index 791da49..fb9e730 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -442,6 +442,16 @@ configure_logging = true make_engine = config.get_engine_maker() self.assertIs(make_engine, custom_make_engine_from_config) + def test_production(self): + config = conf.WuttaConfig() + + # false if not defined + self.assertFalse(config.production()) + + # but config may specify + config.setdefault('wutta.production', 'true') + self.assertTrue(config.production()) + class CustomAppHandler(AppHandler): pass