Пример #1
0
    def test_get_none_section_to_return_whole_category_config(self):
        self.mock_conf([GENE_CATEGORY], MOCK_DATA)

        expected = {SECTION_NAME: {GENE_KEY_NAME_A: GENE_KEY_VALUE_A}}
        actual = EnvConfig.GENE(None, None)

        self.assertEqual(
            actual,
            expected,
            "expected get of existing value to return the value",
        )
Пример #2
0
    def test_existing_key_to_return_actual_value(self):
        self.mock_conf([GLOBAL_CATEGORY, GENE_CATEGORY], MOCK_DATA)

        expected = GENE_KEY_VALUE_A
        actual = EnvConfig.GENE(SECTION_NAME, GENE_KEY_NAME_A)

        self.assertEqual(
            actual,
            expected,
            "expected get of existing value to return the value",
        )
Пример #3
0
    def test_none_existing_key_returns_default(self):
        self.mock_conf([GLOBAL_CATEGORY], MOCK_DATA)

        expected = DEFAULT_VALUE
        actual = EnvConfig.GLOBAL(SECTION_NAME,
                                  NON_EXISTING_KEY_NAME,
                                  default_value=expected)

        self.assertEqual(
            actual,
            expected,
            "expected get of non existing key to return a default value",
        )
Пример #4
0
    def test_none_existing_category_throws_exception(self):
        self.mock_conf([GLOBAL_CATEGORY], MOCK_DATA)

        expected = None
        actual = None
        try:
            EnvConfig.DUMMY(SECTION_NAME,
                            NON_EXISTING_KEY_NAME,
                            default_value=expected)
        except Exception as ex:
            actual = ex

        self.assertNotEqual(
            actual,
            None,
            "expected get of non existing category to raise an exception",
        )
# OS / ENVIRONMENT VARS                                                     #
#############################################################################

v = OSVars.get("COMPANY")
Logger.info(f"Company name provided by os env is: {v} and its type is: {type(v)}")


#############################################################################
# ENV CONFIGURATION (using github)                                          #
#############################################################################

# visit https://github.com/Twistbioscience/configuration/tree/kitchen-sink-demo-do-not-delete
# in order to examine concrete values involved in this example.

# attempting to read the "all" section from the system.json conf file in the configuration repo
v = EnvConfig.SYSTEM("all", None)
Logger.info(f"got {v} from system conf [all] section...\n")

# attempting to read the all.some_demo_key value from the system.json conf file in the configuration repo
v = EnvConfig.SYSTEM("all", "some_demo_key")
Logger.info(f"got {v} from system conf [all.some_demo_key]...\n")

v = EnvConfig.GLOBAL("test", "float", 333.333)
Logger.info(f"got {v} from global conf [test.float]...\n")

# attempting to read a non existing config from the global.json conf file in the configuration repo
v = EnvConfig.get(
    "global",
    "non_existing_section",
    "non_existing_key",
    ["this is a default value as a single list element"],
Пример #6
0
 def setUp(self):
     self.testee = EnvConfig.instance()
     self.testee.set_context_handler(EnvConfigContext(ENV_NAME))
     self.conf_loader = GithubMockEnvConfig()
     self.conf_loader.set_env("dummy", [])