2018-11-01 11:26:04 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2018-11-20 07:24:13 +01:00
|
|
|
from testutils import ADMIN_CLIENT
|
2018-11-01 11:26:04 +01:00
|
|
|
from testutils import harbor_server
|
|
|
|
from testutils import TEARDOWN
|
2020-08-09 09:10:00 +02:00
|
|
|
from library.base import _assert_status_code
|
2018-11-01 11:26:04 +01:00
|
|
|
from library.project import Project
|
|
|
|
from library.user import User
|
|
|
|
from library.repository import Repository
|
2018-11-20 07:24:13 +01:00
|
|
|
from library.repository import push_image_to_project
|
2018-11-01 11:26:04 +01:00
|
|
|
|
|
|
|
class TestProjects(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(self):
|
2020-08-09 09:10:00 +02:00
|
|
|
self.project= Project()
|
|
|
|
self.user= User()
|
|
|
|
self.repo= Repository()
|
2018-11-01 11:26:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(self):
|
2020-08-09 09:10:00 +02:00
|
|
|
print("Case completed")
|
2018-11-01 11:26:04 +01:00
|
|
|
|
2018-12-04 05:26:12 +01:00
|
|
|
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
2018-11-01 11:26:04 +01:00
|
|
|
def test_ClearData(self):
|
|
|
|
#1. Delete project(PA);
|
|
|
|
self.project.delete_project(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT)
|
|
|
|
|
|
|
|
#2. Delete user(UA).
|
2018-11-20 07:24:13 +01:00
|
|
|
self.user.delete_user(TestProjects.user_del_repo_id, **ADMIN_CLIENT)
|
2018-11-01 11:26:04 +01:00
|
|
|
|
|
|
|
def testDelRepo(self):
|
|
|
|
"""
|
|
|
|
Test case:
|
|
|
|
Delete a repository
|
2018-12-04 05:26:12 +01:00
|
|
|
Test step and expected result:
|
2018-11-01 11:26:04 +01:00
|
|
|
1. Create a new user(UA);
|
|
|
|
2. Create a new project(PA) by user(UA);
|
|
|
|
3. Create a new repository(RA) in project(PA) by user(UA);
|
|
|
|
4. Get repository in project(PA), there should be one repository which was created by user(UA);
|
|
|
|
5. Delete repository(RA) by user(UA);
|
|
|
|
6. Get repository by user(UA), it should get nothing;
|
|
|
|
Tear down:
|
|
|
|
1. Delete project(PA);
|
|
|
|
2. Delete user(UA).
|
|
|
|
"""
|
2018-11-20 07:24:13 +01:00
|
|
|
url = ADMIN_CLIENT["endpoint"]
|
2018-11-01 11:26:04 +01:00
|
|
|
user_del_repo_password = "Aa123456"
|
|
|
|
|
|
|
|
#1. Create a new user(UA);
|
2018-11-29 11:27:53 +01:00
|
|
|
TestProjects.user_del_repo_id, user_del_repo_name = self.user.create_user(user_password = user_del_repo_password, **ADMIN_CLIENT)
|
2018-11-01 11:26:04 +01:00
|
|
|
|
|
|
|
TestProjects.USER_del_repo_CLIENT=dict(endpoint = url, username = user_del_repo_name, password = user_del_repo_password)
|
|
|
|
|
|
|
|
#2. Create a new project(PA) by user(UA);
|
2018-11-12 16:39:16 +01:00
|
|
|
TestProjects.project_del_repo_id, project_del_repo_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_del_repo_CLIENT)
|
2018-11-01 11:26:04 +01:00
|
|
|
|
|
|
|
#3. Create a new repository(RA) in project(PA) by user(UA);
|
2018-11-20 07:24:13 +01:00
|
|
|
repo_name, _ = push_image_to_project(project_del_repo_name, harbor_server, 'admin', 'Harbor12345', "hello-world", "latest")
|
2018-11-01 11:26:04 +01:00
|
|
|
|
|
|
|
#4. Get repository in project(PA), there should be one repository which was created by user(UA);
|
|
|
|
repo_data = self.repo.get_repository(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT)
|
|
|
|
_assert_status_code(repo_name, repo_data[0].name)
|
|
|
|
|
|
|
|
#5. Delete repository(RA) by user(UA);
|
|
|
|
self.repo.delete_repoitory(repo_name, **TestProjects.USER_del_repo_CLIENT)
|
|
|
|
|
|
|
|
#6. Get repository by user(UA), it should get nothing;
|
|
|
|
repo_data = self.repo.get_repository(TestProjects.project_del_repo_id, **TestProjects.USER_del_repo_CLIENT)
|
|
|
|
_assert_status_code(len(repo_data), 0)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|