def test_find_digests_to_delete_tags_by_age_no_keep(self, get_keep_digests_patched, get_delete_digests_patched): get_keep_digests_patched.return_value = [] all_tags_list = self.registry.list_tags("imagename") tags_to_keep = get_newer_tags(self.registry, "imagename", 24, all_tags_list) find_digests_to_delete(registry=self.registry, image_name="imagename", tags_to_delete=all_tags_list, tags_to_keep=tags_to_keep) self.list_tags_mock.assert_called_with("imagename") self.get_tag_config_mock.assert_called_with("imagename", "image") get_keep_digests_patched.assert_called_with(image_name="imagename", tags_to_keep=[]) get_delete_digests_patched.assert_called_with(image_name="imagename", tags_to_delete=['image'], digests_to_keep=[])
def test_find_digests_to_delete_by_age_no_keep_with_non_utc_value(self, get_keep_digests_patched, get_delete_digests_patched): get_keep_digests_patched.return_value = [] self.registry.get_image_age.return_value = "2017-12-27T12:47:33.511765448+02:00" all_tags_list = self.registry.list_tags("imagename") tags_to_keep = get_newer_tags(self.registry, "imagename", 24, all_tags_list) find_digests_to_delete(registry=self.registry, image_name="imagename", tags_to_delete=all_tags_list, tags_to_keep=tags_to_keep) self.list_tags_mock.assert_called_with("imagename") self.get_tag_config_mock.assert_called_with("imagename", "image") get_keep_digests_patched.assert_called_with(image_name="imagename", tags_to_keep=[]) get_delete_digests_patched.assert_called_with(image_name="imagename", tags_to_delete=['image'], digests_to_keep=[])
def test_find_digests_to_delete_by_age_keep_tags_by_age(self, get_keep_digests_patched, get_delete_digests_patched): get_keep_digests_patched.return_value = ["MOCK_DIGEST"] all_tags_list = self.registry.list_tags("imagename") self.registry.get_image_age.return_value = str(datetime.now(tz=tzutc())) tags_to_keep = get_newer_tags(self.registry, "imagename", 24, all_tags_list) find_digests_to_delete(registry=self.registry, image_name="imagename", tags_to_delete=all_tags_list, tags_to_keep=tags_to_keep) self.list_tags_mock.assert_called_with("imagename") self.get_tag_config_mock.assert_called_with("imagename", "image") get_keep_digests_patched.assert_called_with(image_name="imagename", tags_to_keep=['image']) get_delete_digests_patched.assert_called_with(image_name="imagename", tags_to_delete=['image'], digests_to_keep=["MOCK_DIGEST"])
def test_find_tag_digest_to_delete_equals_to_keep(self): digests = find_digests_to_delete(self.registry, "imagename", ["tag1"], ["tag2"]) self.assertEqual(len(digests), 0, msg="Found {0} digest marked for deletion. Should not find any!".format(len(digests))) calls = [call("imagename", "tag2"), call("imagename", "tag1")] self.get_tag_digest_mock.assert_has_calls(calls, any_order=True) self.assertEqual(len(self.get_tag_digest_mock.mock_calls), 2)
def test_find_tag_digest_none(self): self.get_tag_digest_mock = MagicMock(return_value=None) self.registry.get_tag_digest = self.get_tag_digest_mock digests = find_digests_to_delete(self.registry, "imagename", ["tag1", "tag2"], ["tag3"]) self.assertEqual(len(digests), 0, msg="Found {0} digest marked for deletion. Should not find any!".format(len(digests))) calls = [call("imagename", "tag1"), call("imagename", "tag2"), call("imagename", "tag3")] self.get_tag_digest_mock.assert_has_calls(calls, any_order=True) self.assertEqual(len(self.get_tag_digest_mock.mock_calls), 3)
def test_tag_digests(self): digests_to_delete = find_digests_to_delete(self.registry, "image1", tags_to_delete=["1"], tags_to_keep=[]) delete_digests(self.registry, "image1", False, digests_to_delete) calls = [ call( 'HEAD', 'http://testdomain.com/v2/image1/manifests/1', auth=(None, None), headers=self.registry.HEADERS, verify=True ), call( "DELETE", "http://testdomain.com/v2/image1/manifests/MOCK_DIGEST_HEADER", auth=(None, None), headers=self.registry.HEADERS, verify=True ) ] self.registry.http.request.assert_has_calls(calls, any_order=True) self.assertEqual(self.registry.http.request.call_count, 2) self.assertTrue("MOCK_DIGEST_HEADER" in digests_to_delete)
def test_delete_tag_ignored(self): digests_to_delete = find_digests_to_delete(self.registry, "image1", tags_to_delete=["test_tag"], tags_to_keep=["test_tag_ignore"]) delete_digests(self.registry, "image1", False, digests_to_delete) calls = [ call( "HEAD", "http://testdomain.com/v2/image1/manifests/test_tag", auth=(None, None), headers=self.registry.HEADERS, verify=True ), call( "HEAD", "http://testdomain.com/v2/image1/manifests/test_tag_ignore", auth=(None, None), headers=self.registry.HEADERS, verify=True ) ] self.registry.http.request.assert_has_calls(calls, any_order=True) self.assertEqual(self.registry.http.request.call_count, 2)
def test_find_tags_to_delete(self): digests = find_digests_to_delete(self.registry, "imagename", ["tag1"], []) self.get_tag_digest_mock.assert_called_once_with("imagename", "tag1") self.assertEqual(len(digests), 1, msg="Found {0} digest marked for deletion.".format(len(digests)))