diff --git a/tests/units/cli/test_default_provider.py b/tests/units/cli/test_default_provider.py index fa1e4272..c5e56ec7 100644 --- a/tests/units/cli/test_default_provider.py +++ b/tests/units/cli/test_default_provider.py @@ -70,7 +70,7 @@ def test_run_helloapache_app(self, capsys): print stdout # Since this a Docker-only provider test, docker *should* be in it, NOT Kubernetes - assert "u'provider': u'docker'" in stdout + assert "provider: Docker" in stdout assert "Deploying to Kubernetes" not in stdout assert exec_info.value.code == 0 diff --git a/tests/units/nulecule/test_lib.py b/tests/units/nulecule/test_lib.py index d9e56dac..d313429e 100644 --- a/tests/units/nulecule/test_lib.py +++ b/tests/units/nulecule/test_lib.py @@ -25,8 +25,10 @@ def test_get_provider_success(self): nb.plugin.getProvider = mock.Mock(return_value=return_provider) ret_provider_key, ret_provider = nb.get_provider() self.assertEqual(provider_key, ret_provider_key) - return_provider.assert_called_with({u'provider': provider_key}, - '', False) + return_provider.assert_called_with( + {'provider': provider_key, 'namespace': 'default'}, + '', + False) def test_get_provider_failure(self): """ diff --git a/tests/units/nulecule/test_nulecule.py b/tests/units/nulecule/test_nulecule.py index 0f3a3372..13e3e648 100644 --- a/tests/units/nulecule/test_nulecule.py +++ b/tests/units/nulecule/test_nulecule.py @@ -101,23 +101,24 @@ def test_load_config_with_default_provider(self): 'key3': 'val3' }, 'component1': { - 'key2': 'val2', - 'key1': 'val1' + 'key2': 'val2' } }) - self.assertEqual(n.components[0].config.context(), { - 'key3': 'val3', - 'key2': 'val2', - 'key1': 'val1', - 'provider': 'docker' - }) + self.assertEqual( + n.components[0].config.context(scope=n.components[0].namespace), + {'key3': 'val3', + 'key2': 'val2', + 'key1': 'val1', + 'provider': 'docker', + 'namespace': 'default'} + ) def test_load_config_without_default_provider(self): """ Test Nulecule load_config without specifying a default provider. """ - config = Config(answers={}) + config = Config() params = [ { @@ -150,7 +151,7 @@ def test_load_config_without_default_provider(self): graph=graph, params=params, basepath='some/path', config=config) n.load_components() - n.load_config(config) + n.load_config() self.assertEqual(n.config.runtime_answers(), { 'general': { @@ -160,17 +161,18 @@ def test_load_config_without_default_provider(self): 'key3': 'val3' }, 'component1': { - 'key2': 'val2', - 'key1': 'val1' + 'key2': 'val2' } }) - self.assertEqual(n.components[0].config.context(), { - 'key3': 'val3', - 'key2': 'val2', - 'key1': 'val1', - 'provider': 'kubernetes' - }) + self.assertEqual( + n.components[0].config.context(n.components[0].namespace), + {'key3': 'val3', + 'key2': 'val2', + 'key1': 'val1', + 'namespace': 'default', + 'provider': 'kubernetes'} + ) def test_load_config_with_default_provider_overridden_by_answers(self): """ @@ -228,17 +230,18 @@ def test_load_config_with_default_provider_overridden_by_answers(self): 'key3': 'val3' }, 'component1': { - 'key2': 'val2', - 'key1': 'val1' + 'key2': 'val2' } }) - self.assertEqual(n.components[0].config.context(), { - 'key3': 'val3', - 'key2': 'val2', - 'key1': 'val1', - 'provider': 'openshift' - }) + self.assertEqual( + n.components[0].config.context(n.components[0].namespace), + {'key3': 'val3', + 'key2': 'val2', + 'key1': 'val1', + 'namespace': 'default', + 'provider': 'openshift'} + ) class TestNuleculeLoadComponents(unittest.TestCase): diff --git a/tests/units/nulecule/test_nulecule_component.py b/tests/units/nulecule/test_nulecule_component.py index 4bbcb418..9054a2c4 100644 --- a/tests/units/nulecule/test_nulecule_component.py +++ b/tests/units/nulecule/test_nulecule_component.py @@ -136,23 +136,24 @@ def test_load_config_local_app(self): 'general': {'a': 'b', 'key2': 'val2'}, 'some-app': {'key1': 'val1'} } - conf = Config('some-app', answers=initial_config) + conf = Config(answers=initial_config) nc = NuleculeComponent('some-app', 'some/path', params=params, config=conf) nc.load_config() runtime_answers = nc.config.runtime_answers() self.assertEqual(runtime_answers, { - 'general': {'a': 'b', 'key2': 'val2', 'provider': 'kubernetes', 'namespace': 'default'}, - 'some-app': {'key1': 'val1', 'key2': 'val2'} + 'general': { + 'a': 'b', + 'key2': 'val2', + 'provider': 'kubernetes', + 'namespace': 'default' + }, + 'some-app': {'key1': 'val1'} }) def test_load_config_external_app(self): """Test load config for external app""" - mock_nulecule = mock.Mock( - name='nulecule', - spec=Nulecule('some-id', '0.0.2', {}, [], 'some/path') - ) params = [ {'name': 'key1', 'description': 'key1'}, {'name': 'key2', 'description': 'key2'} @@ -161,17 +162,19 @@ def test_load_config_external_app(self): 'general': {'a': 'b', 'key2': 'val2'}, 'some-app': {'key1': 'val1'} } - config = Config('some-app', answers=initial_config) + 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.load_config(config=config) + nc.config = config + nc.load_config() mock_nulecule.load_config.assert_called_once_with( - config=Config('some-app', answers=initial_config, data={ - 'general': {}, - 'some-app': {'key1': 'val1', 'key2': 'val2'} - }), ask=False, skip_asking=False) + config=config, ask=False, skip_asking=False) class TestNuleculeComponentLoadExternalApplication(unittest.TestCase): @@ -260,7 +263,7 @@ def test_render_for_local_app_with_missing_artifacts_for_provider(self): dryrun = False nc = NuleculeComponent(name='some-app', basepath='some/path') - nc.config = {} + nc.config = Config() nc.artifacts = {'x': ['some-artifact']} self.assertRaises(NuleculeException, nc.render, provider_key, dryrun) @@ -276,37 +279,44 @@ def test_render_for_local_app_with_missing_artifacts_from_nulecule(self): with self.assertRaises(NuleculeException): nc.render() - @mock.patch('atomicapp.nulecule.base.NuleculeComponent.get_context') @mock.patch('atomicapp.nulecule.base.NuleculeComponent.' 'get_artifact_paths_for_provider') @mock.patch('atomicapp.nulecule.base.NuleculeComponent.render_artifact') def test_render_for_local_app_with_artifacts_for_provider( - self, mock_render_artifact, mock_get_artifact_paths_for_provider, - mock_get_context): + self, mock_render_artifact, mock_get_artifact_paths_for_provider): """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 + # mock_get_context.return_value = context nc = NuleculeComponent(name='some-app', basepath='some/path') - nc.config = {'general': {'key1': 'val1'}, 'some-provider': {'a': 'b'}} + nc.config = Config(answers={ + 'general': {'key1': 'val1'}, + 'some-provider': {'a': 'b'} + }) nc.artifacts = { 'some-provider': ['artifact1', 'artifact2'], 'x': ['foo'] } nc.render(provider_key, dryrun) + expected_context = { + 'key1': 'val1', + 'namespace': 'default', + 'provider': 'kubernetes' + } mock_get_artifact_paths_for_provider.assert_called_once_with( provider_key) - mock_render_artifact.assert_any_call('some/path/artifact1', context, + mock_render_artifact.assert_any_call('some/path/artifact1', + expected_context, 'some-provider') - mock_render_artifact.assert_any_call('some/path/artifact2', context, + mock_render_artifact.assert_any_call('some/path/artifact2', + expected_context, 'some-provider') mock_get_artifact_paths_for_provider.assert_called_once_with( provider_key)