def test_check_sha256(self): sha = "sha256:{sha}".format(sha=hashlib.sha256().hexdigest()) assert tools.check_sha256(sha) sha = "sha257:{sha}".format(sha=hashlib.sha256().hexdigest()) assert not tools.check_sha256(sha) sha = "sha256:wrong" assert not tools.check_sha256(sha)
def test_image_json( self, fixture_registry_url, fixture_repository, fixture_tags, capsys ): tag = 'latest' with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-j', ] ): console_main() out_json = tools.get_output_json(capsys) assert out_json and isinstance(out_json, dict) and \ list(out_json.keys()) == ['result'] and \ list(out_json['result'].keys()) == ['digest'] and \ tools.check_sha256(out_json['result']['digest']) # with manifest with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-j', '-m', ] ): console_main() out_json = tools.get_output_json(capsys) assert out_json and isinstance(out_json, dict) and \ list(out_json.keys()) == ['result'] and \ sorted(list(out_json['result'].keys())) \ == ['digest', 'manifest'] and \ tools.check_sha256(out_json['result']['digest'])
def test_image( self, fixture_client, fixture_repository, fixture_tags, ): tag = 'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385' image = self.get_repo(fixture_client).image(tag) assert image and image.name == fixture_repository and \ image.data and isinstance(image.data, dict) and \ image.tag == tag and \ tools.check_sha256(image.digest) and \ tools.check_sha256(image.config_digest) # get image date image.get_date() assert image.date # delete flow image.delete() # after delete, same image delete should 404 (no more manifest) msg404 = tools.get_error_status_message(404) with pytest.raises(DRegCliException) as excinfo: image.delete() assert str(excinfo.value) == msg404 # after delete, same image request should 404 (no more manifest) with pytest.raises(DRegCliException) as excinfo: self.get_repo(fixture_client).image(tag) assert str(excinfo.value) == msg404 fixture_tags.remove(tag) repo = self.get_repo(fixture_client) assert sorted(repo.tags()) == sorted(fixture_tags) # after delete, repo should still be here in catalog assert repo.name == fixture_repository
def test_image_delete_json( self, fixture_registry_url, fixture_repository, fixture_tags, fixture_client, capsys ): tag = 'master-b2a7d05ca36cdd3e8eb092f857580b3ed0f7159a-1386' with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-d', '-y', '-j', ] ): console_main() out_json = tools.get_output_json(capsys) assert out_json and isinstance(out_json, dict) and \ list(out_json.keys()) == ['result'] and \ sorted(list(out_json['result'].keys())) == [ 'digest', 'message'] and \ tools.check_sha256(out_json['result']['digest']) and \ out_json['result']['message'] == 'deleted' # after delete, same image action should 404 (no more manifest) with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-d', '-y', '-j', ] ): msg404 = tools.get_error_status_message(404) expected_json = {'error': msg404} console_main() assert tools.get_output_json(capsys) == expected_json # extrapolated tags left # deleted in test_image_delete() fixture_tags.remove( 'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385') # deleted here fixture_tags.remove( 'master-b2a7d05ca36cdd3e8eb092f857580b3ed0f7159a-1386') repo = self.get_repo(fixture_client) assert sorted(repo.tags()) == sorted(fixture_tags) # after delete, repo should still be here in catalog assert repo.name == fixture_repository
def test_image_delete( self, fixture_registry_url, fixture_repository, fixture_tags, fixture_client, capsys ): tag = 'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385' expected_out = [ 'image', 'GET {url}/v2/{repo}/manifests/{tag}'.format( url=fixture_registry_url, repo=fixture_repository, tag=tag ), ] expected_delete_prefix = \ 'DELETE {url}/v2/{repo}/manifests/'.format( url=fixture_registry_url, repo=fixture_repository ) with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-d', '-y' ] ): console_main() out_lines = tools.get_output_lines(capsys) # 5 lines: command, get image request, delete request, # then digest and 'deleted' message delete_digest = out_lines[2][len(expected_delete_prefix):] digest = out_lines[3] assert len(out_lines) == 5 and \ out_lines[:2] == expected_out and \ out_lines[2].startswith(expected_delete_prefix) and \ tools.check_sha256(delete_digest) and \ tools.check_sha256(digest) and \ out_lines[4] == 'deleted' # after delete, same image action should 404 (no more manifest) with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-d', '-y' ] ): expected_out_404 = expected_out.copy() expected_out_404.append(tools.get_error_status_message(404)) console_main() assert tools.get_output_lines(capsys) == expected_out_404 fixture_tags.remove( 'master-6da64c000cf59c30e4841371e0dac3dd02c31aaa-1385') repo = self.get_repo(fixture_client) assert sorted(repo.tags()) == sorted(fixture_tags) # after delete, repo should still be here in catalog assert repo.name == fixture_repository
def test_image( self, fixture_registry_url, fixture_repository, fixture_tags, capsys ): tag = 'latest' expected_out = [ 'image', 'GET {url}/v2/{repo}/manifests/{tag}'.format( url=fixture_registry_url, repo=fixture_repository, tag=tag ), ] with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, ] ): console_main() out_lines = tools.get_output_lines(capsys) # 3 lines, command, request and digest assert len(out_lines) == 3 and \ out_lines[:2] == expected_out and \ tools.check_sha256(out_lines[2]) # with manifest expected_out = [ 'image', 'GET {url}/v2/{repo}/manifests/{tag}'.format( url=fixture_registry_url, repo=fixture_repository, tag=tag ), ] with mock.patch( 'sys.argv', [ 'dregcli', 'image', fixture_registry_url, fixture_repository, tag, '-m' ] ): console_main() out_lines = tools.get_output_lines(capsys) # as we ask for manifest, we have more than 3 out_lines assert len(out_lines) > 3 and \ out_lines[:2] == expected_out and \ tools.check_sha256(out_lines[2])