def test_deployments_outputs_json(self): outputs = deployments.DeploymentOutputs({ 'deployment_id': 'dep1', 'outputs': { 'port': 8080 } }) deployment = deployments.Deployment({ 'outputs': { 'port': { 'description': 'Webserver port.', 'value': '...' } } }) self.client.deployments.get = MagicMock(return_value=deployment) self.client.deployments.outputs.get = MagicMock(return_value=outputs) outcome = self.invoke('cfy deployments outputs dep1 --json') parsed = json.loads(outcome.output) self.assertEqual( parsed, {'port': { 'value': 8080, 'description': 'Webserver port.' }})
def test_workflows_get(self): deployment = deployments.Deployment({ 'blueprint_id': 'mock_blueprint_id', 'workflows': [{ 'created_at': None, 'name': 'mock_workflow', 'parameters': { 'test-key': { 'default': 'test-value' }, 'test-mandatory-key': {}, 'test-nested-key': { 'default': { 'key': 'nested value' } } } }] }) self.client.deployments.get = MagicMock(return_value=deployment) outcome = self.invoke('workflows get mock_workflow -d dep_id') self.assertIn('test-mandatory-key', outcome.output) self.assertIn('nested value', outcome.output)
def test_deployment_create_without_skip_plugins_validation_flag(self): deployment = deployments.Deployment({'deployment_id': 'deployment_id'}) self.client.deployments.create = MagicMock(return_value=deployment) self.invoke('cfy deployments create deployment -b aa') call_args = list(self.client.deployments.create.call_args) self.assertIn('skip_plugins_validation', call_args[1]) self.assertEqual(call_args[1]['skip_plugins_validation'], False)
def test_workflows_get_json(self): deployment = deployments.Deployment({ 'blueprint_id': 'mock_blueprint_id', 'workflows': [{ 'created_at': None, 'name': 'mock_workflow', 'parameters': { 'test-key': { 'default': 'test-value' }, 'test-mandatory-key': {}, 'test-nested-key': { 'default': { 'key': 'nested value' } } } }] }) self.client.deployments.get = MagicMock(return_value=deployment) outcome = self.invoke('workflows get mock_workflow -d dep_id --json') parsed = json.loads(outcome.output) self.assertEqual(deployment.workflows[0]['parameters'], parsed['parameters'])
def test_workflows_get_nonexistent_workflow(self): expected_message = 'Workflow nonexistent_workflow not found' deployment = deployments.Deployment({ 'blueprint_id': 'mock_blueprint_id', 'workflows': [{ 'created_at': None, 'name': 'mock_workflow', 'parameters': { 'test-key': { 'default': 'test-value' }, 'test-mandatory-key': {}, 'test-nested-key': { 'default': { 'key': 'val' } } } }] }) self.client.deployments.get = MagicMock(return_value=deployment) self.invoke('cfy workflows get nonexistent_workflow -d dep_id', expected_message)
def test_deployment_create(self): deployment = deployments.Deployment({'deployment_id': 'deployment_id'}) self.client.deployments.create = MagicMock(return_value=deployment) cli_runner.run_cli('cfy deployments create -b ' 'a-blueprint-id -d deployment')
def test_deployment_create(self): deployment = deployments.Deployment({ 'deployment_id': 'deployment_id' }) self.client.deployments.create = MagicMock(return_value=deployment) self.invoke( 'cfy deployments create deployment -b a-blueprint-id')
def create_deployments_in_tenant(deps_list, num_of_deps, tenant, start_index): for i in range(num_of_deps): deps_list.append( deployments.Deployment({ 'id': 'dep{0}'.format(start_index), 'tenant_name': tenant['name'] })) start_index += 1 return start_index
def test_deployments_inputs_json(self): deployment = deployments.Deployment({ 'deployment_id': 'deployment_id', 'inputs': {'key1': 'val1', 'key2': 'val2'} }) self.client.deployments.get = MagicMock(return_value=deployment) outcome = self.invoke('cfy deployments inputs deployment_id --json') parsed = json.loads(outcome.output) self.assertEqual(parsed, {'key1': 'val1', 'key2': 'val2'})
def test_deployments_outputs(self): outputs = deployments.DeploymentOutputs({ 'deployment_id': 'dep1', 'outputs': { 'port': 8080 } }) deployment = deployments.Deployment({ 'outputs': { 'port': { 'description': 'Webserver port.', 'value': '...' } } }) self.client.deployments.get = MagicMock(return_value=deployment) self.client.deployments.outputs.get = MagicMock(return_value=outputs) self.invoke('cfy deployments outputs dep1')
def test_workflows_sort_list(self): deployment = deployments.Deployment({ 'blueprint_id': 'mock_blueprint_id', 'workflows': [{ 'created_at': None, 'name': 'my_workflow_1', 'parameters': { 'test-key': { 'default': 'test-value' }, 'test-mandatory-key': {}, 'test-nested-key': { 'default': { 'key': 'val' } } } }, { 'created_at': None, 'name': 'my_workflow_0', 'parameters': { 'test-key': { 'default': 'test-value' }, 'test-mandatory-key': {}, 'test-nested-key': { 'default': { 'key': 'val' } } } }] }) self.client.deployments.get = MagicMock(return_value=deployment) output = self.invoke('cfy workflows list -d a-deployment-id').output first = output.find('my_workflow_0') second = output.find('my_workflow_1') self.assertTrue(0 < first < second)
def test_deployments_inputs(self): deployment = deployments.Deployment({ 'deployment_id': 'deployment_id', 'inputs': {'key1': 'val1', 'key2': 'val2'} }) expected_outputs = [ 'Retrieving inputs for deployment deployment_id...', '- "key1":', 'Value: val1', '- "key2":', 'Value: val2', ] self.client.deployments.get = MagicMock(return_value=deployment) outcome = self.invoke('cfy deployments inputs deployment_id') outcome = [o.strip() for o in outcome.logs.split('\n')] for output in expected_outputs: self.assertIn(output, outcome)
def test_workflows_list(self): deployment = deployments.Deployment({ 'blueprint_id': 'mock_blueprint_id', 'workflows': [{ 'created_at': None, 'name': 'mock_workflow', 'parameters': { 'test-key': { 'default': 'test-value' }, 'test-mandatory-key': {}, 'test-nested-key': { 'default': { 'key': 'val' } } } }] }) self.client.deployments.get = MagicMock(return_value=deployment) self.invoke('cfy workflows list -d a-deployment-id')
def test_deployment_create_without_site_name(self): deployment = deployments.Deployment({'deployment_id': 'deployment_id'}) self.client.deployments.create = MagicMock(return_value=deployment) self.invoke('cfy deployments create deployment -b a') call_args = list(self.client.deployments.create.call_args) self.assertIsNone(call_args[1]['site_name'])
def mock_deployments_get(*args, **kwargs): return deployments.Deployment({'blueprint_id': 'bid'})
def _mock_deployments_get(self, deployment_id): return deployments.Deployment({'id': deployment_id})