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

Update the script for tag-retention APIs test case #19676

Closed
Closed
Changes from all commits
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
50 changes: 24 additions & 26 deletions tests/apitests/python/test_project_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import urllib3
import os

admin_name = os.environ.get("ADMIN_NAME")
admin_name = os.environ.get("ADMIN_USER_NAME")
admin_password = os.environ.get("ADMIN_PASSWORD")
user_name = os.environ.get("USER_NAME")
password = os.environ.get("PASSWORD")
Expand Down Expand Up @@ -256,47 +256,45 @@ def call(self):
}
}


def get_retention_id() -> str:
# create retention rule fist
retention_id = None
if resource == "tag-retention":
# create retention rule first
# this request can be failed(retention rule existed) or succeeded, but we can finally get the retention id
requests.request("POST", "{}/retentions".format(harbor_base_url),
data=json.dumps(tag_retention_rule_payload), verify=False,
auth=(admin_name, admin_password), headers={"Content-Type": "application/json"})
response1 = requests.request("GET", "{}/projects/{}/metadatas/retention_id".format(harbor_base_url, project_id),
data=None, verify=False,
auth=(admin_name, admin_password), headers={"Content-Type": "application/json"})
retention_id = project_id
if "retention_id" in json.loads(response1.text):
retention_id = json.loads(response1.text)["retention_id"]
return retention_id


# because get_retention_id() has been called, so the expected status code is 400
create_tag_retention_rule = Permission("{}/retentions".format(harbor_base_url), "POST",
data=json.dumps(tag_retention_rule_payload), verify=False,
auth=(admin_name, admin_password), headers={"Content-Type": "application/json"})
get_retention_response = requests.request("GET", "{}/projects/{}/metadatas/retention_id".format(harbor_base_url,project_id),
verify=False,
auth=(admin_name, admin_password))
if "retention_id" in json.loads(get_retention_response.text):
retention_id = json.loads(get_retention_response.text)["retention_id"]
# because the retention rule exists, so the expected status code is 400
create_tag_retention_rule = Permission("{}/retentions".format(harbor_base_url, retention_id), "POST",
400,
tag_retention_rule_payload)

update_retention_payload = copy.deepcopy(tag_retention_rule_payload)
update_retention_payload["rules"][0]["disabled"] = True
read_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, get_retention_id()), "GET", 200)
update_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, get_retention_id()), "PUT", 200,
read_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, retention_id), "GET", 200)
update_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, retention_id), "PUT", 200,
update_retention_payload)
delete_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, get_retention_id()), "DELETE", 200)
execute_tag_retention = Permission("{}/retentions/{}/executions".format(harbor_base_url, get_retention_id()), "POST",
delete_tag_retention = Permission("{}/retentions/{}".format(harbor_base_url, retention_id), "DELETE", 200)
execute_tag_retention = Permission("{}/retentions/{}/executions".format(harbor_base_url, retention_id), "POST",
201)
list_tag_retention_execution = Permission("{}/retentions/{}/executions".format(harbor_base_url, get_retention_id()),
list_tag_retention_execution = Permission("{}/retentions/{}/executions".format(harbor_base_url, retention_id),
"GET",
200)
stop_tag_retention = Permission("{}/retentions/{}/executions/0".format(harbor_base_url, get_retention_id()), "PATCH",
stop_tag_retention = Permission("{}/retentions/{}/executions/0".format(harbor_base_url, retention_id), "PATCH",
404,
{"action": "stop"})
list_tag_retention_tasks = Permission("{}/retentions/{}/executions/0/tasks".format(harbor_base_url, get_retention_id()),
"GET", 404)
list_tag_retention_tasks = Permission(
"{}/retentions/{}/executions/0/tasks".format(harbor_base_url, retention_id),
"GET", 404)
read_tag_retention_tasks = Permission(
"{}/retentions/{}/executions/0/tasks/0".format(harbor_base_url, get_retention_id()),
"{}/retentions/{}/executions/0/tasks/0".format(harbor_base_url, retention_id),
"GET", 404)


# 15. Resource log actions: ['list']
list_log = Permission("{}/projects/{}/logs".format(harbor_base_url, project_name), "GET", 200)

Expand Down
Loading