2018-08-01 00:38:23 +02:00
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
"""
|
|
|
|
Harbor API
|
|
|
|
|
2020-08-17 08:51:18 +02:00
|
|
|
These APIs provide services for manipulating Harbor project.
|
2018-08-01 00:38:23 +02:00
|
|
|
|
|
|
|
OpenAPI spec version: 1.4.0
|
2020-08-17 08:51:18 +02:00
|
|
|
|
2018-08-01 00:38:23 +02:00
|
|
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
2021-03-11 13:25:51 +01:00
|
|
|
|
2018-08-01 00:38:23 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2021-03-11 13:25:51 +01:00
|
|
|
|
2018-08-01 00:38:23 +02:00
|
|
|
sys.path.append(os.environ["SWAGGER_CLIENT_PATH"])
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import testutils
|
2021-03-11 13:25:51 +01:00
|
|
|
from testutils import ADMIN_CLIENT
|
2018-08-01 00:38:23 +02:00
|
|
|
|
2021-05-06 04:55:33 +02:00
|
|
|
from v2_swagger_client.models.user_group import UserGroup
|
2021-03-11 13:25:51 +01:00
|
|
|
from library.configurations import Configurations
|
2018-08-01 00:38:23 +02:00
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
#Testcase
|
|
|
|
#12-01-LDAP-usergroup-add
|
|
|
|
#12-02-LDAP-usergroup-update
|
|
|
|
#12-03-LDAP-usergroup-delete
|
|
|
|
|
|
|
|
class TestUserGroup(unittest.TestCase):
|
|
|
|
"""UserGroup unit test stubs"""
|
|
|
|
product_api = testutils.GetProductApi("admin", "Harbor12345")
|
2021-03-30 07:53:42 +02:00
|
|
|
usergroup_api = testutils.GetUserGroupApi("admin", "Harbor12345")
|
2018-08-01 00:38:23 +02:00
|
|
|
groupId = 0
|
|
|
|
def setUp(self):
|
2021-03-11 13:25:51 +01:00
|
|
|
self.conf= Configurations()
|
|
|
|
self.conf.set_configurations_of_ldap(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, **ADMIN_CLIENT)
|
2018-08-01 00:38:23 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if self.groupId > 0 :
|
2021-03-30 07:53:42 +02:00
|
|
|
self.usergroup_api.delete_user_group(group_id=self.groupId)
|
2018-08-01 00:38:23 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def testAddUpdateUserGroup(self):
|
|
|
|
"""Test UserGroup"""
|
|
|
|
user_group = UserGroup(group_name="harbor_group123", group_type=1, ldap_group_dn="cn=harbor_group,ou=groups,dc=example,dc=com")
|
2021-03-30 07:53:42 +02:00
|
|
|
result = self.usergroup_api.create_user_group(usergroup=user_group)
|
2018-08-01 00:38:23 +02:00
|
|
|
pprint(result)
|
2020-08-17 08:51:18 +02:00
|
|
|
|
2021-03-30 07:53:42 +02:00
|
|
|
user_groups = self.usergroup_api.list_user_groups()
|
2018-08-01 00:38:23 +02:00
|
|
|
found = False
|
2020-08-17 08:51:18 +02:00
|
|
|
|
2018-08-01 00:38:23 +02:00
|
|
|
for ug in user_groups :
|
|
|
|
if ug.group_name == "harbor_group123" :
|
|
|
|
found = True
|
|
|
|
print("Found usergroup")
|
|
|
|
pprint(ug)
|
|
|
|
self.groupId = ug.id
|
|
|
|
self.assertTrue(found)
|
|
|
|
|
2021-03-30 07:53:42 +02:00
|
|
|
result = self.usergroup_api.update_user_group(self.groupId, usergroup = UserGroup(group_name = "newharbor_group"))
|
2018-08-01 00:38:23 +02:00
|
|
|
|
2021-03-30 07:53:42 +02:00
|
|
|
new_user_group = self.usergroup_api.get_user_group(group_id=self.groupId)
|
2018-08-01 00:38:23 +02:00
|
|
|
self.assertEqual("newharbor_group", new_user_group.group_name)
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|