2018-12-03 10:05:06 +01:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2020-03-31 06:35:03 +02:00
|
|
|
from testutils import ADMIN_CLIENT, CHART_API_CLIENT
|
2018-12-03 10:05:06 +01:00
|
|
|
from testutils import TEARDOWN
|
2020-09-08 14:09:54 +02:00
|
|
|
import base
|
2018-12-03 10:05:06 +01:00
|
|
|
from library.user import User
|
|
|
|
from library.project import Project
|
|
|
|
from library.chart import Chart
|
|
|
|
|
|
|
|
class TestProjects(unittest.TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUp(self):
|
2020-06-16 11:34:30 +02:00
|
|
|
self.chart= Chart()
|
|
|
|
self.project= Project()
|
|
|
|
self.user= User()
|
2018-12-03 10:05:06 +01:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDown(self):
|
2020-07-30 10:04:14 +02:00
|
|
|
print("Case completed")
|
2018-12-03 10:05:06 +01:00
|
|
|
|
|
|
|
@unittest.skipIf(TEARDOWN == False, "Test data won't be erased.")
|
|
|
|
def test_ClearData(self):
|
|
|
|
#1. Delete chart file;
|
2020-03-31 06:35:03 +02:00
|
|
|
self.chart.delete_chart_with_version(TestProjects.project_chart_name, TestProjects.CHART_NAME, TestProjects.VERSION, **CHART_API_CLIENT)
|
2018-12-03 10:05:06 +01:00
|
|
|
|
|
|
|
#2. Delete project(PA);
|
|
|
|
self.project.delete_project(TestProjects.project_chart_id, **TestProjects.USER_CHART_CLIENT)
|
|
|
|
|
|
|
|
#3. Delete user(UA);
|
|
|
|
self.user.delete_user(TestProjects.user_chart_id, **ADMIN_CLIENT)
|
|
|
|
|
|
|
|
def testListHelmCharts(self):
|
|
|
|
"""
|
|
|
|
Test case:
|
|
|
|
List Helm Charts
|
|
|
|
Test step and expected result:
|
|
|
|
1. Create a new user(UA);
|
|
|
|
2. Create a new project(PA) by user(UA);
|
|
|
|
3. Upload a chart file to project(PA);
|
|
|
|
4. Chart file should be exist in project(PA).
|
|
|
|
Tear down:
|
|
|
|
1. Delete chart file;
|
|
|
|
2. Delete project(PA);
|
|
|
|
3. Delete user(UA).
|
|
|
|
"""
|
|
|
|
url = ADMIN_CLIENT["endpoint"]
|
2020-03-31 06:35:03 +02:00
|
|
|
chart_api_url = CHART_API_CLIENT['endpoint']
|
|
|
|
user_chart_password = 'Aa123456'
|
2018-12-03 10:05:06 +01:00
|
|
|
TestProjects.CHART_NAME = 'mariadb'
|
|
|
|
TestProjects.VERSION = '4.3.1'
|
|
|
|
|
2020-09-08 14:09:54 +02:00
|
|
|
base.run_command( ["curl", r"-o", "./tests/apitests/python/mariadb-4.3.1.tgz", "https://storage.googleapis.com/harbor-builds/bin/charts/mariadb-4.3.1.tgz"])
|
2018-12-03 10:05:06 +01:00
|
|
|
#1. Create a new user(UA);
|
|
|
|
TestProjects.user_chart_id, user_chart_name = self.user.create_user(user_password = user_chart_password, **ADMIN_CLIENT)
|
|
|
|
|
|
|
|
TestProjects.USER_CHART_CLIENT=dict(endpoint = url, username = user_chart_name, password = user_chart_password)
|
|
|
|
|
2020-03-31 06:35:03 +02:00
|
|
|
TestProjects.API_CHART_CLIENT=dict(endpoint = chart_api_url, username = user_chart_name, password = user_chart_password)
|
|
|
|
|
2018-12-03 10:05:06 +01:00
|
|
|
#2. Create a new project(PA) by user(UA);
|
|
|
|
TestProjects.project_chart_id, TestProjects.project_chart_name = self.project.create_project(metadata = {"public": "false"}, **TestProjects.USER_CHART_CLIENT)
|
|
|
|
|
|
|
|
#3. Upload a chart file to project(PA);
|
2020-03-31 06:35:03 +02:00
|
|
|
self.chart.upload_chart(TestProjects.project_chart_name, r'./tests/apitests/python/mariadb-{}.tgz'.format(TestProjects.VERSION), **TestProjects.API_CHART_CLIENT)
|
2018-12-03 10:05:06 +01:00
|
|
|
|
|
|
|
#4. Chart file should be exist in project(PA).
|
2020-03-31 06:35:03 +02:00
|
|
|
self.chart.chart_should_exist(TestProjects.project_chart_name, TestProjects.CHART_NAME, **TestProjects.API_CHART_CLIENT)
|
2018-12-03 10:05:06 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|