From c283a02e5faa2059644eae4f50c9a6bf8f05bee9 Mon Sep 17 00:00:00 2001 From: danfengliu Date: Tue, 25 Feb 2020 10:40:29 +0800 Subject: [PATCH] Update existing API tests for API V2.0 Signed-off-by: danfengliu --- tests/apitests/python/library/artifact.py | 10 +++- .../test_add_member_to_private_project.py | 8 +--- .../python/test_add_replication_rule.py | 15 ++---- .../python/test_add_sys_label_to_tag.py | 23 ++++------ .../python/test_assign_role_to_ldap_group.py | 46 ++++++++++--------- .../apitests/python/test_assign_sys_admin.py | 7 +-- .../test_copy_artifact_outside_project.py | 14 ++---- tests/apitests/python/test_del_repo.py | 11 ++--- .../python/test_garbage_collection.py | 15 ++---- .../python/test_manage_project_member.py | 11 ++--- ...test_project_level_policy_content_trust.py | 23 ++++------ tests/apitests/python/test_project_quota.py | 12 ++--- tests/apitests/python/test_retention.py | 4 +- tests/apitests/python/test_robot_account.py | 11 ++--- tests/apitests/python/test_scan_all_images.py | 15 ++---- tests/apitests/python/test_scan_image.py | 11 ++--- tests/apitests/python/test_sign_image.py | 24 ++++------ tests/apitests/python/testutils.py | 14 ++++++ tests/robot-cases/Group0-BAT/API_DB.robot | 40 ++++++++-------- 19 files changed, 132 insertions(+), 182 deletions(-) diff --git a/tests/apitests/python/library/artifact.py b/tests/apitests/python/library/artifact.py index 894757b1c..a671466aa 100644 --- a/tests/apitests/python/library/artifact.py +++ b/tests/apitests/python/library/artifact.py @@ -7,7 +7,15 @@ from v2_swagger_client.rest import ApiException class Artifact(base.Base): def get_reference_info(self, project_name, repo_name, reference, **kwargs): client = self._get_client(**kwargs) - return client.get_artifact_with_http_info(project_name, repo_name, reference) + params = {} + if "with_signature" in kwargs: + params["with_signature"] = kwargs["with_signature"] + return client.get_artifact_with_http_info(project_name, repo_name, reference, **params ) + + def add_label_to_reference(self, project_name, repo_name, reference, label_id, **kwargs): + client = self._get_client(**kwargs) + label = v2_swagger_client.Label(id = label_id) + return client.add_label_with_http_info(project_name, repo_name, reference, label) def copy_artifact(self, project_name, repo_name, _from, expect_status_code = 201, expect_response_body = None, **kwargs): client = self._get_client(**kwargs) diff --git a/tests/apitests/python/test_add_member_to_private_project.py b/tests/apitests/python/test_add_member_to_private_project.py index ea4c442e3..eb42a2c69 100644 --- a/tests/apitests/python/test_add_member_to_private_project.py +++ b/tests/apitests/python/test_add_member_to_private_project.py @@ -10,12 +10,8 @@ from library.user import User class TestProjects(unittest.TestCase): """UserGroup unit test stubs""" def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - + self.project = Project() + self.user= User() def tearDown(self): pass diff --git a/tests/apitests/python/test_add_replication_rule.py b/tests/apitests/python/test_add_replication_rule.py index 82e500c5c..8ff14a8f3 100644 --- a/tests/apitests/python/test_add_replication_rule.py +++ b/tests/apitests/python/test_add_replication_rule.py @@ -13,17 +13,10 @@ import swagger_client class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - replication = Replication() - self.replication= replication - - registry = Registry() - self.registry= registry + self.project = Project() + self.user = User() + self.replication = Replication() + self.registry = Registry() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_add_sys_label_to_tag.py b/tests/apitests/python/test_add_sys_label_to_tag.py index dee68f86c..9b092799a 100644 --- a/tests/apitests/python/test_add_sys_label_to_tag.py +++ b/tests/apitests/python/test_add_sys_label_to_tag.py @@ -5,6 +5,7 @@ import unittest from testutils import harbor_server from testutils import TEARDOWN from testutils import ADMIN_CLIENT +from library.artifact import Artifact from library.project import Project from library.user import User from library.repository import Repository @@ -14,19 +15,11 @@ from library.label import Label class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository() - self.repo= repo - repo_v2 = Repository(api_type='repository') - self.repo_v2= repo_v2 - - label = Label() - self.label= label + self.project = Project() + self.user = User() + self.artifact = Artifact(api_type='artifact') + self.repo = Repository(api_type='repository') + self.label = Label() @classmethod def tearDown(self): @@ -35,7 +28,7 @@ class TestProjects(unittest.TestCase): @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA) by user(UA); - self.repo_v2.delete_repoitory(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_add_g_lbl_CLIENT) + self.repo.delete_repoitory(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_add_g_lbl_CLIENT) #2. Delete project(PA); self.project.delete_project(TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT) @@ -89,7 +82,7 @@ class TestProjects(unittest.TestCase): TestProjects.label_id, _ = self.label.create_label(**ADMIN_CLIENT) #7. Add this system global label to repository(RA)/tag(TA). - self.repo.add_label_to_tag(TestProjects.repo_name, tag, int(TestProjects.label_id), **TestProjects.USER_add_g_lbl_CLIENT) + self.artifact.add_label_to_reference(TestProjects.project_add_g_lbl_name, TestProjects.repo_name.split('/')[1], tag, int(TestProjects.label_id), **TestProjects.USER_add_g_lbl_CLIENT) if __name__ == '__main__': unittest.main() diff --git a/tests/apitests/python/test_assign_role_to_ldap_group.py b/tests/apitests/python/test_assign_role_to_ldap_group.py index 740f169b8..4f63a5eec 100644 --- a/tests/apitests/python/test_assign_role_to_ldap_group.py +++ b/tests/apitests/python/test_assign_role_to_ldap_group.py @@ -3,10 +3,10 @@ """ Harbor API - These APIs provide services for manipulating Harbor project. + These APIs provide services for manipulating Harbor project. OpenAPI spec version: 1.4.0 - + Generated by: https://github.com/swagger-api/swagger-codegen.git """ @@ -21,12 +21,13 @@ import testutils import docker import swagger_client -from swagger_client.models.project import Project -from swagger_client.models.project_req import ProjectReq -from swagger_client.models.project_metadata import ProjectMetadata -from swagger_client.models.project_member import ProjectMember -from swagger_client.models.user_group import UserGroup -from swagger_client.models.configurations import Configurations + +from swagger_client.models.project import Project +from swagger_client.models.project_req import ProjectReq +from swagger_client.models.project_metadata import ProjectMetadata +from swagger_client.models.project_member import ProjectMember +from swagger_client.models.user_group import UserGroup +from swagger_client.models.configurations import Configurations from swagger_client.rest import ApiException @@ -38,16 +39,17 @@ class TestAssignRoleToLdapGroup(unittest.TestCase): harbor_host = os.environ["HARBOR_HOST"] """AssignRoleToLdapGroup unit test stubs""" product_api = testutils.GetProductApi("admin", "Harbor12345") + repository_api = testutils.GetRepositoryApi("admin", "Harbor12345") project_id = 0 docker_client = docker.from_env() - + def setUp(self): #login with admin, create a project and assign role to ldap group result = self.product_api.configurations_put(configurations=Configurations(ldap_filter="", ldap_group_attribute_name="cn", ldap_group_base_dn="ou=groups,dc=example,dc=com", ldap_group_search_filter="objectclass=groupOfNames", ldap_group_search_scope=2)) pprint(result) cfgs = self.product_api.configurations_get() pprint(cfgs) - req = ProjectReq() + req = ProjectReq() req.project_name = "ldap_group_test_prj" req.metadata = ProjectMetadata(public="false") result = self.product_api.projects_post(req) @@ -57,7 +59,7 @@ class TestAssignRoleToLdapGroup(unittest.TestCase): if projs.count>0 : project = projs[0] self.project_id = project.project_id - + # asign role to project with dn group_dn = "cn=harbor_admin,ou=groups,dc=example,dc=com" projectmember = ProjectMember() @@ -86,9 +88,9 @@ class TestAssignRoleToLdapGroup(unittest.TestCase): def tearDown(self): #delete images in project - result = self.product_api.repositories_repo_name_delete(repo_name="ldap_group_test_prj/busybox") + result = self.repository_api.delete_repository("ldap_group_test_prj", "busybox") pprint(result) - result = self.product_api.repositories_repo_name_delete(repo_name="ldap_group_test_prj/busyboxdev") + result = self.repository_api.delete_repository("ldap_group_test_prj", "busyboxdev") pprint(result) if self.project_id > 0 : self.product_api.projects_project_id_delete(self.project_id) @@ -100,7 +102,7 @@ class TestAssignRoleToLdapGroup(unittest.TestCase): projects = admin_product_api.projects_get(name="ldap_group_test_prj") self.assertTrue(projects.count > 1) self.assertEqual(1, projects[0].current_user_role_id) - + dev_product_api = testutils.GetProductApi("dev_user", "zhu88jie") projects = dev_product_api.projects_get(name="ldap_group_test_prj") @@ -110,7 +112,7 @@ class TestAssignRoleToLdapGroup(unittest.TestCase): guest_product_api = testutils.GetProductApi("guest_user", "zhu88jie") projects = guest_product_api.projects_get(name="ldap_group_test_prj") self.assertTrue(projects.count > 1) - self.assertEqual(3, projects[0].current_user_role_id) + self.assertEqual(3, projects[0].current_user_role_id) self.dockerCmdLoginAdmin(username="admin_user", password="zhu88jie") self.dockerCmdLoginDev(username="dev_user", password="zhu88jie") @@ -126,36 +128,36 @@ class TestAssignRoleToLdapGroup(unittest.TestCase): # admin user can push, pull images def dockerCmdLoginAdmin(self, username, password): pprint(self.docker_client.info()) - self.docker_client.login(username=username, password=password, registry=self.harbor_host) + self.docker_client.login(username=username, password=password, registry=self.harbor_host) self.docker_client.images.pull("busybox:latest") image = self.docker_client.images.get("busybox:latest") image.tag(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="latest") - output = self.docker_client.images.push(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="latest") + output = self.docker_client.images.push(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="latest") if output.find("error")>0 : self.fail("Should not fail to push image for admin_user") self.docker_client.images.pull(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="latest") pass # dev user can push, pull images def dockerCmdLoginDev(self, username, password, harbor_server=harbor_host): - self.docker_client.login(username=username, password=password, registry=self.harbor_host) + self.docker_client.login(username=username, password=password, registry=self.harbor_host) self.docker_client.images.pull("busybox:latest") image = self.docker_client.images.get("busybox:latest") image.tag(repository=self.harbor_host+"/ldap_group_test_prj/busyboxdev", tag="latest") - output = self.docker_client.images.push(repository=self.harbor_host+"/ldap_group_test_prj/busyboxdev", tag="latest") + output = self.docker_client.images.push(repository=self.harbor_host+"/ldap_group_test_prj/busyboxdev", tag="latest") if output.find("error") >0 : self.fail("Should not fail to push images for dev_user") pass # guest user can pull images def dockerCmdLoginGuest(self, username, password, harbor_server=harbor_host): - self.docker_client.login(username=username, password=password, registry=self.harbor_host) + self.docker_client.login(username=username, password=password, registry=self.harbor_host) self.docker_client.images.pull("busybox:latest") image = self.docker_client.images.get("busybox:latest") image.tag(repository=self.harbor_host+"/ldap_group_test_prj/busyboxguest", tag="latest") - output = self.docker_client.images.push(repository=self.harbor_host+"1/ldap_group_test_prj/busyboxguest", tag="latest") + output = self.docker_client.images.push(repository=self.harbor_host+"1/ldap_group_test_prj/busyboxguest", tag="latest") if output.find("error")<0 : self.fail("Should failed to push image for guest user") self.docker_client.images.pull(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="latest") - pass + pass # check can see his log in current project def queryUserLogs(self, username, password, harbor_host=harbor_host): client_product_api = testutils.GetProductApi(username=username, password=password) diff --git a/tests/apitests/python/test_assign_sys_admin.py b/tests/apitests/python/test_assign_sys_admin.py index db158a2c1..431a66d63 100644 --- a/tests/apitests/python/test_assign_sys_admin.py +++ b/tests/apitests/python/test_assign_sys_admin.py @@ -10,11 +10,8 @@ from library.configurations import Configurations class TestProjects(unittest.TestCase): @classmethod def setUp(self): - conf = Configurations() - self.conf= conf - - user = User() - self.user= user + self.conf= Configurations() + self.user = User() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_copy_artifact_outside_project.py b/tests/apitests/python/test_copy_artifact_outside_project.py index 83a4a595b..8e10bba85 100644 --- a/tests/apitests/python/test_copy_artifact_outside_project.py +++ b/tests/apitests/python/test_copy_artifact_outside_project.py @@ -18,16 +18,10 @@ from library.repository import pull_harbor_image class TestProjects(unittest.TestCase): @classmethod def setUpClass(self): - project = Project() - self.project= project - - user = User() - self.user= user - - artifact = Artifact(api_type='artifact') - self.artifact= artifact - repo = Repository(api_type='repository') - self.repo= repo + self.project = Project() + self.user = User() + self.artifact = Artifact(api_type='artifact') + self.repo = Repository(api_type='repository') @classmethod def tearDownClass(self): diff --git a/tests/apitests/python/test_del_repo.py b/tests/apitests/python/test_del_repo.py index e1794403b..0676339e5 100644 --- a/tests/apitests/python/test_del_repo.py +++ b/tests/apitests/python/test_del_repo.py @@ -16,14 +16,9 @@ from library.repository import push_image_to_project class TestProjects(unittest.TestCase): @classmethod def setUpClass(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository(api_type='repository') - self.repo= repo + self.project= Project() + self.user= User() + self.repo= Repository(api_type='repository') @classmethod def tearDownClass(self): diff --git a/tests/apitests/python/test_garbage_collection.py b/tests/apitests/python/test_garbage_collection.py index 5961c15ad..1df2b4c55 100644 --- a/tests/apitests/python/test_garbage_collection.py +++ b/tests/apitests/python/test_garbage_collection.py @@ -15,17 +15,10 @@ from library.base import _assert_status_code class TestProjects(unittest.TestCase): @classmethod def setUp(self): - system = System() - self.system= system - - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository(api_type='repository') - self.repo= repo + self.system = System() + self.project = Project() + self.user = User() + self.repo = Repository(api_type='repository') @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_manage_project_member.py b/tests/apitests/python/test_manage_project_member.py index be20b2afa..42af14d9a 100644 --- a/tests/apitests/python/test_manage_project_member.py +++ b/tests/apitests/python/test_manage_project_member.py @@ -13,14 +13,9 @@ from library.repository import Repository class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository(api_type='repository') - self.repo= repo + self.project = Project() + self.user = User() + self.repo = Repository(api_type='repository') @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_project_level_policy_content_trust.py b/tests/apitests/python/test_project_level_policy_content_trust.py index e2c0d74a7..68251cd96 100644 --- a/tests/apitests/python/test_project_level_policy_content_trust.py +++ b/tests/apitests/python/test_project_level_policy_content_trust.py @@ -6,6 +6,7 @@ from testutils import ADMIN_CLIENT from testutils import harbor_server from testutils import TEARDOWN +from library.artifact import Artifact from library.project import Project from library.user import User from library.repository import Repository @@ -15,16 +16,10 @@ from library.repository import pull_harbor_image class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository() - self.repo= repo - repo_v2 = Repository(api_type='repository') - self.repo_v2= repo_v2 + self.project= Project() + self.user= User() + self.artifact= Artifact(api_type='artifact') + self.repo= Repository(api_type='repository') @classmethod def tearDown(self): @@ -33,7 +28,7 @@ class TestProjects(unittest.TestCase): @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA) by user(UA); - self.repo_v2.delete_repoitory(TestProjects.project_content_trust_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_CONTENT_TRUST_CLIENT) + self.repo.delete_repoitory(TestProjects.project_content_trust_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_CONTENT_TRUST_CLIENT) #2. Delete project(PA); self.project.delete_project(TestProjects.project_content_trust_id, **TestProjects.USER_CONTENT_TRUST_CLIENT) @@ -59,6 +54,7 @@ class TestProjects(unittest.TestCase): 3. Delete user(UA); """ url = ADMIN_CLIENT["endpoint"] + image = "hello-world" admin_name = ADMIN_CLIENT["username"] admin_password = ADMIN_CLIENT["password"] user_content_trust_password = "Aa123456" @@ -72,10 +68,11 @@ class TestProjects(unittest.TestCase): TestProjects.project_content_trust_id, TestProjects.project_content_trust_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CONTENT_TRUST_CLIENT) #3. Push a new image(IA) in project(PA) by admin; - TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_content_trust_name, harbor_server, admin_name, admin_password, "hello-world", "latest") + TestProjects.repo_name, tag = push_image_to_project(TestProjects.project_content_trust_name, harbor_server, admin_name, admin_password, image, "latest") #4. Image(IA) should exist; - self.repo.image_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_CONTENT_TRUST_CLIENT) + artifact = self.artifact.get_reference_info(TestProjects.project_content_trust_name, image, tag, **TestProjects.USER_CONTENT_TRUST_CLIENT) + self.assertEqual(artifact[0].tags[0].name, tag) #5. Pull image(IA) successfully; pull_harbor_image(harbor_server, admin_name, admin_password, TestProjects.repo_name, tag) diff --git a/tests/apitests/python/test_project_quota.py b/tests/apitests/python/test_project_quota.py index 6958d75e9..207985afe 100644 --- a/tests/apitests/python/test_project_quota.py +++ b/tests/apitests/python/test_project_quota.py @@ -13,15 +13,9 @@ from library.system import System class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository() - self.repo= repo - + self.project= Project() + self.user= User() + self.repo= Repository() self.system = System() @classmethod diff --git a/tests/apitests/python/test_retention.py b/tests/apitests/python/test_retention.py index eea52ec6f..d67f139c0 100644 --- a/tests/apitests/python/test_retention.py +++ b/tests/apitests/python/test_retention.py @@ -35,9 +35,9 @@ class TestProjects(unittest.TestCase): def setUpClass(self): self.user = User() self.system = System() - self.repo= Repository(api_type='repository') + self.repo = Repository(api_type='repository') self.project = Project() - self.retention=Retention() + self.retention = Retention() def testTagRetention(self): user_ra_password = "Aa123456" diff --git a/tests/apitests/python/test_robot_account.py b/tests/apitests/python/test_robot_account.py index a36b26e45..aca81d93c 100644 --- a/tests/apitests/python/test_robot_account.py +++ b/tests/apitests/python/test_robot_account.py @@ -15,14 +15,9 @@ from library.base import _assert_status_code class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository(api_type='repository') - self.repo= repo + self.project = Project() + self.user = User() + self.repo = Repository(api_type='repository') @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_scan_all_images.py b/tests/apitests/python/test_scan_all_images.py index 7d5bbc2b7..b8cd9e29f 100644 --- a/tests/apitests/python/test_scan_all_images.py +++ b/tests/apitests/python/test_scan_all_images.py @@ -13,17 +13,10 @@ from library.repository import push_image_to_project class TestProjects(unittest.TestCase): @classmethod def setUp(self): - system = System() - self.system= system - - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository() - self.repo= repo + self.system = System() + self.project= Project() + self.user= User() + self.repo= Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_scan_image.py b/tests/apitests/python/test_scan_image.py index 34b2f6844..fe2a09b8c 100644 --- a/tests/apitests/python/test_scan_image.py +++ b/tests/apitests/python/test_scan_image.py @@ -12,14 +12,9 @@ from library.repository import push_image_to_project class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository() - self.repo= repo + self.project= Project() + self.user= User() + self.repo= Repository() @classmethod def tearDown(self): diff --git a/tests/apitests/python/test_sign_image.py b/tests/apitests/python/test_sign_image.py index 72aab4682..879722e01 100644 --- a/tests/apitests/python/test_sign_image.py +++ b/tests/apitests/python/test_sign_image.py @@ -5,6 +5,7 @@ from library.sign import sign_image from testutils import ADMIN_CLIENT from testutils import harbor_server from testutils import TEARDOWN +from library.artifact import Artifact from library.project import Project from library.user import User from library.repository import Repository @@ -13,25 +14,19 @@ from library.repository import push_image_to_project class TestProjects(unittest.TestCase): @classmethod def setUp(self): - project = Project() - self.project= project - - user = User() - self.user= user - - repo = Repository() - self.repo= repo - repo_v2 = Repository(api_type='repository') - self.repo_v2= repo_v2 + self.project = Project() + self.user = User() + self.artifact = Artifact(api_type='artifact') + self.repo = Repository(api_type='repository') @classmethod def tearDown(self): print "Case completed" - @unittest.skipIf(TEARDOWN == True, "Test data won't be erased.") + @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") def test_ClearData(self): #1. Delete repository(RA) by user(UA); - self.repo_v2.delete_repoitory(TestProjects.project_sign_image_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_sign_image_CLIENT) + self.repo.delete_repoitory(TestProjects.project_sign_image_name, TestProjects.repo_name.split('/')[1], **TestProjects.USER_sign_image_CLIENT) #2. Delete project(PA); self.project.delete_project(TestProjects.project_sign_image_id, **TestProjects.USER_sign_image_CLIENT) @@ -60,7 +55,7 @@ class TestProjects(unittest.TestCase): #1. Create user-001 TestProjects.user_sign_image_id, user_sign_image_name = self.user.create_user(user_password = user_001_password, **ADMIN_CLIENT) - TestProjects.USER_sign_image_CLIENT=dict(endpoint = url, username = user_sign_image_name, password = user_001_password) + TestProjects.USER_sign_image_CLIENT=dict(with_signature = True, endpoint = url, username = user_sign_image_name, password = user_001_password) #2. Create a new private project(PA) by user(UA); TestProjects.project_sign_image_id, TestProjects.project_sign_image_name = self.project.create_project(metadata = {"public": "false"}, **ADMIN_CLIENT) @@ -81,7 +76,8 @@ class TestProjects(unittest.TestCase): sign_image(harbor_server, TestProjects.project_sign_image_name, image, tag) #7. Get signature of image with tag(TA), it should be exist. - self.repo.signature_should_exist(TestProjects.repo_name, tag, **TestProjects.USER_sign_image_CLIENT) + artifact = self.artifact.get_reference_info(TestProjects.project_sign_image_name, image, tag, **TestProjects.USER_sign_image_CLIENT) + self.assertEqual(artifact[0].tags[0].signed, True) if __name__ == '__main__': unittest.main() diff --git a/tests/apitests/python/testutils.py b/tests/apitests/python/testutils.py index be3c92e5d..94662d906 100644 --- a/tests/apitests/python/testutils.py +++ b/tests/apitests/python/testutils.py @@ -3,6 +3,7 @@ import os import sys sys.path.insert(0, os.environ["SWAGGER_CLIENT_PATH"]) +import v2_swagger_client from swagger_client.rest import ApiException import swagger_client.models from pprint import pprint @@ -27,6 +28,19 @@ def GetProductApi(username, password, harbor_server= os.environ["HARBOR_HOST"]): api_client = swagger_client.ApiClient(cfg) api_instance = swagger_client.ProductsApi(api_client) return api_instance + +def GetRepositoryApi(username, password, harbor_server= os.environ["HARBOR_HOST"]): + + cfg = v2_swagger_client.Configuration() + cfg.host = "https://"+harbor_server+"/api/v2.0" + cfg.username = username + cfg.password = password + cfg.verify_ssl = False + cfg.debug = True + api_client = v2_swagger_client.ApiClient(cfg) + api_instance = v2_swagger_client.RepositoryApi(api_client) + return api_instance + class TestResult(object): def __init__(self): self.num_errors = 0 diff --git a/tests/robot-cases/Group0-BAT/API_DB.robot b/tests/robot-cases/Group0-BAT/API_DB.robot index 9c9a8029a..071901129 100644 --- a/tests/robot-cases/Group0-BAT/API_DB.robot +++ b/tests/robot-cases/Group0-BAT/API_DB.robot @@ -26,8 +26,8 @@ Test Case - Add Private Project Member and Check User Can See It Harbor API Test ./tests/apitests/python/test_add_member_to_private_project.py Test Case - Delete a Repository of a Certain Project Created by Normal User Harbor API Test ./tests/apitests/python/test_del_repo.py -#Test Case - Add a System Global Label to a Certain Tag -# Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py +Test Case - Add a System Global Label to a Certain Tag + Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py Test Case - Add Replication Rule Harbor API Test ./tests/apitests/python/test_add_replication_rule.py Test Case - Edit Project Creation @@ -35,10 +35,10 @@ Test Case - Edit Project Creation # TODO uncomment this after image scan work with basic auth - #10277 #Test Case - Scan Image # Harbor API Test ./tests/apitests/python/test_scan_image.py -### Test Case - Manage Project Member -### Harbor API Test ./tests/apitests/python/test_manage_project_member.py -### Test Case - Project Level Policy Content Trust -### Harbor API Test ./tests/apitests/python/test_project_level_policy_content_trust.py +Test Case - Manage Project Member + Harbor API Test ./tests/apitests/python/test_manage_project_member.py +Test Case - Project Level Policy Content Trust + Harbor API Test ./tests/apitests/python/test_project_level_policy_content_trust.py # TODO uncomment this after we move the accesslog away from registry notificaiton # TODO potentially #10602 may also fix this. # Test Case - User View Logs @@ -49,23 +49,23 @@ Test Case - Edit Project Creation # TODO uncomment this after bump up chart API version to v2.0 # Test Case - List Helm Charts # Harbor API Test ./tests/apitests/python/test_list_helm_charts.py -### Test Case - Assign Sys Admin -### Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py +Test Case - Assign Sys Admin + Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py Test Case - Copy Artifact Outside Project Harbor API Test ./tests/apitests/python/test_copy_artifact_outside_project.py -### Test Case - Robot Account -### Harbor API Test ./tests/apitests/python/test_robot_account.py -### Test Case - Sign A Image -### Harbor API Test ./tests/apitests/python/test_sign_image.py +Test Case - Robot Account + Harbor API Test ./tests/apitests/python/test_robot_account.py +Test Case - Sign A Image + Harbor API Test ./tests/apitests/python/test_sign_image.py # TODO uncomment this after making quota work with OCI registry # Test Case - Project Quota # Harbor API Test ./tests/apitests/python/test_project_quota.py -### Test Case - System Level CVE Whitelist -### Harbor API Test ./tests/apitests/python/test_sys_cve_whitelists.py -### Test Case - Project Level CVE Whitelist -### Harbor API Test ./tests/apitests/python/test_project_level_cve_whitelist.py -### Test Case - Tag Retention -### Harbor API Test ./tests/apitests/python/test_retention.py -### Test Case - Health Check -### Harbor API Test ./tests/apitests/python/test_health_check.py +Test Case - System Level CVE Whitelist + Harbor API Test ./tests/apitests/python/test_sys_cve_whitelists.py +Test Case - Project Level CVE Whitelist + Harbor API Test ./tests/apitests/python/test_project_level_cve_whitelist.py +Test Case - Tag Retention + Harbor API Test ./tests/apitests/python/test_retention.py +Test Case - Health Check + Harbor API Test ./tests/apitests/python/test_health_check.py