Ejemplo n.º 1
0
    def test_update_version(self, *mocks):
        """
        Ensures that version in env is updated when the publish command is run
        """
        version = '1.2.3'
        new_version = '0.9.999'
        docker_image = 'foo:bar'

        docker_mock = mocks[0]
        docker_mock.get_config.return_value = (
            f"FOO=1\nBAR=2\nVERSION={version}\nDOCKER_IMAGE={docker_image}"
        )

        utils_mock = mocks[1]
        utils_mock.get_tag_version.return_value = new_version
        utils_mock.render = utils.render

        command = shlex.split('-e dev publish')
        flow = Workflow(argv=command)

        env = Env(flow)

        env.update_workflow_env()

        self.assertEqual(utils_mock.get_tag_version.return_value, env.data['VERSION'])
        self.assertEqual(f'foo:{new_version}', env.data['DOCKER_IMAGE'])
Ejemplo n.º 2
0
    def test_data_not_loaded_when_cache_is_empty_dict(self, *mocks):
        workflow = mock.MagicMock()
        workflow.args.environment = None
        workflow.args.iter.return_value = []

        env = Env(workflow)

        # setup mocks on the env instance
        env.load = mock.Mock()
        env.load.return_value = {}

        # prime the cache with an empty dict to ensure load is not called
        env._data = {}

        env.data

        env.load.assert_not_called()
Ejemplo n.º 3
0
    def test_backend_default(self, *mocks):
        """
        Ensure a local backend is returned
        """
        flow = mock.Mock()
        flow.args.remote = None

        env = Env(flow)

        self.assertEqual(env.backend.__class__.__name__, "LocalBackend")
Ejemplo n.º 4
0
    def test_default_config_name(self, *mocks):
        """
        Ensure the default config is given

        TODO: this should move to test_workflow
        """
        command = shlex.split('-e dev env cat')
        flow = Workflow(argv=command)
        env = Env(flow)

        self.assertEqual(flow.config_name, 'dev-testdirname')
Ejemplo n.º 5
0
    def test_config_name_arg(self, *mocks):
        """
        Ensure the config arg updates the config name

        TODO: this should move to test_workflow
        """
        command = shlex.split('-e dev --config-name=test env cat')
        flow = Workflow(argv=command)
        env = Env(flow)

        self.assertEqual(flow.config_name, 'test')
Ejemplo n.º 6
0
    def test_backend_from_app_config(self, *mocks):
        """
        Ensure a local backend is returned
        """
        backend_name = "rancher"

        flow = mock.Mock()
        flow.args.remote = "dev"

        flow.app_config = {
            "remotes": {"dev": {"environment": {"backend": backend_name}}}
        }

        get_backend_mock = mocks[0]
        get_backend_mock.return_value = "RancherBackend"

        env = Env(flow)
        backend = env.backend

        self.assertEqual(backend, "RancherBackend")

        get_backend_mock.assert_called_with(backend_name, workflow=flow)