def test_render_for_local_app_with_artifacts_for_provider(
            self, mock_render_artifact, mock_get_artifact_paths_for_provider,
            mock_get_context):
        """Test rendering artifacts for a local Nulecule component"""
        provider_key = 'some-provider'
        dryrun = False
        expected_rendered_artifacts = [
            'some/path/.artifact1', 'some/path/.artifact2']
        context = {'a': 'b'}
        mock_get_artifact_paths_for_provider.return_value = [
            'some/path/artifact1', 'some/path/artifact2']
        mock_render_artifact.side_effect = lambda path, context, provider: path.replace('artifact', '.artifact')
        mock_get_context.return_value = context

        nc = NuleculeComponent(name='some-app', basepath='some/path')
        nc.config = {'general': {'key1': 'val1'}, 'some-provider': {'a': 'b'}}
        nc.artifacts = {
            'some-provider': ['artifact1', 'artifact2'],
            'x': ['foo']
        }
        nc.render(provider_key, dryrun)

        mock_get_artifact_paths_for_provider.assert_called_once_with(
            provider_key)
        mock_render_artifact.assert_any_call('some/path/artifact1', context,
                                             'some-provider')
        mock_render_artifact.assert_any_call('some/path/artifact2', context,
                                             'some-provider')
        mock_get_artifact_paths_for_provider.assert_called_once_with(
            provider_key)
        self.assertEqual(nc.rendered_artifacts[provider_key],
                         expected_rendered_artifacts)
Esempio n. 2
0
    def test_load_config_external_app(self):
        """Test load config for external app"""
        params = [{
            'name': 'key1',
            'description': 'key1'
        }, {
            'name': 'key2',
            'description': 'key2'
        }]
        initial_config = {
            'general': {
                'a': 'b',
                'key2': 'val2'
            },
            'some-app': {
                'key1': 'val1'
            }
        }
        config = Config(answers=initial_config)
        mock_nulecule = mock.Mock(name='nulecule',
                                  spec=Nulecule('some-id', '0.0.2', config, [],
                                                'some/path'))

        nc = NuleculeComponent('some-app', 'some/path', params=params)
        nc._app = mock_nulecule
        nc.config = config
        nc.load_config()

        mock_nulecule.load_config.assert_called_once_with(config=config,
                                                          ask=False,
                                                          skip_asking=False)
    def test_render_for_local_app_with_artifacts_for_provider(
            self, mock_render_artifact, mock_get_artifact_paths_for_provider,
            mock_get_context):
        """Test rendering artifacts for a local Nulecule component"""
        provider_key = 'some-provider'
        dryrun = False
        expected_rendered_artifacts = [
            'some/path/.artifact1', 'some/path/.artifact2'
        ]
        context = {'a': 'b'}
        mock_get_artifact_paths_for_provider.return_value = [
            'some/path/artifact1', 'some/path/artifact2'
        ]
        mock_render_artifact.side_effect = lambda path, context, provider: path.replace(
            'artifact', '.artifact')
        mock_get_context.return_value = context

        nc = NuleculeComponent(name='some-app', basepath='some/path')
        nc.config = {'general': {'key1': 'val1'}, 'some-provider': {'a': 'b'}}
        nc.artifacts = {
            'some-provider': ['artifact1', 'artifact2'],
            'x': ['foo']
        }
        nc.render(provider_key, dryrun)

        mock_get_artifact_paths_for_provider.assert_called_once_with(
            provider_key)
        mock_render_artifact.assert_any_call('some/path/artifact1', context,
                                             'some-provider')
        mock_render_artifact.assert_any_call('some/path/artifact2', context,
                                             'some-provider')
        mock_get_artifact_paths_for_provider.assert_called_once_with(
            provider_key)
        self.assertEqual(nc.rendered_artifacts[provider_key],
                         expected_rendered_artifacts)
    def test_render_for_local_app_with_missing_artifacts_from_nulecule(self):
        """
        Test rendering a Nulecule component with no artifacts provided in the
        Nulecule file.
        """
        nc = NuleculeComponent(name='some-app', basepath='some/path')
        nc.config = {}

        with self.assertRaises(NuleculeException):
            nc.render()
Esempio n. 5
0
    def test_render_for_local_app_with_missing_artifacts_from_nulecule(self):
        """
        Test rendering a Nulecule component with no artifacts provided in the
        Nulecule file.
        """
        nc = NuleculeComponent(name='some-app', basepath='some/path')
        nc.config = {}

        with self.assertRaises(NuleculeException):
            nc.render()
    def test_render_for_local_app_with_missing_artifacts_for_provider(self):
        """
        Test rendering a Nulecule component with missing artifacts for a
        provider.
        """
        provider_key = 'some-provider'
        dryrun = False

        nc = NuleculeComponent(name='some-app', basepath='some/path')
        nc.config = {}
        nc.artifacts = {'x': ['some-artifact']}

        self.assertRaises(NuleculeException, nc.render, provider_key, dryrun)
Esempio n. 7
0
    def test_render_for_local_app_with_missing_artifacts_for_provider(self):
        """
        Test rendering a Nulecule component with missing artifacts for a
        provider.
        """
        provider_key = 'some-provider'
        dryrun = False

        nc = NuleculeComponent(name='some-app', basepath='some/path')
        nc.config = Config()
        nc.artifacts = {'x': ['some-artifact']}

        self.assertRaises(NuleculeException, nc.render, provider_key, dryrun)
    def test_load_config_external_app(self):
        """Test load config for external app"""
        params = [
            {'name': 'key1', 'description': 'key1'},
            {'name': 'key2', 'description': 'key2'}
        ]
        initial_config = {
            'general': {'a': 'b', 'key2': 'val2'},
            'some-app': {'key1': 'val1'}
        }
        config = Config(answers=initial_config)
        mock_nulecule = mock.Mock(
            name='nulecule',
            spec=Nulecule('some-id', '0.0.2', config, [], 'some/path')
        )

        nc = NuleculeComponent('some-app', 'some/path', params=params)
        nc._app = mock_nulecule
        nc.config = config
        nc.load_config()

        mock_nulecule.load_config.assert_called_once_with(
            config=config, ask=False, skip_asking=False)