Exemple #1
0
    def test_kvp_param_comment(self):

        kvps = "ami:ami-324:ami for ec2 hosts,vpc-id:vpc-325552:id of nonprod vpc"

        params = Params({})
        params.load_kvps(kvps)

        self.assertTrue(params.get("ami") == 'ami-324')
        self.assertTrue(params.get("vpc-id") == 'vpc-325552')
Exemple #2
0
    def test_setup(self):

        test_descriptor = {
            "tests": [{
                "name": "my-custom",
                "description": ["custom test driver will be ignored"],
                "setup": "yac/tests/test/lib/setup_cleanup.py",
                "target": "https://www.google.com/",
                "driver": "yac/tests/lib/custom_test_pass.py"
            }]
        }

        params = Params({})

        tests = IntegrationTests(test_descriptor)

        err = tests.run(params,
                        context="",
                        test_names=["my-custom"],
                        setup_only=True)

        # test that the setup was called and set a param
        my_setup_param = params.get('setup-param')

        self.assertTrue(my_setup_param == 'setup-value')
        self.assertTrue(not err)
Exemple #3
0
    def test_kvp_params(self):

        kvps = "joe:blue,jan:green"

        params = Params({})
        params.load_kvps(kvps)

        self.assertTrue(params.get("jan") == 'green')
        self.assertTrue(params.get("joe") == 'blue')
Exemple #4
0
    def test_secrets(self):

        my_secrets = {
            "param-key-1": {
                "comment": "branch 1, child 1, entry 1",
                "source": "keepass",
                "lookup": {
                    "path": "Branch 1/B1-C1/B1-C1-E1",
                    "field": "password"
                }
            },
            "param-key-2": {
                "comment": "branch 2, child 2, entry 1",
                "source": "keepass",
                "lookup": {
                    "path": "Branch 2/B2-C2/B2-C2-E1",
                    "field": "password"
                }
            }
        }

        secrets_vaults = [{
            "type": "keepass",
            "name": "keepass",
            "configs": {
                "vault-path": "yac/tests/vault/vectors/test_vault.kdbx",
                "vault-pwd-path": TestCase.pwd_path
            }
        }]

        params = Params({})

        vaults = SecretVaults(secrets_vaults)

        secrets = Secrets(my_secrets)

        secrets.load(params, vaults)

        print(secrets.get_errors())

        both_loaded = (params.get("param-key-1") == 'b1-c1-e1-secret'
                       and params.get("param-key-2") == 'b2-c2-e1-secret')

        self.assertTrue(both_loaded)
Exemple #5
0
    def test_params(self):

        test_parameters = {
            "ssl-cert" : {
              "value": "godzilla",
              "comment": ""
            },
            "s3_path": {
              "value": "/sets/jira/dev",
              "comment": ""
            }
        }

        # run test
        params = Params(test_parameters)

        self.assertTrue(params.get("ssl-cert") == "godzilla")
Exemple #6
0
    def test_map(self):

        test_parameters = {
            "user-name": {
                "value": "tom-johnson"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-johnson": "phinney",
                    "henry-grantham": "queen-ann-hill"
                }
            }
        }

        params = Params(test_parameters)

        self.assertTrue(params.get("neighborhood-map") == "phinney")
Exemple #7
0
    def conditions_met(self, params):

        conditions_met = True

        # currently the only conditional supported is based on key-value pair (aka 'kvps')
        # conditions are met if the state of the conditional params matches the current params
        if self.conditions and 'kvps' in self.conditions:

            # load the kvps into params
            condition_params = Params({})
            condition_params.load_kvps(self.conditions['kvps'])

            for condition_param_key in list(condition_params.keys()):
                if params.get(condition_param_key) != condition_params.get(condition_param_key):
                    conditions_met = False
                    break

        return conditions_met
Exemple #8
0
    def test_map_miss(self):

        # user-name doesn't match any of the map keys

        test_parameters = {
            "user-name": {
                "value": "tom-johnsons"
            },
            "neighborhood-map": {
                "lookup": "user-name",
                "value": {
                    "tom-johnson": "phinney",
                    "henry-grantham": "queen-ann-hill"
                }
            }
        }

        params = Params(test_parameters)

        value = params.get("neighborhood-map", "m.i.a")

        self.assertTrue(value == "m.i.a")
Exemple #9
0
    def test_params_load(self):

        # load params
        params = Params({})

        serialized_inputs = [{
            "key": "env",
            "title": "Environment",
            "type": "string",
            "help": "The environment to build stack for",
            "required": True,
            "options": ["dev"]
        }]

        inputs = Inputs(serialized_inputs)

        # inject the correct response to inputs prompt into stdin
        sys.stdin = io.StringIO('dev')

        # load inputs into params
        inputs.load(params)

        self.assertTrue(params.get('env') == 'dev')