Exemple #1
0
 def test_blank_env_values(self):
     conf = """a: ${key1}"""
     e = parse_environment("""key1:""")
     c = parse_config(conf, e)
     self.assertEqual(c["a"], None)
     e = parse_environment("""key1: !!str""")
     c = parse_config(conf, e)
     self.assertEqual(c["a"], "")
Exemple #2
0
 def test_blank_env_values(self):
     conf = """a: ${key1}"""
     e = parse_environment("""key1:""")
     c = parse_config(conf, e)
     self.assertEqual(c['a'], None)
     e = parse_environment("""key1: !!str""")
     c = parse_config(conf, e)
     self.assertEqual(c['a'], "")
Exemple #3
0
    def test_generator(self):
        # Search for tests in given paths
        configs = []
        for d in self.yaml_dirs:
            configs.extend(
                glob('%s/%s/%s' % (self.classdir, d, self.yaml_filename)))

        class ConfigTest(self.base_class):
            def __init__(self, config, stack, filepath):
                self.config = config
                self.stack = stack
                self.description = "%s (%s)" % (stack.name, filepath)

            def __call__(self):
                # Use the context property of the baseclass, if present.
                # If not, default to a basic context.
                try:
                    ctx = self.context
                except AttributeError:
                    ctx = Context(config=self.config,
                                  environment={'environment': 'test'})

                configvars = self.stack.variables or {}
                variables = [Variable(k, v) for k, v in configvars.iteritems()]

                blueprint_class = load_object_from_string(
                    self.stack.class_path)
                blueprint = blueprint_class(self.stack.name, ctx)
                blueprint.resolve_variables(variables or [])
                blueprint.setup_parameters()
                blueprint.create_template()
                self.assertRenderedBlueprint(blueprint)

            def assertEquals(self, a, b, msg):  # noqa: N802
                assert a == b, msg

        for f in configs:
            with open(f) as test:
                config = parse_config(test.read())
                config.validate()

                for stack in config.stacks:
                    # Nosetests supports "test generators", which allows us to
                    # yield a callable object which will be wrapped as a test
                    # case.
                    #
                    # http://nose.readthedocs.io/en/latest/writing_tests.html#test-generators
                    yield ConfigTest(config, stack, filepath=f)
Exemple #4
0
 def test_valid_env_substitution(self):
     c = parse_config("a: $a", {"a": "A"})
     self.assertEqual(c["a"], "A")
Exemple #5
0
 def test_no_variable_config(self):
     c = parse_config("a: A", {})
     self.assertEqual(c["a"], "A")
Exemple #6
0
 def test_missing_env(self):
     env = {"a": "A"}
     with self.assertRaises(exceptions.MissingEnvironment) as expected:
         parse_config(config, env)
     self.assertEqual(expected.exception.key, "b")
Exemple #7
0
 def test_vault_constructor(self, patched):
     patched.check_output.return_value = "secret\n"
     c = parse_config("a: $a", {"a": "!vault secret/hello@value"})
     self.assertEqual(c["a"], "secret")
Exemple #8
0
 def test_custom_constructors(self, patched):
     patched.return_value = "stub"
     c = parse_config("a: $a", {"a": "!vault some_encrypted_value"})
     self.assertEqual(c["a"], "stub")
Exemple #9
0
 def test_valid_env_substitution(self):
     c = parse_config("a: $a", {"a": "A"})
     self.assertEqual(c["a"], "A")
Exemple #10
0
 def test_no_variable_config(self):
     c = parse_config("a: A", {})
     self.assertEqual(c["a"], "A")
Exemple #11
0
 def test_missing_env(self):
     env = {"a": "A"}
     with self.assertRaises(exceptions.MissingEnvironment) as expected:
         parse_config(config, env)
     self.assertEqual(expected.exception.key, "b")
Exemple #12
0
 def test_vault_constructor(self, patched):
     patched.check_output.return_value = 'secret\n'
     c = parse_config('a: $a', {'a': '!vault secret/hello@value'})
     self.assertEqual(c['a'], 'secret')
Exemple #13
0
 def test_vault_constructor(self, patched):
     patched.check_output.return_value = "secret\n"
     c = parse_config("a: $a", {"a": "!vault secret/hello@value"})
     self.assertEqual(c["a"], "secret")
Exemple #14
0
 def test_custom_constructors(self, patched):
     patched.return_value = "stub"
     c = parse_config("a: $a", {"a": "!vault some_encrypted_value"})
     self.assertEqual(c["a"], "stub")
Exemple #15
0
 def test_missing_env(self):
     env = {'a': 'A'}
     try:
         parse_config(config, env)
     except MissingEnvironment as e:
         self.assertEqual(e.key, 'b')
Exemple #16
0
 def test_vault_constructor(self, patched):
     patched.check_output.return_value = 'secret\n'
     c = parse_config('a: $a', {'a': '!vault secret/hello@value'})
     self.assertEqual(c['a'], 'secret')