def test_find_reference_with_invalid_template_throws_error(self): self.mock_tosca_discover_service.discover.side_effect = ToscaValidationError( 'Validation error') driver = ResourceDriverHandler( self.mock_location_translator, resource_driver_config=self.resource_driver_config, heat_translator_service=self.mock_heat_translator, tosca_discovery_service=self.mock_tosca_discover_service) with self.assertRaises(InvalidDriverFilesError) as context: driver.find_reference('test', self.tosca_driver_files, self.deployment_location) self.assertEqual(str(context.exception), 'Validation error')
def test_find_reference_returns_empty_when_not_found(self): self.mock_tosca_discover_service.discover.side_effect = NotDiscoveredError( 'Not found') driver = ResourceDriverHandler( self.mock_location_translator, resource_driver_config=self.resource_driver_config, heat_translator_service=self.mock_heat_translator, tosca_discovery_service=self.mock_tosca_discover_service) response = driver.find_reference('test', self.tosca_driver_files, self.deployment_location) self.assertIsInstance(response, FindReferenceResponse) self.assertIsNone(response.result)
def test_find_reference(self): self.mock_tosca_discover_service.discover.return_value = DiscoveryResult( '1', {'test': '1'}) driver = ResourceDriverHandler( self.mock_location_translator, resource_driver_config=self.resource_driver_config, heat_translator_service=self.mock_heat_translator, tosca_discovery_service=self.mock_tosca_discover_service) response = driver.find_reference('test', self.tosca_driver_files, self.deployment_location) self.assertIsInstance(response, FindReferenceResponse) self.assertIsNotNone(response.result) self.assertIsInstance(response.result, FindReferenceResult) self.assertEqual(response.result.associated_topology, None) self.assertEqual(response.result.outputs, {'test': '1'}) self.mock_location_translator.from_deployment_location.assert_called_once_with( self.deployment_location) self.mock_tosca_discover_service.discover.assert_called_once_with( self.discover_template, self.mock_location_translator. from_deployment_location.return_value, {'instance_name': 'test'})