def test_env_variable_with_deep_vars_module_import_with_shortcuts(self): """testing if the module path has multiple shortcuts like ~ and other env variables """ splits = os.path.split(self.temp_config_folder) var1 = splits[0] var2 = os.path.sep.join(splits[1:]) var3 = os.path.join("$var1", "$var2") os.environ["var1"] = var1 os.environ["var2"] = var2 os.environ["var3"] = var3 os.environ["STALKER_PATH"] = "$var3" test_value = "sqlite:///.test_value.db" config_file = open(self.config_full_path, "w") config_file.writelines(["#-*- coding: utf-8 -*-\n", 'database_url = "' + test_value + '"\n']) config_file.close() # now import the config.py and see if it updates the # database_file_name variable from stalker import config conf = config.Config() self.assertEqual(test_value, conf.database_url)
def test_non_existing_path_in_environment_variable(self): """testing if the non existing path situation will be handled gracefully by warning the user """ os.environ["STALKER_PATH"] = "/tmp/non_existing_path" from stalker import config config.Config()
def test_syntax_error_in_settings_file(self): """testing if a RuntimeError will be raised when there are syntax errors in the config.py file """ # now create a config.py file and fill it with the desired values # like database_file_name = "test_value.db" # but do a syntax error on purpose, like forgetting the last quote sign test_value = ".test_value.db" config_file = open(self.config_full_path, "w") config_file.writelines([ "#-*- coding: utf-8 -*-\n", 'database_file_name = "' + test_value + '\n' ]) config_file.close() # now import the config.py and see if it updates the # database_file_name variable from stalker import config with self.assertRaises(RuntimeError) as cm: config.Config() self.assertEqual( str(cm.exception), 'There is a syntax error in your configuration file: EOL while ' 'scanning string literal (<string>, line 2)')
def test___delitem__is_working_properly(self): """testing if config.Config.__delitem__() method is working properly """ from stalker import config c = config.Config() assert c['admin_name'] is not None del c['admin_name'] assert 'admin_name' not in c
def test___delitem__is_working_properly(self): """testing if config.Config.__delitem__() method is working properly """ from stalker import config c = config.Config() self.assertIsNotNone(c['admin_name']) del c['admin_name'] self.assertTrue('admin_name' not in c)
def test___setitem__is_working_properly(self): """testing if config.Config.__setitem__() method is working properly """ from stalker import config c = config.Config() test_value = 'administrator' assert c['admin_name'] != test_value c['admin_name'] = test_value assert c['admin_name'] == test_value
def test___setitem__is_working_properly(self): """testing if config.Config.__setitem__() method is working properly """ from stalker import config c = config.Config() test_value = 'administrator' self.assertNotEqual(c['admin_name'], test_value) c['admin_name'] = test_value self.assertEqual(c['admin_name'], test_value)
def test_config_variable_does_create_new_variables_with_user_config(self): """testing if the config will be updated by the user config by adding new variables """ # now create a config.py file and fill it with the desired values # like database_file_name = "test_value.db" test_value = ".test_value.db" config_file = open(self.config_full_path, "w") config_file.writelines(["#-*- coding: utf-8 -*-\n", 'test_value = "' + test_value + '"\n']) config_file.close() # now import the config.py and see if it updates the # database_file_name variable from stalker import config conf = config.Config() assert conf.test_value == test_value
def test_config_variable_updates_with_user_config(self): """testing if the database_file_name will be updated by the user config """ # now create a config.py file and fill it with the desired values # like database_file_name = "test_value.db" test_value = ".test_value.db" config_file = open(self.config_full_path, "w") config_file.writelines([ "#-*- coding: utf-8 -*-\n", 'database_engine_settings = "%s"\n' % test_value ]) config_file.close() # now import the config.py and see if it updates the # database_file_name variable from stalker import config conf = config.Config() self.assertEqual(test_value, conf.database_engine_settings)
""" import sys __version__ = '0.2.21' __string_types__ = [] if sys.version_info[0] >= 3: # Python 3 __string_types__ = tuple([str]) else: # Python 2 __string_types__ = tuple([str, unicode]) # before anything about stalker create the defaults # use this instance from stalker import config defaults = config.Config() from stalker.models.auth import (Group, Permission, User, LocalSession, Role, AuthenticationLog) from stalker.models.asset import Asset from stalker.models.budget import (Budget, BudgetEntry, Good, PriceList, Invoice, Payment) from stalker.models.client import Client, ClientUser from stalker.models.department import Department, DepartmentUser from stalker.models.entity import SimpleEntity, Entity, EntityGroup from stalker.models.format import ImageFormat from stalker.models.link import Link from stalker.models.message import Message from stalker.models.mixins import (ACLMixin, AmountMixin, CodeMixin, DAGMixin, DateRangeMixin, ProjectMixin, ReferenceMixin, ScheduleMixin, StatusMixin,
def test___contains___is_working_properly(self): """testing if config.Config.__contains__() method is working properly """ from stalker import config c = config.Config() assert 'admin_name' in c
def test___getitem___is_working_properly(self): """testing if config.Config.__getitem__() method is working properly """ from stalker import config c = config.Config() assert c['admin_name'] == 'admin'
def test___getattr___is_working_properly(self): """testing if config.Config.__getattr__() method is working properly """ from stalker import config c = config.Config() self.assertEqual(c.admin_name, 'admin')