예제 #1
0
    def test_all_environment_is_not_case_sensitive(self):
        config = Config(
            '{"Prod": {"Shared": "production!"}, "All": {"Shared": "none", "AllOnly": "works"}}'
        )
        config = config.for_environment("Prod")
        self.assertEqual(config.all_only, "works")

        config = Config(
            '{"Prod": {"Shared": "production!"}, "all": {"Shared": "none", "AllOnly": "works"}}'
        )
        config = config.for_environment("Prod")
        self.assertEqual(config.all_only, "works")
예제 #2
0
 def test_supports_deep_merge(self):
     config = Config(
         '{"Prod": {"Database": {"Server": "prod-sql"}}, "All": {"Database": {"MigrationsPath": "path/to/migrations"}}}'
     )
     config = config.for_environment("Prod")
     self.assertEqual(config.database.server, "prod-sql")
     self.assertEqual(config.database.migrations_path, "path/to/migrations")
예제 #3
0
    def test_enumerated_json_object_values_are_still_shiny(self):
        json = """
        {
          "connections": {
            "firstConnection": {
              "user": "******",
              "password":"******"
            },
            "secondConnection": {
              "user": "******",
              "password":"******"
            }
          }
        }"""

        config = Config(json)
        for k, v in config.connections:
            self.assertEqual(v.password, "secret")
예제 #4
0
 def test_enumerating_json_object(self):
     config = Config(self._json_config)
     itemCount = 0
     for item in config:
         itemCount += 1
     self.assertEqual(itemCount, 1)
예제 #5
0
 def test_enumerating_json_array(self):
     config = Config(self._json_config_with_array)
     itemCount = 0
     for item in config.the_array:
         itemCount += 1
     self.assertEqual(itemCount, 2)
예제 #6
0
 def test_indexing_json_array(self):
     config = Config(self._json_config_with_array)
     self.assertEqual(config.the_array[0].the_key, "Value1")
     self.assertEqual(config.the_array[1].the_key, "Value2")
예제 #7
0
 def test_environment_specific_config_overrides_all(self):
     config = Config(
         '{"Prod": {"Shared": "production!"}, "All": {"Shared": "none"}}')
     config = config.for_environment("Prod")
     self.assertEqual(config.shared, "production!")
예제 #8
0
 def test_modifying_raw_config(self):
     config = Config(self._json_config)
     config.raw_config["theEnvironment"]["theKey"] = "NotTheValue"
     self.assertEqual(config.the_environment.the_key, "NotTheValue")
예제 #9
0
 def test_to_string_returns_json(self):
     json = self._json_config
     config = Config(json)
     self.assertEqual(str(config), json)
예제 #10
0
 def test_environment_specific_config_is_included(self):
     config = Config(self._json_config)
     environment_config = config.for_environment("theEnvironment")
     self.assertEqual(environment_config.the_key, "TheValue")
예제 #11
0
 def test_environment_property_is_included(self):
     config = Config(self._json_config)
     environment_config = config.for_environment("theEnvironment")
     self.assertEqual(environment_config.environment, "theEnvironment")
예제 #12
0
 def test_readable_using_snake_case_property(self):
     config = Config(self._json_config)
     self.assertEqual(config.the_environment.the_key, "TheValue")
예제 #13
0
 def test_raises_if_duplicate_normalized_keys_exist(self):
     json = '{ "someKey": "value", "some_key": "value" }'
     with self.assertRaisesRegexp(KeyError, "duplicate.+someKey.+some_key"):
         Config(json)
예제 #14
0
 def test_raises_if_key_not_found(self):
     config = Config(self._json_config)
     with self.assertRaisesRegexp(KeyError, "does_not_exist"):
         config = config.does_not_exist
예제 #15
0
 def test_create_from_string(self):
     config = Config(self._json_config)
     self.assertEqual(config.the_environment.the_key, "TheValue")
예제 #16
0
 def test_has_key(self):
     config = Config(self._json_config)
     self.assertTrue("the_environment" in config)
     self.assertTrue("does_not_exist" not in config)