def test_GIVEN_redundant_progress_WHEN_upload_image_to_repo_THEN_filter( self, add_annotations_to_manifest): # GIVEN repository_uri = self.ecr_client.create_repository( repositoryName=self.REPO_NAME)["repository"]["repositoryUri"] status_dict = { "status": "pushing", "progressDetail": { "total": 100, "current": 10 } } statuses = (str.encode(json.dumps(status_dict)), str.encode(json.dumps(status_dict))) docker_client = docker.from_env() docker_client.api.push.return_value = statuses add_annotations_to_manifest = MagicMock() # WHEN output_gen = UploadToRepoHandler.upload_image_to_repo( self.REPO_NAME, repository_uri, "", "") output_statuses = [status for status in output_gen] # THEN # verify only 2 are returned (instead of three) # there's an extra 100 progress status for marking completion expected = [ ImageUploadStatus(progress=10, error_msg=None, error_trace=None), ImageUploadStatus(progress=100, error_msg=None, error_trace=None) ] self.assertEquals(expected, output_statuses)
def test_GIVEN_100_progress_WHEN_cap_progress_THEN_return_status_with_99_progress( self): # GIVEN uncapped = ImageUploadStatus(progress=100, error_msg=None, error_trace=None) expected = ImageUploadStatus(progress=99, error_msg=None, error_trace=None) # WHEN capped = UploadToRepoHandler.cap_progress(uncapped) # THEN self.assertEquals(expected, capped)
def test_GIVEN_current_and_total_WHEN_parse_status_THEN_return_status_with_progress( self): status = json.dumps({ "status": "pushing", "progressDetail": { "total": 100, "current": 10 } }) expected = ImageUploadStatus(progress=10, error_msg=None, error_trace=None) self.assertEquals(expected, UploadToRepoHandler.parse_upload_status(status))
def test_GIVEN_redundant_progress_with_error_WHEN_upload_image_to_repo_THEN_dont_filter( self, add_annotations_to_manifest): # GIVEN repository_uri = self.ecr_client.create_repository( repositoryName=self.REPO_NAME)["repository"]["repositoryUri"] image = "image" status_dict1 = { "status": "pushing", "progressDetail": { "total": 100, "current": 99 } } status_dict2 = { "status": "pushing", "progressDetail": UploadToRepoHandler.LAYER_EXISTS_MSG } statuses = (str.encode(json.dumps(status_dict1)), str.encode(json.dumps(status_dict2))) docker_client = docker.from_env() docker_client.api.push.return_value = statuses add_annotations_to_manifest = MagicMock() # WHEN output_gen = UploadToRepoHandler.upload_image_to_repo( self.REPO_NAME, repository_uri, image, "") output_statuses = [status for status in output_gen] # THEN error_msg = "This image has already been uploaded to this repository." expected = [ ImageUploadStatus(progress=99, error_msg=None, error_trace=None), ImageUploadStatus(progress=99, error_msg=error_msg, error_trace=None) ] self.assertEquals(expected, output_statuses)
def test_GIVEN_layer_already_upload_WHEN_parse_status_THEN_return_status_with_error( self): status = json.dumps({ "status": "pushing", "progressDetail": UploadToRepoHandler.LAYER_EXISTS_MSG }) expected = ImageUploadStatus( progress=100, error_trace=None, error_msg="This image has already been uploaded to this repository." ) self.assertEquals(expected, UploadToRepoHandler.parse_upload_status(status))
def test_GIVEN_diff_from_previous_progress_WHEN_status_should_be_reported_THEN( self): # GIVEN previous_progress = 2 recent_progress = 2 status = ImageUploadStatus(progress=recent_progress, error_msg=None, error_trace=None) # WHEN observed = UploadToRepoHandler.status_should_be_reported( status, previous_progress) # THEN self.assertFalse(observed)