Update existing API tests for API V2.0

Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
danfengliu 2020-02-25 10:40:29 +08:00
parent aa71fc43cf
commit c283a02e5f
19 changed files with 132 additions and 182 deletions

View File

@ -7,7 +7,15 @@ from v2_swagger_client.rest import ApiException
class Artifact(base.Base): class Artifact(base.Base):
def get_reference_info(self, project_name, repo_name, reference, **kwargs): def get_reference_info(self, project_name, repo_name, reference, **kwargs):
client = self._get_client(**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): def copy_artifact(self, project_name, repo_name, _from, expect_status_code = 201, expect_response_body = None, **kwargs):
client = self._get_client(**kwargs) client = self._get_client(**kwargs)

View File

@ -10,12 +10,8 @@ from library.user import User
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
"""UserGroup unit test stubs""" """UserGroup unit test stubs"""
def setUp(self): def setUp(self):
project = Project() self.project = Project()
self.project= project self.user= User()
user = User()
self.user= user
def tearDown(self): def tearDown(self):
pass pass

View File

@ -13,17 +13,10 @@ import swagger_client
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project = Project()
self.project= project self.user = User()
self.replication = Replication()
user = User() self.registry = Registry()
self.user= user
replication = Replication()
self.replication= replication
registry = Registry()
self.registry= registry
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -5,6 +5,7 @@ import unittest
from testutils import harbor_server from testutils import harbor_server
from testutils import TEARDOWN from testutils import TEARDOWN
from testutils import ADMIN_CLIENT from testutils import ADMIN_CLIENT
from library.artifact import Artifact
from library.project import Project from library.project import Project
from library.user import User from library.user import User
from library.repository import Repository from library.repository import Repository
@ -14,19 +15,11 @@ from library.label import Label
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project = Project()
self.project= project self.user = User()
self.artifact = Artifact(api_type='artifact')
user = User() self.repo = Repository(api_type='repository')
self.user= user self.label = Label()
repo = Repository()
self.repo= repo
repo_v2 = Repository(api_type='repository')
self.repo_v2= repo_v2
label = Label()
self.label= label
@classmethod @classmethod
def tearDown(self): def tearDown(self):
@ -35,7 +28,7 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #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); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_add_g_lbl_id, **TestProjects.USER_add_g_lbl_CLIENT) 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) TestProjects.label_id, _ = self.label.create_label(**ADMIN_CLIENT)
#7. Add this system global label to repository(RA)/tag(TA). #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__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -3,10 +3,10 @@
""" """
Harbor API Harbor API
These APIs provide services for manipulating Harbor project. These APIs provide services for manipulating Harbor project.
OpenAPI spec version: 1.4.0 OpenAPI spec version: 1.4.0
Generated by: https://github.com/swagger-api/swagger-codegen.git Generated by: https://github.com/swagger-api/swagger-codegen.git
""" """
@ -21,12 +21,13 @@ import testutils
import docker import docker
import swagger_client import swagger_client
from swagger_client.models.project import Project
from swagger_client.models.project_req import ProjectReq from swagger_client.models.project import Project
from swagger_client.models.project_metadata import ProjectMetadata from swagger_client.models.project_req import ProjectReq
from swagger_client.models.project_member import ProjectMember from swagger_client.models.project_metadata import ProjectMetadata
from swagger_client.models.user_group import UserGroup from swagger_client.models.project_member import ProjectMember
from swagger_client.models.configurations import Configurations from swagger_client.models.user_group import UserGroup
from swagger_client.models.configurations import Configurations
from swagger_client.rest import ApiException from swagger_client.rest import ApiException
@ -38,16 +39,17 @@ class TestAssignRoleToLdapGroup(unittest.TestCase):
harbor_host = os.environ["HARBOR_HOST"] harbor_host = os.environ["HARBOR_HOST"]
"""AssignRoleToLdapGroup unit test stubs""" """AssignRoleToLdapGroup unit test stubs"""
product_api = testutils.GetProductApi("admin", "Harbor12345") product_api = testutils.GetProductApi("admin", "Harbor12345")
repository_api = testutils.GetRepositoryApi("admin", "Harbor12345")
project_id = 0 project_id = 0
docker_client = docker.from_env() docker_client = docker.from_env()
def setUp(self): def setUp(self):
#login with admin, create a project and assign role to ldap group #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)) 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) pprint(result)
cfgs = self.product_api.configurations_get() cfgs = self.product_api.configurations_get()
pprint(cfgs) pprint(cfgs)
req = ProjectReq() req = ProjectReq()
req.project_name = "ldap_group_test_prj" req.project_name = "ldap_group_test_prj"
req.metadata = ProjectMetadata(public="false") req.metadata = ProjectMetadata(public="false")
result = self.product_api.projects_post(req) result = self.product_api.projects_post(req)
@ -57,7 +59,7 @@ class TestAssignRoleToLdapGroup(unittest.TestCase):
if projs.count>0 : if projs.count>0 :
project = projs[0] project = projs[0]
self.project_id = project.project_id self.project_id = project.project_id
# asign role to project with dn # asign role to project with dn
group_dn = "cn=harbor_admin,ou=groups,dc=example,dc=com" group_dn = "cn=harbor_admin,ou=groups,dc=example,dc=com"
projectmember = ProjectMember() projectmember = ProjectMember()
@ -86,9 +88,9 @@ class TestAssignRoleToLdapGroup(unittest.TestCase):
def tearDown(self): def tearDown(self):
#delete images in project #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) 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) pprint(result)
if self.project_id > 0 : if self.project_id > 0 :
self.product_api.projects_project_id_delete(self.project_id) 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") projects = admin_product_api.projects_get(name="ldap_group_test_prj")
self.assertTrue(projects.count > 1) self.assertTrue(projects.count > 1)
self.assertEqual(1, projects[0].current_user_role_id) self.assertEqual(1, projects[0].current_user_role_id)
dev_product_api = testutils.GetProductApi("dev_user", "zhu88jie") dev_product_api = testutils.GetProductApi("dev_user", "zhu88jie")
projects = dev_product_api.projects_get(name="ldap_group_test_prj") 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") guest_product_api = testutils.GetProductApi("guest_user", "zhu88jie")
projects = guest_product_api.projects_get(name="ldap_group_test_prj") projects = guest_product_api.projects_get(name="ldap_group_test_prj")
self.assertTrue(projects.count > 1) 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.dockerCmdLoginAdmin(username="admin_user", password="zhu88jie")
self.dockerCmdLoginDev(username="dev_user", password="zhu88jie") self.dockerCmdLoginDev(username="dev_user", password="zhu88jie")
@ -126,36 +128,36 @@ class TestAssignRoleToLdapGroup(unittest.TestCase):
# admin user can push, pull images # admin user can push, pull images
def dockerCmdLoginAdmin(self, username, password): def dockerCmdLoginAdmin(self, username, password):
pprint(self.docker_client.info()) 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") self.docker_client.images.pull("busybox:latest")
image = self.docker_client.images.get("busybox:latest") image = self.docker_client.images.get("busybox:latest")
image.tag(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="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 : if output.find("error")>0 :
self.fail("Should not fail to push image for admin_user") 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") self.docker_client.images.pull(repository=self.harbor_host+"/ldap_group_test_prj/busybox", tag="latest")
pass pass
# dev user can push, pull images # dev user can push, pull images
def dockerCmdLoginDev(self, username, password, harbor_server=harbor_host): 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") self.docker_client.images.pull("busybox:latest")
image = self.docker_client.images.get("busybox:latest") image = self.docker_client.images.get("busybox:latest")
image.tag(repository=self.harbor_host+"/ldap_group_test_prj/busyboxdev", tag="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 : if output.find("error") >0 :
self.fail("Should not fail to push images for dev_user") self.fail("Should not fail to push images for dev_user")
pass pass
# guest user can pull images # guest user can pull images
def dockerCmdLoginGuest(self, username, password, harbor_server=harbor_host): 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") self.docker_client.images.pull("busybox:latest")
image = self.docker_client.images.get("busybox:latest") image = self.docker_client.images.get("busybox:latest")
image.tag(repository=self.harbor_host+"/ldap_group_test_prj/busyboxguest", tag="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 : if output.find("error")<0 :
self.fail("Should failed to push image for guest user") 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") 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 # check can see his log in current project
def queryUserLogs(self, username, password, harbor_host=harbor_host): def queryUserLogs(self, username, password, harbor_host=harbor_host):
client_product_api = testutils.GetProductApi(username=username, password=password) client_product_api = testutils.GetProductApi(username=username, password=password)

View File

@ -10,11 +10,8 @@ from library.configurations import Configurations
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
conf = Configurations() self.conf= Configurations()
self.conf= conf self.user = User()
user = User()
self.user= user
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -18,16 +18,10 @@ from library.repository import pull_harbor_image
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
project = Project() self.project = Project()
self.project= project self.user = User()
self.artifact = Artifact(api_type='artifact')
user = User() self.repo = Repository(api_type='repository')
self.user= user
artifact = Artifact(api_type='artifact')
self.artifact= artifact
repo = Repository(api_type='repository')
self.repo= repo
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):

View File

@ -16,14 +16,9 @@ from library.repository import push_image_to_project
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
project = Project() self.project= Project()
self.project= project self.user= User()
self.repo= Repository(api_type='repository')
user = User()
self.user= user
repo = Repository(api_type='repository')
self.repo= repo
@classmethod @classmethod
def tearDownClass(self): def tearDownClass(self):

View File

@ -15,17 +15,10 @@ from library.base import _assert_status_code
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
system = System() self.system = System()
self.system= system self.project = Project()
self.user = User()
project = Project() self.repo = Repository(api_type='repository')
self.project= project
user = User()
self.user= user
repo = Repository(api_type='repository')
self.repo= repo
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -13,14 +13,9 @@ from library.repository import Repository
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project = Project()
self.project= project self.user = User()
self.repo = Repository(api_type='repository')
user = User()
self.user= user
repo = Repository(api_type='repository')
self.repo= repo
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -6,6 +6,7 @@ from testutils import ADMIN_CLIENT
from testutils import harbor_server from testutils import harbor_server
from testutils import TEARDOWN from testutils import TEARDOWN
from library.artifact import Artifact
from library.project import Project from library.project import Project
from library.user import User from library.user import User
from library.repository import Repository from library.repository import Repository
@ -15,16 +16,10 @@ from library.repository import pull_harbor_image
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project= Project()
self.project= project self.user= User()
self.artifact= Artifact(api_type='artifact')
user = User() self.repo= Repository(api_type='repository')
self.user= user
repo = Repository()
self.repo= repo
repo_v2 = Repository(api_type='repository')
self.repo_v2= repo_v2
@classmethod @classmethod
def tearDown(self): def tearDown(self):
@ -33,7 +28,7 @@ class TestProjects(unittest.TestCase):
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.") @unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #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); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_content_trust_id, **TestProjects.USER_CONTENT_TRUST_CLIENT) 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); 3. Delete user(UA);
""" """
url = ADMIN_CLIENT["endpoint"] url = ADMIN_CLIENT["endpoint"]
image = "hello-world"
admin_name = ADMIN_CLIENT["username"] admin_name = ADMIN_CLIENT["username"]
admin_password = ADMIN_CLIENT["password"] admin_password = ADMIN_CLIENT["password"]
user_content_trust_password = "Aa123456" 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) 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; #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; #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; #5. Pull image(IA) successfully;
pull_harbor_image(harbor_server, admin_name, admin_password, TestProjects.repo_name, tag) pull_harbor_image(harbor_server, admin_name, admin_password, TestProjects.repo_name, tag)

View File

@ -13,15 +13,9 @@ from library.system import System
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project= Project()
self.project= project self.user= User()
self.repo= Repository()
user = User()
self.user= user
repo = Repository()
self.repo= repo
self.system = System() self.system = System()
@classmethod @classmethod

View File

@ -35,9 +35,9 @@ class TestProjects(unittest.TestCase):
def setUpClass(self): def setUpClass(self):
self.user = User() self.user = User()
self.system = System() self.system = System()
self.repo= Repository(api_type='repository') self.repo = Repository(api_type='repository')
self.project = Project() self.project = Project()
self.retention=Retention() self.retention = Retention()
def testTagRetention(self): def testTagRetention(self):
user_ra_password = "Aa123456" user_ra_password = "Aa123456"

View File

@ -15,14 +15,9 @@ from library.base import _assert_status_code
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project = Project()
self.project= project self.user = User()
self.repo = Repository(api_type='repository')
user = User()
self.user= user
repo = Repository(api_type='repository')
self.repo= repo
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -13,17 +13,10 @@ from library.repository import push_image_to_project
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
system = System() self.system = System()
self.system= system self.project= Project()
self.user= User()
project = Project() self.repo= Repository()
self.project= project
user = User()
self.user= user
repo = Repository()
self.repo= repo
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -12,14 +12,9 @@ from library.repository import push_image_to_project
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project= Project()
self.project= project self.user= User()
self.repo= Repository()
user = User()
self.user= user
repo = Repository()
self.repo= repo
@classmethod @classmethod
def tearDown(self): def tearDown(self):

View File

@ -5,6 +5,7 @@ from library.sign import sign_image
from testutils import ADMIN_CLIENT from testutils import ADMIN_CLIENT
from testutils import harbor_server from testutils import harbor_server
from testutils import TEARDOWN from testutils import TEARDOWN
from library.artifact import Artifact
from library.project import Project from library.project import Project
from library.user import User from library.user import User
from library.repository import Repository from library.repository import Repository
@ -13,25 +14,19 @@ from library.repository import push_image_to_project
class TestProjects(unittest.TestCase): class TestProjects(unittest.TestCase):
@classmethod @classmethod
def setUp(self): def setUp(self):
project = Project() self.project = Project()
self.project= project self.user = User()
self.artifact = Artifact(api_type='artifact')
user = User() self.repo = Repository(api_type='repository')
self.user= user
repo = Repository()
self.repo= repo
repo_v2 = Repository(api_type='repository')
self.repo_v2= repo_v2
@classmethod @classmethod
def tearDown(self): def tearDown(self):
print "Case completed" 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): def test_ClearData(self):
#1. Delete repository(RA) by user(UA); #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); #2. Delete project(PA);
self.project.delete_project(TestProjects.project_sign_image_id, **TestProjects.USER_sign_image_CLIENT) 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 #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_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); #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) 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) sign_image(harbor_server, TestProjects.project_sign_image_name, image, tag)
#7. Get signature of image with tag(TA), it should be exist. #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__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -3,6 +3,7 @@ import os
import sys import sys
sys.path.insert(0, os.environ["SWAGGER_CLIENT_PATH"]) sys.path.insert(0, os.environ["SWAGGER_CLIENT_PATH"])
import v2_swagger_client
from swagger_client.rest import ApiException from swagger_client.rest import ApiException
import swagger_client.models import swagger_client.models
from pprint import pprint 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_client = swagger_client.ApiClient(cfg)
api_instance = swagger_client.ProductsApi(api_client) api_instance = swagger_client.ProductsApi(api_client)
return api_instance 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): class TestResult(object):
def __init__(self): def __init__(self):
self.num_errors = 0 self.num_errors = 0

View File

@ -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 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 Test Case - Delete a Repository of a Certain Project Created by Normal User
Harbor API Test ./tests/apitests/python/test_del_repo.py Harbor API Test ./tests/apitests/python/test_del_repo.py
#Test Case - Add a System Global Label to a Certain Tag Test Case - Add a System Global Label to a Certain Tag
# Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py Harbor API Test ./tests/apitests/python/test_add_sys_label_to_tag.py
Test Case - Add Replication Rule Test Case - Add Replication Rule
Harbor API Test ./tests/apitests/python/test_add_replication_rule.py Harbor API Test ./tests/apitests/python/test_add_replication_rule.py
Test Case - Edit Project Creation 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 # TODO uncomment this after image scan work with basic auth - #10277
#Test Case - Scan Image #Test Case - Scan Image
# Harbor API Test ./tests/apitests/python/test_scan_image.py # Harbor API Test ./tests/apitests/python/test_scan_image.py
### Test Case - Manage Project Member Test Case - Manage Project Member
### Harbor API Test ./tests/apitests/python/test_manage_project_member.py Harbor API Test ./tests/apitests/python/test_manage_project_member.py
### Test Case - Project Level Policy Content Trust Test Case - Project Level Policy Content Trust
### Harbor API Test ./tests/apitests/python/test_project_level_policy_content_trust.py 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 uncomment this after we move the accesslog away from registry notificaiton
# TODO potentially #10602 may also fix this. # TODO potentially #10602 may also fix this.
# Test Case - User View Logs # 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 # TODO uncomment this after bump up chart API version to v2.0
# Test Case - List Helm Charts # Test Case - List Helm Charts
# Harbor API Test ./tests/apitests/python/test_list_helm_charts.py # Harbor API Test ./tests/apitests/python/test_list_helm_charts.py
### Test Case - Assign Sys Admin Test Case - Assign Sys Admin
### Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py Harbor API Test ./tests/apitests/python/test_assign_sys_admin.py
Test Case - Copy Artifact Outside Project Test Case - Copy Artifact Outside Project
Harbor API Test ./tests/apitests/python/test_copy_artifact_outside_project.py Harbor API Test ./tests/apitests/python/test_copy_artifact_outside_project.py
### Test Case - Robot Account Test Case - Robot Account
### Harbor API Test ./tests/apitests/python/test_robot_account.py Harbor API Test ./tests/apitests/python/test_robot_account.py
### Test Case - Sign A Image Test Case - Sign A Image
### Harbor API Test ./tests/apitests/python/test_sign_image.py Harbor API Test ./tests/apitests/python/test_sign_image.py
# TODO uncomment this after making quota work with OCI registry # TODO uncomment this after making quota work with OCI registry
# Test Case - Project Quota # Test Case - Project Quota
# Harbor API Test ./tests/apitests/python/test_project_quota.py # Harbor API Test ./tests/apitests/python/test_project_quota.py
### Test Case - System Level CVE Whitelist Test Case - System Level CVE Whitelist
### Harbor API Test ./tests/apitests/python/test_sys_cve_whitelists.py Harbor API Test ./tests/apitests/python/test_sys_cve_whitelists.py
### Test Case - Project Level CVE Whitelist Test Case - Project Level CVE Whitelist
### Harbor API Test ./tests/apitests/python/test_project_level_cve_whitelist.py Harbor API Test ./tests/apitests/python/test_project_level_cve_whitelist.py
### Test Case - Tag Retention Test Case - Tag Retention
### Harbor API Test ./tests/apitests/python/test_retention.py Harbor API Test ./tests/apitests/python/test_retention.py
### Test Case - Health Check Test Case - Health Check
### Harbor API Test ./tests/apitests/python/test_health_check.py Harbor API Test ./tests/apitests/python/test_health_check.py