Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Commit

Permalink
Fixed tests for config refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtnpro committed Aug 12, 2016
1 parent 155ed33 commit aea5161
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion tests/units/cli/test_default_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions tests/units/nulecule/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
55 changes: 29 additions & 26 deletions tests/units/nulecule/test_nulecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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': {
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
54 changes: 32 additions & 22 deletions tests/units/nulecule/test_nulecule_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit aea5161

Please sign in to comment.