2018-11-06 11:27:58 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import unittest
|
|
|
|
|
2020-11-04 03:13:12 +01:00
|
|
|
from testutils import ADMIN_CLIENT, suppress_urllib3_warning
|
2019-08-08 10:16:02 +02:00
|
|
|
from testutils import harbor_server
|
2018-11-06 11:27:58 +01:00
|
|
|
from testutils import TEARDOWN
|
|
|
|
from library.project import Project
|
|
|
|
from library.user import User
|
|
|
|
from library.replication import Replication
|
2019-08-08 10:16:02 +02:00
|
|
|
from library.registry import Registry
|
2021-03-31 09:49:23 +02:00
|
|
|
import v2_swagger_client
|
2018-11-06 11:27:58 +01:00
|
|
|
|
|
|
|
class TestProjects(unittest.TestCase):
|
2020-11-04 03:13:12 +01:00
|
|
|
@suppress_urllib3_warning
|
2018-11-06 11:27:58 +01:00
|
|
|
def setUp(self):
|
2020-02-25 03:40:29 +01:00
|
|
|
self.project = Project()
|
|
|
|
self.user = User()
|
|
|
|
self.replication = Replication()
|
|
|
|
self.registry = Registry()
|
2018-11-06 11:27:58 +01:00
|
|
|
|
2018-12-04 05:26:12 +01:00
|
|
|
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
2020-11-04 03:13:12 +01:00
|
|
|
def tearDown(self):
|
2018-11-06 11:27:58 +01:00
|
|
|
#1. Delete rule(RA);
|
2019-08-08 10:16:02 +02:00
|
|
|
self.replication.delete_replication_rule(TestProjects.rule_id, **ADMIN_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
2019-08-08 10:16:02 +02:00
|
|
|
#2. Delete registry(TA);
|
|
|
|
self.registry.delete_registry(TestProjects.registry_id, **ADMIN_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
|
|
|
#3. Delete project(PA);
|
|
|
|
self.project.delete_project(TestProjects.project_add_rule_id, **TestProjects.USER_add_rule_CLIENT)
|
|
|
|
|
|
|
|
#4. Delete user(UA);
|
2018-11-20 07:24:13 +01:00
|
|
|
self.user.delete_user(TestProjects.user_add_rule_id, **ADMIN_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
2018-11-30 06:32:20 +01:00
|
|
|
def testAddReplicationRule(self):
|
2018-11-06 11:27:58 +01:00
|
|
|
"""
|
|
|
|
Test case:
|
2018-11-12 16:39:16 +01:00
|
|
|
Add Replication Rule
|
2018-12-04 05:26:12 +01:00
|
|
|
Test step and expected result:
|
2018-11-06 11:27:58 +01:00
|
|
|
1. Create a new user(UA);
|
|
|
|
2. Create a new private project(PA) by user(UA);
|
2019-08-08 10:16:02 +02:00
|
|
|
3. Create a new registry;
|
|
|
|
4. Create a new rule for this registry;
|
|
|
|
5. Check rule should be exist.
|
2018-11-06 11:27:58 +01:00
|
|
|
Tear down:
|
|
|
|
1. Delete rule(RA);
|
2019-08-08 10:16:02 +02:00
|
|
|
2. Delete registry(TA);
|
2018-11-06 11:27:58 +01:00
|
|
|
3. Delete project(PA);
|
|
|
|
4. Delete user(UA).
|
|
|
|
"""
|
2018-11-20 07:24:13 +01:00
|
|
|
url = ADMIN_CLIENT["endpoint"]
|
2018-11-06 11:27:58 +01:00
|
|
|
user_add_rule_password = "Aa123456"
|
|
|
|
|
|
|
|
#1. Create user(UA)
|
2018-11-29 11:27:53 +01:00
|
|
|
TestProjects.user_add_rule_id, user_add_rule_name = self.user.create_user(user_password = user_add_rule_password, **ADMIN_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
|
|
|
TestProjects.USER_add_rule_CLIENT=dict(endpoint = url, username = user_add_rule_name, password = user_add_rule_password)
|
|
|
|
|
|
|
|
#2.1. Create private project(PA) by user(UA)
|
2018-11-12 16:39:16 +01:00
|
|
|
TestProjects.project_add_rule_id, _ = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_add_rule_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
|
|
|
#2.2. Get private project of uesr-001, uesr-001 can see only one private project which is project-001
|
|
|
|
self.project.projects_should_exist(dict(public=False), expected_count = 1,
|
|
|
|
expected_project_id = TestProjects.project_add_rule_id, **TestProjects.USER_add_rule_CLIENT)
|
|
|
|
|
2019-08-08 10:16:02 +02:00
|
|
|
#3. Create a new registry
|
|
|
|
TestProjects.registry_id, _ = self.registry.create_registry("https://" + harbor_server,**ADMIN_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
2019-08-08 10:16:02 +02:00
|
|
|
#4. Create a new rule for this registry;
|
2021-03-31 09:49:23 +02:00
|
|
|
TestProjects.rule_id, rule_name = self.replication.create_replication_policy(dest_registry=v2_swagger_client.Registry(id=int(TestProjects.registry_id)), **ADMIN_CLIENT)
|
2018-11-06 11:27:58 +01:00
|
|
|
|
2019-08-08 10:16:02 +02:00
|
|
|
#5. Check rule should be exist
|
|
|
|
self.replication.check_replication_rule_should_exist(TestProjects.rule_id, rule_name, **ADMIN_CLIENT)
|
2018-11-07 03:34:24 +01:00
|
|
|
|
2018-11-06 11:27:58 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|