Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tc for limited guest of a project to get repository #20311

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ src/server/v2.0/models/
src/server/v2.0/restapi/
.editorconfig

harborclient/
openapi-generator-cli.jar
62 changes: 62 additions & 0 deletions tests/apitests/python/test_user_limited_guest_get_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import absolute_import
import unittest


from testutils import ADMIN_CLIENT, suppress_urllib3_warning
from testutils import harbor_server
from testutils import admin_user
from testutils import admin_pwd
from testutils import created_project
from testutils import created_user
from testutils import TEARDOWN
from library.repository import push_self_build_image_to_project
from library.repository import Repository


class TestLimitedGuestGetRepository(unittest.TestCase):


@suppress_urllib3_warning
def setUp(self):
self.repository = Repository()

@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
def tearDown(self):
print("Case completed")

def testLimitedGuestGetRepository(self):
"""
Test case:
Limited Guest GetRepository
Test step and expected result:
1. Create a new user(UA)
2. Create a private project(PA)
3. Add (UA) as "Limited Guest" to this (PA)
4. Push an image to project(PA)
5. Call the "GetRepository" API, it should return 200 status code and project_id should be as expected, and the name should be "ProjectName/ImageName"
6. Delete repository(RA)
"""
url = ADMIN_CLIENT["endpoint"]
user_001_password = "Aa123456"
# 1. Create a new user(UA)
with created_user(user_001_password) as (user_id, user_name):
#2. Create a new private project(PA) by user(UA);
#3. Add user(UA) as a member of project(PA) with "Limited Guest" role;
with created_project(metadata={"public": "false"}, user_id=user_id, member_role_id=5) as (project_id, project_name):
#4. Push an image to project(PA) by user(UA), then check the project quota usage;
image, tag = "goharbor/alpine", "3.10"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can define these variables in setUp.

push_self_build_image_to_project(project_name, harbor_server, admin_user, admin_pwd, image, tag)

#5. Call the "GetRepository" API, it should return 200 status code and the "name" attribute is "ProjectName/ImageName"
USER_CLIENT=dict(endpoint=url, username=user_name, password=user_001_password)
repository_data = self.repository.get_repository(project_name, "goharbor%2Falpine", **USER_CLIENT)
self.assertEqual(repository_data.project_id, project_id)
self.assertEqual(repository_data.name, project_name + "/" + image)

#6. Delete repository(RA)
self.repository.delete_repository(project_name, "goharbor%2Falpine", **ADMIN_CLIENT)
Comment on lines +56 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this step should be in tearDown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has to be within the with created_project, otherwise with created_project cannot delete the project itself because there is repository within the project to be deleted.



if __name__ == '__main__':
unittest.main()

4 changes: 4 additions & 0 deletions tests/robot-cases/Group0-BAT/API_DB.robot
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,7 @@ Test Case - Banner Message
Test Case - User CRUD
[Tags] user_crud
Harbor API Test ./tests/apitests/python/test_user_crud.py

Test Case - Limited Guest GetRepository
[Tags] limited_guest_getrepository
Harbor API Test ./tests/apitests/python/test_user_limited_guest_get_repository.py
Loading