2019-09-11 07:34:23 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import unittest
|
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
from testutils import harbor_server, created_project, created_user
|
2019-09-11 07:34:23 +02:00
|
|
|
from testutils import ADMIN_CLIENT
|
|
|
|
from library.repository import Repository
|
|
|
|
from library.repository import push_image_to_project
|
|
|
|
from library.system import System
|
|
|
|
|
|
|
|
class TestProjects(unittest.TestCase):
|
|
|
|
@classmethod
|
2020-03-12 04:50:30 +01:00
|
|
|
def setUp(cls):
|
2020-03-16 03:13:28 +01:00
|
|
|
cls.repo = Repository()
|
2020-03-12 04:50:30 +01:00
|
|
|
cls.system = System()
|
2019-09-11 07:34:23 +02:00
|
|
|
|
|
|
|
@classmethod
|
2020-03-12 04:50:30 +01:00
|
|
|
def tearDown(cls):
|
2019-09-11 07:34:23 +02:00
|
|
|
print "Case completed"
|
|
|
|
|
|
|
|
def testProjectQuota(self):
|
|
|
|
"""
|
|
|
|
Test case:
|
|
|
|
Project Quota
|
|
|
|
Test step and expected result:
|
|
|
|
1. Create a new user(UA);
|
|
|
|
2. Create a new private project(PA) by user(UA);
|
|
|
|
3. Add user(UA) as a member of project(PA) with project-admin role;
|
|
|
|
4. Push an image to project(PA) by user(UA), then check the project quota usage;
|
|
|
|
5. Check quota change
|
2020-03-12 04:50:30 +01:00
|
|
|
6. Push the image with another tag to project(PA) by user(UA)
|
|
|
|
7. Check quota not changed
|
|
|
|
8. Delete repository(RA) by user(UA);
|
|
|
|
9. Delete image, the quota should be changed to 0.
|
2019-09-11 07:34:23 +02:00
|
|
|
Tear down:
|
|
|
|
1. Delete repository(RA) by user(UA);
|
|
|
|
2. Delete project(PA);
|
|
|
|
3. Delete user(UA);
|
|
|
|
"""
|
|
|
|
user_001_password = "Aa123456"
|
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#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 project-admin role;
|
|
|
|
with created_project(metadata={"public": "false"}, user_id=user_id) as (project_id, project_name):
|
|
|
|
#4. Push an image to project(PA) by user(UA), then check the project quota usage; -- {"count": 1, "storage": 2791709}
|
|
|
|
image, tag = "goharbor/alpine", "3.10"
|
|
|
|
push_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#5. Get project quota
|
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
|
|
|
self.assertEqual(quota[0].used["storage"], 2789002)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#6. Push the image with another tag to project(PA) by user(UA), the check the project quota usage; -- {"count": 1, "storage": 2791709}
|
|
|
|
push_image_to_project(project_name, harbor_server, user_name, user_001_password, image, tag)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#7. Get project quota
|
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
|
|
|
self.assertEqual(quota[0].used["storage"], 2789002)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#8. Delete repository(RA) by user(UA);
|
2020-04-07 11:06:26 +02:00
|
|
|
self.repo.delete_repoitory(project_name, "goharbor%2Falpine", **ADMIN_CLIENT)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
2020-03-12 04:50:30 +01:00
|
|
|
#9. Quota should be 0
|
|
|
|
quota = self.system.get_project_quota("project", project_id, **ADMIN_CLIENT)
|
|
|
|
self.assertEqual(quota[0].used["storage"], 0)
|
2019-09-11 07:34:23 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|