def test_handler_delete_not_created(context, cf_endpoint, device_farm_endpoint): event = { 'RequestType': 'Delete', 'LogicalResourceId': 'DeviceFarm', 'PhysicalResourceId': 'ResourceNotCreated', 'RequestId': '1234', 'ResponseURL': TEST_RESPONSE_URL, 'StackId': 'arn:aws:cloudformation:us-east-2:namespace:stack/stack-name/guid', 'ResourceProperties': { 'ProjectName': TEST_PROJECT_NAME, } } project_resource.lambda_handler(event, context) assert cf_endpoint.called assert len(cf_endpoint.request_history) == 1 assert cf_endpoint.request_history[0].json( )['PhysicalResourceId'] == 'ResourceNotCreated' assert cf_endpoint.request_history[0].json()['Status'] == 'SUCCESS' device_farm_endpoint.create_project.assert_not_called() device_farm_endpoint.update_project.assert_not_called() device_farm_endpoint.delete_project.assert_not_called()
def test_handler_delete_fails(context, cf_endpoint, device_farm_endpoint): event = { 'RequestType': 'Delete', 'LogicalResourceId': 'DeviceFarm', 'PhysicalResourceId': TEST_PHYSICAL_RESOURCE_ID, 'RequestId': '1234', 'ResponseURL': TEST_RESPONSE_URL, 'StackId': 'arn:aws:cloudformation:us-east-2:namespace:stack/stack-name/guid', 'ResourceProperties': { 'ProjectName': TEST_PROJECT_NAME, } } device_farm_endpoint.delete_project = MagicMock( side_effect=Exception('This went wrong')) project_resource.lambda_handler(event, context) assert cf_endpoint.called assert len(cf_endpoint.request_history) == 1 assert cf_endpoint.request_history[0].json( )['PhysicalResourceId'] == TEST_PHYSICAL_RESOURCE_ID assert cf_endpoint.request_history[0].json()['Status'] == 'FAILED' device_farm_endpoint.create_project.assert_not_called() device_farm_endpoint.update_project.assert_not_called() device_farm_endpoint.delete_project.assert_called_with( arn=TEST_PHYSICAL_RESOURCE_ID)
def test_handler_update(context, cf_endpoint, device_farm_endpoint): event = { 'RequestType': 'Update', 'LogicalResourceId': 'DeviceFarm', 'PhysicalResourceId': TEST_PHYSICAL_RESOURCE_ID, 'RequestId': '1234', 'ResponseURL': TEST_RESPONSE_URL, 'StackId': 'arn:aws:cloudformation:us-east-2:namespace:stack/stack-name/guid', 'ResourceProperties': { 'ProjectName': TEST_PROJECT_NAME, } } project_resource.lambda_handler(event, context) assert cf_endpoint.called assert len(cf_endpoint.request_history) == 1 assert cf_endpoint.request_history[0].json( )['PhysicalResourceId'] == TEST_PHYSICAL_RESOURCE_ID assert cf_endpoint.request_history[0].json()['Status'] == 'SUCCESS' assert cf_endpoint.request_history[0].json( )['Data']['Arn'] == TEST_PHYSICAL_RESOURCE_ID assert cf_endpoint.request_history[0].json( )['Data']['ProjectId'] == TEST_PROJECT_ID assert cf_endpoint.request_history[0].json( )['Data']['TopDevicesDevicePoolArn'] == TEST_TOP_DEVICES_ARN device_farm_endpoint.create_project.assert_not_called() device_farm_endpoint.update_project.assert_called_with( arn=TEST_PHYSICAL_RESOURCE_ID, name=TEST_PROJECT_NAME) device_farm_endpoint.get_paginator.assert_called_with('list_device_pools') device_farm_endpoint.get_paginator().paginate.assert_called_with( arn=TEST_PHYSICAL_RESOURCE_ID, type='CURATED')