mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-24 03:05:39 +01:00
Merge pull request #11091 from ywk253100/200316_test
Add create/delete tag API test case
This commit is contained in:
commit
01ec93856b
@ -10,6 +10,8 @@ class Artifact(base.Base):
|
||||
params = {}
|
||||
if "with_signature" in kwargs:
|
||||
params["with_signature"] = kwargs["with_signature"]
|
||||
if "with_tag" in kwargs:
|
||||
params["with_tag"] = kwargs["with_tag"]
|
||||
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):
|
||||
@ -31,3 +33,14 @@ class Artifact(base.Base):
|
||||
base._assert_status_code(expect_status_code, status_code)
|
||||
base._assert_status_code(201, status_code)
|
||||
return data
|
||||
|
||||
def create_tag(self, project_name, repo_name, reference, tag_name, expect_status_code = 201, **kwargs):
|
||||
client = self._get_client(**kwargs)
|
||||
tag = v2_swagger_client.Tag(name = tag_name)
|
||||
_, status_code, _ = client.create_tag_with_http_info(project_name, repo_name, reference, tag)
|
||||
base._assert_status_code(expect_status_code, status_code)
|
||||
|
||||
def delete_tag(self, project_name, repo_name, reference, tag_name, expect_status_code = 200, **kwargs):
|
||||
client = self._get_client(**kwargs)
|
||||
_, status_code, _ = client.delete_tag_with_http_info(project_name, repo_name, reference, tag_name)
|
||||
base._assert_status_code(expect_status_code, status_code)
|
||||
|
99
tests/apitests/python/test_create_delete_tag.py
Normal file
99
tests/apitests/python/test_create_delete_tag.py
Normal file
@ -0,0 +1,99 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
import library.repository
|
||||
import library.docker_api
|
||||
from library.base import _assert_status_code
|
||||
from testutils import ADMIN_CLIENT
|
||||
from testutils import harbor_server
|
||||
|
||||
from testutils import TEARDOWN
|
||||
from library.project import Project
|
||||
from library.user import User
|
||||
from library.repository import Repository
|
||||
from library.artifact import Artifact
|
||||
from library.repository import push_image_to_project
|
||||
from library.repository import pull_harbor_image
|
||||
|
||||
class TestProjects(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(self):
|
||||
self.project= Project()
|
||||
self.user= User()
|
||||
self.artifact = Artifact(api_type='artifact')
|
||||
self.repo= Repository(api_type='repository')
|
||||
self.url = ADMIN_CLIENT["endpoint"]
|
||||
self.user_password = "Aa123456"
|
||||
self.repo_name = "hello-world"
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(self):
|
||||
print "Case completed"
|
||||
|
||||
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
||||
def test_ClearData(self):
|
||||
#1. Delete repository(RA,IA) by user(UA);
|
||||
self.repo.delete_repoitory(TestProjects.project_name, self.repo_name, **TestProjects.USER_CLIENT)
|
||||
|
||||
#2. Delete project(PA);
|
||||
self.project.delete_project(TestProjects.project_id, **TestProjects.USER_CLIENT)
|
||||
|
||||
#3. Delete user(UA).
|
||||
self.user.delete_user(TestProjects.user_id, **ADMIN_CLIENT)
|
||||
|
||||
def testCreateDeleteTag(self):
|
||||
"""
|
||||
Test case:
|
||||
Create/Delete tag
|
||||
Test step and expected result:
|
||||
1. Create a new user(UA);
|
||||
2. Create a new project(PA) by user(UA);
|
||||
3. Push an image(IA) to Harbor by docker successfully;
|
||||
4. Create a tag(1.0) for the image(IA);
|
||||
5. Get the image(latest) from Harbor successfully;
|
||||
6. Verify the image(IA) contains tag named 1.0;
|
||||
7. Delete the tag(1.0) from image(IA);
|
||||
8. Get the image(IA) from Harbor successfully;
|
||||
9. Verify the image(IA) contains no tag named 1.0;
|
||||
Tear down:
|
||||
1. Delete repository(RA,IA) by user(UA);
|
||||
2. Delete project(PA);
|
||||
3. Delete user(UA).
|
||||
"""
|
||||
#1. Create a new user(UA);
|
||||
TestProjects.user_id, user_name = self.user.create_user(user_password = self.user_password, **ADMIN_CLIENT)
|
||||
|
||||
TestProjects.USER_CLIENT=dict(with_tag = True, endpoint = self.url, username = user_name, password = self.user_password)
|
||||
|
||||
#2. Create a new project(PA) by user(UA);
|
||||
TestProjects.project_id, TestProjects.project_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CLIENT)
|
||||
|
||||
#3. Push an image(IA) to Harbor by docker successfully;
|
||||
repo_name, tag = push_image_to_project(TestProjects.project_name, harbor_server, 'admin', 'Harbor12345', self.repo_name, "latest")
|
||||
|
||||
#4. Create a tag(1.0) for the image(IA)
|
||||
self.artifact.create_tag(TestProjects.project_name, self.repo_name, tag, "1.0",**TestProjects.USER_CLIENT)
|
||||
|
||||
#5. Get the image(IA) from Harbor successfully;
|
||||
artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, tag, **TestProjects.USER_CLIENT)
|
||||
|
||||
#6. Verify the image(IA) contains tag named 1.0;
|
||||
self.assertEqual(artifact[0].tags[0].name, tag)
|
||||
self.assertEqual(artifact[0].tags[1].name, "1.0")
|
||||
|
||||
#7. Delete the tag(1.0) from image(IA);
|
||||
self.artifact.delete_tag(TestProjects.project_name, self.repo_name, tag, "1.0",**TestProjects.USER_CLIENT)
|
||||
|
||||
#8. Get the image(latest) from Harbor successfully;
|
||||
artifact = self.artifact.get_reference_info(TestProjects.project_name, self.repo_name, tag, **TestProjects.USER_CLIENT)
|
||||
|
||||
#9. Verify the image(IA) contains no tag named 1.0;
|
||||
self.assertEqual(artifact[0].tags[0].name, tag)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -16,10 +16,7 @@ ${SERVER_URL} https://${SERVER}
|
||||
${SERVER_API_ENDPOINT} ${SERVER_URL}/api
|
||||
&{SERVER_CONFIG} endpoint=${SERVER_API_ENDPOINT} verify_ssl=False
|
||||
|
||||
# TODO the cases commented by "###" can be uncommented after implementing the repository python library based on new API
|
||||
|
||||
*** Test Cases ***
|
||||
# TODO uncomment this after re-implement the case
|
||||
Test Case - Garbage Collection
|
||||
Harbor API Test ./tests/apitests/python/test_garbage_collection.py
|
||||
Test Case - Add Private Project Member and Check User Can See It
|
||||
@ -73,4 +70,6 @@ Test Case - Push Index By Docker Manifest
|
||||
Harbor API Test ./tests/apitests/python/test_push_chart_by_helm3_chart_cli.py
|
||||
Test Case - Push Cnab Bundle
|
||||
Harbor API Test ./tests/apitests/python/test_push_cnab_bundle.py
|
||||
Test Case - Create/Delete tag
|
||||
Harbor API Test ./tests/apitests/python/test_create_delete_tag.py
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user