def test_test4(self): """ Generation of files: creationg """ if hasattr(self, "assertLogs"): django_yamlconf.add_attributes( self.settings, { 'USE_A': True, 'A': 'a', 'YAMLCONF_SYSFILES_DIR': os.path.join(self.sysfiles_root, "test4"), }, "**TESTING**") with self.assertLogs('', level='DEBUG') as logs: rootdir = os.path.join(TestYCSysfiles.BASE_DIR, "root") django_yamlconf.sysfiles( create=True, noop=False, settings=self.settings, rootdir=rootdir, render=self.render, ) self.assertRegex( " ".join(logs.output), 'Updating the system control file ' + '".*root.etc.xmpl.txt"', )
def test_create_nested_dict(self): """ Verify nested dict's are created """ settings = MockSettings() settings.X = {} django_yamlconf.add_attributes(settings, {'X.Y.Z': 20}, "**TESTING**") self.assertEqual(settings.X["Y"]["Z"], 20)
def test_nested_dict(self): """ Verify setting a value within nested dicts """ settings = MockSettings() settings.X = {"Y": {"Z": 10}} django_yamlconf.add_attributes(settings, {'X.Y.Z': 20}, "**TESTING**") self.assertEqual(settings.X["Y"]["Z"], 20)
def add_cmd_attrs(defines, methods): """ Add attributes defined on the command line, via name=value of an application method, to the set of attributes available in templates. """ django_yamlconf.add_attributes(settings, get_methods(methods), "**GENERATED**") django_yamlconf.add_attributes(settings, get_defines(defines), "**CMDLINE**")
def test_set_non_key(self): """ Check error when setting non dictionaries """ if hasattr(self, "assertLogs"): settings = MockSettings() settings.X = "x" django_yamlconf.load(project="nosuchfile", settings=settings) with self.assertLogs('', level='ERROR') as logs: django_yamlconf.add_attributes(settings, {'X.not_there': 'a'}, "**TESTING**") self.assertIn('Not a dictionary', logs.output[0])
def test_missing_key(self): """ Test error message for invalid attr name """ if hasattr(self, "assertLogs"): with self.assertLogs('', level='ERROR') as logs: django_yamlconf.add_attributes( self.settings, {"X": "Reference to undefined {NO_SUCH_ATTR}"}, "**TESTING**", ) self.assertIn('Reference to undefined', "\n".join(logs.output))
def test_invalid_format(self): """ Test error message for invalid attr reference """ if hasattr(self, "assertLogs"): with self.assertLogs('', level='ERROR') as logs: django_yamlconf.add_attributes( self.settings, {"X": "Reference to invalid {ATTR"}, "**TESTING**", ) self.assertIn('Invalid format', "\n".join(logs.output))
def setUp(self): """ Initialize the mock settings object """ self.settings = MockSettings() self.settings.X = "x" django_yamlconf.load(project="testing", settings=self.settings) django_yamlconf.add_attributes(self.settings, { 'A': 'a', 'B': '{A}b', 'ETC_DIR': '{TOP_DIR}/etc' }, "**TESTING**")
def test_test6(self): """ Missing sys files directory """ if hasattr(self, "assertLogs"): django_yamlconf.add_attributes(self.settings, { 'A': 'a', }, "**TESTING**") with self.assertLogs('', level='DEBUG') as logs: django_yamlconf.sysfiles( create=False, noop=True, settings=self.settings, render=self.render, ) self.assertIn('No YAMLCONF_SYSFILES_DIR settings defined', "\n".join(logs.output))
def test_test1(self): """ Simple reference to an attribute """ if hasattr(self, "assertLogs"): django_yamlconf.add_attributes( self.settings, { 'A': 'a', 'YAMLCONF_SYSFILES_DIR': os.path.join(self.sysfiles_root, "test1"), }, "**TESTING**") with self.assertLogs('', level='DEBUG') as logs: django_yamlconf.sysfiles( create=False, noop=True, settings=self.settings, render=self.render, ) self.assertIn('Value of A is a.', "\n".join(logs.output))
def test_test3(self): """ Generation of files: non-writeable """ if hasattr(self, "assertLogs"): django_yamlconf.add_attributes( self.settings, { 'A': True, 'YAMLCONF_SYSFILES_DIR': os.path.join(self.sysfiles_root, "test3"), }, "**TESTING**") with self.assertLogs('', level='DEBUG') as logs: django_yamlconf.sysfiles( create=True, noop=False, settings=self.settings, render=self.render, ) self.assertIn( 'Skipping non-writeable or missing system file: ' + '"/myapp/tmpl.txt"', "\n".join(logs.output))
def test_test2(self): """ Reference to a dictionary based attribute """ if hasattr(self, "assertLogs"): self.settings.DATABASES = {} django_yamlconf.add_attributes( self.settings, { 'DATABASES.default.PASSWORD': '******', 'YAMLCONF_SYSFILES_DIR': os.path.join(self.sysfiles_root, "test2"), }, "**TESTING**") with self.assertLogs('', level='DEBUG') as logs: django_yamlconf.sysfiles( create=False, noop=True, settings=self.settings, render=self.render, ) self.assertIn('DB password is is Welcome.', "\n".join(logs.output))