def get_version(name, environment, short): ServiceInformationFetcher(name, environment).get_version(short)
def test_fetch_current_image_uri(self, mock_client): mock_client.return_value = mock_client with self.subTest("when all services configurations are present"): service_configuration = { 'ecr_repo': {'name': 'dummy-repo'}, 'services': { 'ServiceOne': {'ecs_service_name': 'service1'}, 'ServiceTwo': {'ecs_service_name': 'service2'}, } } mock_client.describe_services.return_value = { 'services': [{'taskDefinition': 'tdArn1'}]} mock_client.describe_task_definition.return_value = {'taskDefinition': { 'containerDefinitions': [{'image': 'image:v1'}] }} sif = ServiceInformationFetcher( service, env, service_configuration) actual = sif._fetch_current_image_uri() expected = "image:v1" self.assertEqual(expected, actual) mock_client.describe_task_definition.assert_called_with( taskDefinition='tdArn1') with self.subTest("when few services configurations are present"): service_configuration = { 'ecr_repo': {'name': 'dummy-repo'}, 'services': { 'ServiceOne': {}, 'ServiceTwo': {'ecs_service_name': 'service2'}, } } mock_client.describe_services.return_value = { 'services': [{'taskDefinition': 'tdArn1'}]} mock_client.describe_task_definition.return_value = {'taskDefinition': { 'containerDefinitions': [{'image': 'image:v1'}] }} sif = ServiceInformationFetcher( service, env, service_configuration) actual = sif._fetch_current_image_uri() expected = "image:v1" self.assertEqual(expected, actual) mock_client.describe_services.assert_called_with( cluster="cluster-test", services=["service2"], ) with self.subTest("raises exception if service is not present"): service_configuration = { 'ecr_repo': {'name': 'dummy-repo'}, 'services': { 'ServiceOne': {}, 'ServiceTwo': {'ecs_service_name': 'service2'}, } } mock_client.describe_services.side_effect = Exception() sif = ServiceInformationFetcher( service, env, service_configuration) with self.assertRaises(Exception): sif._fetch_current_image_uri()