harbor/tests/apitests/python/test_ldap_admin_role.py
He Weiwei f309896f2f refactor(api): generate project apis by go-swagger
Signed-off-by: He Weiwei <hweiwei@vmware.com>
2020-08-15 16:10:57 +00:00

74 lines
2.0 KiB
Python

# coding: utf-8
"""
Harbor API
These APIs provide services for manipulating Harbor project.
OpenAPI spec version: 1.4.0
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
from __future__ import absolute_import
import os
import sys
sys.path.append(os.environ["SWAGGER_CLIENT_PATH"])
import unittest
import testutils
import swagger_client
from testutils import TEARDOWN
from library.base import _random_name
from library.project import Project
from swagger_client.models.configurations import Configurations
from pprint import pprint
#Testcase
# Define a LDAP group with harbor admin
class TestLdapAdminRole(unittest.TestCase):
"""AccessLog unit test stubs"""
product_api = testutils.GetProductApi("admin", "Harbor12345")
project_id = 0
def setUp(self):
self.project= Project()
self.mike_product_api = Project("mike", "zhu88jie")
def tearDown(self):
print("Case completed")
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def test_ClearData(self):
if self.project_id > 0 :
self.mike_product_api.delete_project(self.project_id)
def testLdapAdminRole(self):
"""Test LdapAdminRole"""
_project_name = _random_name("test-ldap-admin-role")
result = self.product_api.configurations_put(configurations=Configurations(ldap_group_admin_dn="cn=harbor_users,ou=groups,dc=example,dc=com"))
# Create a private project
result = self.project.create_project(_project_name)
# query project with ldap user mike
projects = self.mike_product_api.get_projects(dict(name=_project_name))
print("=================", projects)
self.assertTrue(len(projects) == 1)
self.project_id = projects[0].project_id
# check the mike is not admin in Database
user_list = self.product_api.users_get(username="mike")
pprint(user_list[0])
self.assertFalse(user_list[0].sysadmin_flag)
pass
if __name__ == '__main__':
unittest.main()