Skip to content
Snippets Groups Projects

Draft: Tests for non-purge delete

Open I. Nüske requested to merge f-delete-tests into main
2 unresolved threads
4 files
+ 9
30
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -9,12 +9,13 @@ import requests
import fdo_manager_service_api_client.types as client_types
from fdo_manager_service_api_client import Client
from fdo_manager_service_api_client.api.fd_os import base_delete
from fdo_manager_service_api_client.api.fd_os import delete
from fdo_manager_service_api_client.api.repositories import list_repositories
from ..service_index import services_to_test_changes as services
from ..test_utils.utils import created_fdos, purged_fdos, root_dir
from ..test_utils.utils import root_dir
from ..test_utils.assertions import check_timeout
from ..test_utils import management_util as man_util
from ..manager_repository.test_list_repositories \
import PATH_LOCAL as PATH_LISTREPO
from ..manager_fdo.test_create_fdo \
@@ -25,6 +26,7 @@ from ..manager_logging.test_list_log_events \
import PATH_LOCAL as PATH_LOGGING
PATH_FILE = str(Path(__file__).relative_to(root_dir))
PATH_LOCAL_DELETE = PATH_FILE + "::TestClassDeleteFDO::"
PATH_LOCAL_PURGE = PATH_FILE + "::TestClassPurgeFDO::"
@@ -33,101 +35,303 @@ PATH_LOCAL_PURGE = PATH_FILE + "::TestClassPurgeFDO::"
f"{PATH_RESOLVE}test_http_resolve_fdo",
f"{PATH_RESOLVE}test_client_resolve_fdo",
f"{PATH_LOGGING}test_http_log_createfdo"])
class TestClassPurgeFDO: # pylint: disable=fixme
"""Basic Tests for /fdo delete calls with purge=true"""
# ToDo: DeleteFDO on everything, then check, logs, then purge all etc.,
# create -> create check -> delete -> delete check -> purge
class TestClassDeleteFDO: # pylint: disable=fixme
"""Basic Tests for /fdo delete calls with purge=false"""
# ToDo: Cleanup dependencies - some might be redundant now that FDOs are
# not shared
@pytest.mark.parametrize("url", [pytest.param(service["url"], marks=[
@pytest.mark.parametrize("service_url", [pytest.param(service["url"], marks=[
pytest.mark.dependency(scope='session', depends=[
f'{PATH_LISTREPO}test_http_repositories[{service["url"]}]'])])
for service in services])
def test_http_purge_fdo(self, url: str):
"""Tests purge of a fdo with a delete request to /fdo/... with
purge=true. Deletes some of the fdos saved in created_fdos[<service>].
def test_http_delete_fdo(self, service_url: str):
"""Tests delete of a fdo with a delete request to /fdo/... with
purge=false.
Parameters
----------
url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
service_url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
"""
if url not in created_fdos or len(created_fdos[url]) == 0:
pytest.skip("Cannot test purge - Nothing to delete.")
if url not in purged_fdos:
purged_fdos[url] = []
urls = []
# delete a fdo in every available repository
response = requests.get(url + "/repositories", timeout=10)
repositories = json.loads(response.content.decode())['data']
if len(repositories) == 0:
pytest.skip("Cannot purge an FDO without repository.")
for repo in repositories:
local_fdos = filter(lambda x, rid=repo['id']: x['repo'] == rid,
created_fdos[url])
for fdo in list(local_fdos)[::2]:
try:
response = requests.get(service_url + "/repositories", timeout=10)
repositories = json.loads(response.content.decode())['data']
if len(repositories) == 0:
pytest.skip("Cannot delete an FDO without repository.")
for repo in repositories:
if repo['id'] == "Linkahead": # ToDo: Remove when implemented
pytest.skip(
'Linkahead does not yet support deletion of FDOs.')
# Create FDO
url_md, _ = man_util.create_fdo(service_url, repo['id'])
urls.append(url_md)
data_md, metadata_md = man_util.get_data_metadata(url_md)
# Test
query_time = datetime.datetime.now(datetime.timezone.utc)
response = requests.delete(f"{fdo['url']}?purge=true",
response = requests.delete(f"{url_md}?delete_MD=true",
timeout=10)
return_time = datetime.datetime.now(datetime.timezone.utc)
self.assertions_helper(response, query_time, return_time)
purged_fdos[url].append(fdo)
created_fdos[url].remove(fdo)
self.assertions_helper(response, query_time, return_time,
url_md, data_md, metadata_md, True)
# Create FDO
url_no_md, _ = man_util.create_fdo(service_url, repo['id'])
urls.append(url_no_md)
data_no_md, metadata_no_md = man_util.get_data_metadata(
url_no_md)
# Test
query_time = datetime.datetime.now(datetime.timezone.utc)
response = requests.delete(f"{url_no_md}", timeout=10)
return_time = datetime.datetime.now(datetime.timezone.utc)
self.assertions_helper(response, query_time, return_time,
url_no_md, data_no_md, metadata_no_md)
finally:
for url in urls:
man_util.purge_fdo(url)
@pytest.mark.parametrize("url", [pytest.param(service["url"], marks=[
@pytest.mark.parametrize("service_url", [pytest.param(service["url"], marks=[
pytest.mark.dependency(scope='session', depends=[
f'{PATH_LOCAL_PURGE}test_http_purge_fdo[{service["url"]}]',
f'{PATH_LOCAL_DELETE}test_http_delete_fdo[{service["url"]}]',
f'{PATH_LISTREPO}test_client_repositories[{service["url"]}]'])])
for service in services])
def test_client_purge_fdo(self, url: str):
"""Tests purge of a fdo with an unauthenticated client.
Deletes some of the fdos saved in created_fdos[<service>].
def test_client_delete_fdo(self, service_url: str):
"""Tests delete of a fdo with an unauthenticated client.
Parameters
----------
url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
service_url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
"""
if url not in created_fdos or len(created_fdos[url]) == 0:
pytest.skip("Cannot test purge - Nothing to delete.")
urls = []
# delete a fdo in every available repository
with Client(base_url=url) as client:
response = list_repositories.sync_detailed(client=client)
try:
with Client(base_url=service_url) as client:
response = list_repositories.sync_detailed(client=client)
repositories = json.loads(response.content.decode())['data']
if len(repositories) == 0:
pytest.skip("Cannot purge an FDO without repository.")
for repo in repositories:
if repo['id'] == "Linkahead": # ToDo: Remove when implemented
pytest.skip(
'Linkahead does not yet support deletion of FDOs.')
# Create FDO
url_md, _ = man_util.create_fdo(service_url, repo['id'])
urls.append(url_md)
data_md, metadata_md = man_util.get_data_metadata(url_md)
# Test
pid = url_md.split(f'{service_url}/fdo/')[1]
prefix, suffix = pid.split('/')
query_time = datetime.datetime.now(datetime.timezone.utc)
response = delete.sync_detailed(client=client, prefix=prefix,
suffix=suffix, delete_md=True)
return_time = datetime.datetime.now(datetime.timezone.utc)
self.assertions_helper(response, query_time, return_time,
url_md, data_md, metadata_md, True)
# Create FDO
url_no_md, _ = man_util.create_fdo(service_url, repo['id'])
urls.append(url_no_md)
data_no_md, metadata_no_md = man_util.get_data_metadata(
url_no_md)
# Test
pid = url_no_md.split(f'{service_url}/fdo/')[1]
prefix, suffix = pid.split('/')
query_time = datetime.datetime.now(datetime.timezone.utc)
response = delete.sync_detailed(client=client,
prefix=prefix, suffix=suffix)
return_time = datetime.datetime.now(datetime.timezone.utc)
self.assertions_helper(response, query_time, return_time,
url_no_md, data_no_md, metadata_no_md)
finally:
for url in urls:
man_util.purge_fdo(url)
@pytest.mark.parametrize("service_url", [pytest.param(service["url"], marks=[
pytest.mark.dependency(scope='session', depends=[
f'{PATH_LOCAL_DELETE}test_client_delete_fdo[{service["url"]}]'])])
for service in services])
def test_client_delete_unknown_fdo(self, service_url: str):
"""Tests delete of a nonexistent fdo.
Parameters
----------
service_url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
"""
with Client(base_url=service_url) as client:
prefix, suffix = "invalid.prefix", "ThisIsNotASuffix145670935"
query_time = datetime.datetime.now(datetime.timezone.utc)
response = delete.sync_detailed(client=client, prefix=prefix,
suffix=suffix)
return_time = datetime.datetime.now(datetime.timezone.utc)
# Correct Error
assert response.status_code == HTTPStatus.NOT_FOUND
# Same procedure for delete_md=True
check_timeout(query_time, return_time, response.headers['date'])
query_time = datetime.datetime.now(datetime.timezone.utc)
response = delete.sync_detailed(client=client, prefix=prefix,
suffix=suffix, delete_md=True)
return_time = datetime.datetime.now(datetime.timezone.utc)
assert response.status_code == HTTPStatus.NOT_FOUND
check_timeout(query_time, return_time, response.headers['date'])
def assertions_helper(self,
response: requests.Response | client_types.Response,
query_time: datetime.datetime,
return_time: datetime.datetime,
fdo_location: str,
data_pid: str,
metadata_pid: str,
delete_md: bool = False):
"""Asserts correct behaviour of /fdo purge calls.
This includes response code and reasonable response time.
Parameters
----------
response : requests.Response | fdo_[...]_client.types.Response
Response from the /fdo request.
query_time : datetime.datetime
Time from just before the request to /fdo was sent,
using datetime.datetime.now(datetime.timezone.utc)
return_time : datetime.datetime
Time from just after the request to /fdo was sent,
using datetime.datetime.now(datetime.timezone.utc)
fdo_location : str
Url of the deleted fdo.
data_pid : str
PID of the deleted data.
metadata_pid : str
PID of the deleted metadata.
delete_md : bool: optional, default False
Boolean indicating whether the metadata was supposed
to also be deleted.
"""
# No errors
assert response.status_code == HTTPStatus.NO_CONTENT
# Answer within one second
check_timeout(query_time, return_time, response.headers['date'], 10)
# Correct changes:
# ToDo: As soon as access of attributes and files is possible from
# the /fdo endpoint, also check content changes
response_fdo = requests.get(fdo_location, timeout=10)
assert response_fdo.status_code == HTTPStatus.OK
base_url = '/'.join(fdo_location.split('/')[:-2])+'/'
if data_pid is not None:
response_data = requests.get(base_url+data_pid, timeout=10)
assert response_data.status_code == HTTPStatus.OK
if metadata_pid is not None:
response_md = requests.get(base_url+metadata_pid, timeout=10)
assert response_md.status_code == HTTPStatus.OK
@pytest.mark.order(after=[
f"{PATH_CREATE_CHECKS}test_create_fdo_outside_systems_check",
f"{PATH_RESOLVE}test_http_resolve_fdo",
f"{PATH_RESOLVE}test_client_resolve_fdo",
f"{PATH_LOGGING}test_http_log_createfdo"])
class TestClassPurgeFDO: # pylint: disable=fixme
"""Basic Tests for /fdo delete calls with purge=true"""
@pytest.mark.parametrize("service_url", [pytest.param(service["url"], marks=[
pytest.mark.dependency(scope='session', depends=[
f'{PATH_LISTREPO}test_http_repositories[{service["url"]}]'])])
for service in services])
def test_http_purge_fdo(self, service_url: str):
"""Tests purge of a fdo with a delete request to /fdo/... with
purge=true.
Parameters
----------
service_url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
"""
urls = []
# purge a fdo in every available repository
try:
response = requests.get(service_url + "/repositories", timeout=10)
repositories = json.loads(response.content.decode())['data']
if len(repositories) == 0:
pytest.skip("Cannot purge an FDO without repository.")
for repo in repositories:
local_fdos = filter(lambda x, rid=repo['id']: x['repo'] == rid,
created_fdos[url])
for fdo in list(local_fdos):
pid = fdo['url'].split(f'{url}/fdo/')[1]
if repo['id'] == "Linkahead": # ToDo: Remove when implemented
pytest.skip(
'Linkahead does not yet support deletion of FDOs.')
url, _ = man_util.create_fdo(service_url, repo['id'])
urls.append(url)
data, metadata = man_util.get_data_metadata(url)
query_time = datetime.datetime.now(datetime.timezone.utc)
response = requests.delete(f"{urls[-1]}?purge=true",
timeout=10)
return_time = datetime.datetime.now(datetime.timezone.utc)
self.assertions_helper(response, query_time, return_time,
url, data, metadata)
finally:
for url in urls:
man_util.purge_fdo(url)
@pytest.mark.parametrize("service_url", [pytest.param(service["url"], marks=[
pytest.mark.dependency(scope='session', depends=[
f'{PATH_LOCAL_PURGE}test_http_purge_fdo[{service["url"]}]',
f'{PATH_LISTREPO}test_client_repositories[{service["url"]}]'])])
for service in services])
def test_client_purge_fdo(self, service_url: str):
"""Tests purge of a fdo with an unauthenticated client.
Parameters
----------
service_url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
"""
urls = []
# delete a fdo in every available repository
try:
with Client(base_url=service_url) as client:
response = list_repositories.sync_detailed(client=client)
repositories = json.loads(response.content.decode())['data']
if len(repositories) == 0:
pytest.skip("Cannot purge an FDO without repository.")
for repo in repositories:
if repo['id'] == "Linkahead": # ToDo: Remove when implemented
pytest.skip(
'Linkahead does not yet support deletion of FDOs.')
url, _ = man_util.create_fdo(service_url, repo['id'])
urls.append(url)
data, metadata = man_util.get_data_metadata(url)
pid = url.split(f'{service_url}/fdo/')[1]
prefix, suffix = pid.split('/')
query_time = datetime.datetime.now(datetime.timezone.utc)
response = base_delete.sync_detailed(client=client,
prefix=prefix, suffix=suffix, purge=True)
response = delete.sync_detailed(client=client, prefix=prefix,
suffix=suffix, purge=True)
return_time = datetime.datetime.now(datetime.timezone.utc)
self.assertions_helper(response, query_time, return_time)
purged_fdos[url].append(fdo)
created_fdos[url].remove(fdo)
self.assertions_helper(response, query_time, return_time,
url, data, metadata)
finally:
for url in urls:
man_util.purge_fdo(url)
@pytest.mark.parametrize("url", [pytest.param(service["url"], marks=[
@pytest.mark.parametrize("service_url", [pytest.param(service["url"], marks=[
pytest.mark.dependency(scope='session', depends=[
f'{PATH_LOCAL_PURGE}test_client_purge_fdo[{service["url"]}]'])])
for service in services])
def test_client_purge_unknown_fdo(self, url: str):
def test_client_purge_unknown_fdo(self, service_url: str):
"""Tests purge of a nonexistent fdo.
Parameters
----------
url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
service_url : str
URL of the service to be tested without trailing slash,
for example "https://manager.testbed.pid.gwdg.de/api/v1"
"""
with Client(base_url=url) as client:
with Client(base_url=service_url) as client:
prefix, suffix = "invalid.prefix", "ThisIsNotASuffix145670935"
query_time = datetime.datetime.now(datetime.timezone.utc)
response = base_delete.sync_detailed(client=client, prefix=prefix,
suffix=suffix, purge=True)
response = delete.sync_detailed(client=client, prefix=prefix,
suffix=suffix, purge=True)
return_time = datetime.datetime.now(datetime.timezone.utc)
# Correct Error
assert response.status_code == HTTPStatus.NOT_FOUND
@@ -137,25 +341,234 @@ class TestClassPurgeFDO: # pylint: disable=fixme
def assertions_helper(self,
response: requests.Response | client_types.Response,
query_time: datetime.datetime,
return_time: datetime.datetime):
return_time: datetime.datetime,
fdo_location: str,
data_pid: str,
metadata_pid: str):
"""Asserts correct behaviour of /fdo purge calls.
This includes response code and reasonable response time.
Parameters
----------
response : requests.Response | fdo_[...]_client.types.Response
Response from the /fdo request.
query_time : datetime.datetime
Time from just before the request to /fdo was sent,
using datetime.datetime.now(datetime.timezone.utc)
return_time : datetime.datetime
Time from just after the request to /fdo was sent,
using datetime.datetime.now(datetime.timezone.utc)
response : requests.Response | fdo_[...]_client.types.Response
Response from the /fdo request.
query_time : datetime.datetime
Time from just before the request to /fdo was sent,
using datetime.datetime.now(datetime.timezone.utc)
return_time : datetime.datetime
Time from just after the request to /fdo was sent,
using datetime.datetime.now(datetime.timezone.utc)
fdo_location : str
Url of the deleted fdo.
data_pid : str
PID of the deleted data.
metadata_pid : str
PID of the deleted metadata.
"""
# No errors
assert response.status_code == HTTPStatus.NO_CONTENT
# Answer within one second
check_timeout(query_time, return_time, response.headers['date'], 10)
# FDO deleted
response_fdo = requests.get(fdo_location, timeout=10)
assert response_fdo.status_code == HTTPStatus.NOT_FOUND
base_url = '/'.join(fdo_location.split('/')[:-2])+'/'
if data_pid is not None:
response_data = requests.get(base_url+data_pid, timeout=10)
assert response_data.status_code == HTTPStatus.NOT_FOUND
if metadata_pid is not None:
response_md = requests.get(base_url+metadata_pid, timeout=10)
assert response_md.status_code == HTTPStatus.NOT_FOUND
@pytest.mark.order(after=["TestClassDeleteFDO"])
class TestClassDeleteFDOChecks: # pylint: disable=fixme
"""Tests whether FDO delete is reflected in outside systems"""
@pytest.mark.parametrize("service", [pytest.param(service, marks=[
pytest.mark.dependency(scope='session', depends=[])])
for service in services])
def test_purge_fdo_outside_systems_check(self, service: dict):
"""Tests successful deletion of a fdo by checking directly with
the repo if possible.
Parameters
----------
service: dict
Dictionary containing info of the service to be tested,
including url and information about available repos.
"""
urls = []
try:
any_checks_made = False
response = requests.get(
service['url'] + "/repositories", timeout=10)
repositories = json.loads(response.content.decode())['data']
for repo in repositories:
if repo['id'] == "Linkahead": # ToDo: Remove when implemented
# Linkahead does not yet support deletion of FDOs.
continue
try:
# Setup Data
url_md, _ = man_util.create_fdo(service['url'], repo['id'])
urls.append(url_md)
data_md, metadata_md = man_util.get_data_metadata(url_md)
url_no_md, _ = man_util.create_fdo(
service['url'], repo['id'])
urls.append(url_no_md)
data_no_md, metadata_no_md = man_util.get_data_metadata(
url_no_md)
# ToDo: Save files from the metadata of the delete_MD=false
# call here to later check that they were not changed
# Deletion
requests.delete(f"{url_md}?delete_MD=true", timeout=10)
with Client(base_url=service['url']) as client:
prefix, suffix = url_no_md.split('/')[-2:]
delete.sync_detailed(
prefix, suffix, client=client)
except Exception as e: # pylint: disable=broad-exception-caught
pytest.skip(f"Setup unsuccessful with Exception: {str(e)}")
repo = service["repos"][repo['id']]
pid_md = url_md.split(f"{service['url']}/fdo/")[1]
pid_no_md = url_no_md.split(f"{service['url']}/fdo/")[1]
# If possible, check with repo
if "retrieve" in repo["links"] and repo["links"]["retrieve"]:
api_config = repo["links"]["retrieve"]
match api_config["api_version"]:
case "Cordra-V1":
cordra_url = api_config["url"]
# Checks with metadata deletion
self.assertions_helper_cordra(cordra_url, pid_md)
any_checks_made = True
if data_md is not None:
self.assertions_helper_cordra(
cordra_url, data_md, is_fdo=False)
if metadata_md is not None:
self.assertions_helper_cordra(
cordra_url, metadata_md, is_fdo=False)
# Checks without metadata deletion
self.assertions_helper_cordra(
cordra_url, pid_no_md)
if data_no_md is not None:
self.assertions_helper_cordra(
cordra_url, data_no_md, is_fdo=False)
if metadata_no_md is not None:
self.assertions_helper_cordra(
cordra_url, metadata_no_md, is_fdo=False, deleted=False)
# If possible, check with handle system
if "handle" in repo["links"] and repo["links"]["handle"] != "":
handle_url = repo["links"]["handle"]["url"]
# Checks with metadata deletion
self.assertions_helper_handle(handle_url, pid_md)
any_checks_made = True
if data_md is not None:
self.assertions_helper_handle(
handle_url, data_md, is_fdo=False)
if metadata_md is not None:
self.assertions_helper_handle(
handle_url, metadata_md, is_fdo=False)
# Checks without metadata deletion
self.assertions_helper_handle(handle_url, pid_no_md)
if data_no_md is not None:
self.assertions_helper_handle(
handle_url, data_no_md, is_fdo=False)
if metadata_no_md is not None:
self.assertions_helper_handle(
handle_url, metadata_no_md, is_fdo=False, deleted=False)
finally:
for url in urls:
man_util.purge_fdo(url)
if not any_checks_made:
pytest.skip('No checks with outside systems were possible.')
def assertions_helper_cordra(self,
cordra_url: str,
pid: str,
deleted: bool = True,
is_fdo: bool = True):
"""Asserts that the Cordra response matches expected output.
Parameters
----------
cordra_url : str
Url to the Cordra API endpoint
pid : str
PID of DO to be tested
deleted : bool: optional, default True
Boolean indicating whether the content is supposed to
have been deleted.
is_fdo : bool: optional, default True
Boolean indicating whether to check fdo or component
deletion.
"""
response = requests.get(
cordra_url, params={"targetId": pid}, timeout=10)
# No errors
assert response.status_code == HTTPStatus.OK
# Correct changes
content = json.loads(response.content.decode())[
'attributes']['content']
if not deleted:
if "FDO_Status" in content:
assert content["FDO_Status"] != "deleted"
assert "URL_Status" not in content
if "DO_Status" in content:
assert content["DO_Status"] != "deleted"
assert "URL_Status" not in content
return
if is_fdo:
assert "FDO_Status" in content
assert content["FDO_Status"] == "deleted"
assert "URL_Status" not in content
else:
assert "DO_Status" in content.keys()
assert content["DO_Status"] == "deleted"
assert "URL_Status" in content
assert "file_size" not in content
def assertions_helper_handle(self,
handle_url: str,
pid: str,
deleted: bool = True,
is_fdo: bool = True):
"""Asserts that the Cordra response matches expected output.
Parameters
----------
handle_url : str
Url to the Handle API endpoint
pid : str
PID of DO to be tested
deleted : bool: optional, default True
Boolean indicating whether the content is supposed to
have been deleted.
is_fdo : bool: optional, default True
Boolean indicating whether to check fdo or component
deletion.
"""
response = requests.get(f'{handle_url}{pid}', timeout=10)
# No errors
assert response.status_code == HTTPStatus.OK
# Correct changes
content = json.loads(response.content.decode())
attributes = {entry["type"]: entry["data"]["value"]
for entry in content["values"]}
if not deleted:
if "FDO_Status" in attributes:
assert attributes["FDO_Status"] != "deleted"
assert "URL_Status" not in attributes
if "DO_Status" in attributes:
assert attributes["DO_Status"] != "deleted"
assert "URL_Status" not in attributes
return
if is_fdo:
assert "FDO_Status" in attributes
assert attributes["FDO_Status"] == "deleted"
assert "URL_Status" not in attributes
else:
assert "DO_Status" in attributes
assert attributes["DO_Status"] == "deleted"
assert "URL_Status" in attributes
@pytest.mark.order(after=["TestClassPurgeFDO"])
@@ -175,36 +588,52 @@ class TestClassPurgeFDOChecks: # pylint: disable=fixme
Dictionary containing info of the service to be tested,
including url and information about available repos.
"""
if service['url'] not in purged_fdos:
pytest.skip('Cannot check FDOs if none have been purged.')
any_checks_made = False
for fdo in purged_fdos[service['url']]:
repo = service["repos"][fdo['repo']]
pid = fdo['url'].split(f"{service['url']}/fdo/")[1]
# If possible, check with repo
if "retrieve" in repo["links"] and repo["links"]["retrieve"]:
api_config = repo["links"]["retrieve"]
match api_config["api_version"]:
case "Cordra-V1":
url = api_config["url"]
response = requests.get(url, params={"targetId": pid},
timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
any_checks_made = True
# If possible, check with handle system
if "handle" in repo["links"] and repo["links"]["handle"] != "":
# Handle system API lags for minutes - have to check
# against frontend instead
url = repo["links"]["handle"]["url"]
response = requests.get(f'{url}{pid}?auth', timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
any_checks_made = True
if 'data' in fdo:
response = requests.get(f'{url}{fdo["data"]}?auth', timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
if 'metadata' in fdo:
response = requests.get(
f'{url}{fdo["metadata"]}?auth', timeout=10)
urls = []
try:
any_checks_made = False
response = requests.get(
service['url'] + "/repositories", timeout=10)
repositories = json.loads(response.content.decode())['data']
for repo in repositories:
if repo['id'] == "Linkahead": # ToDo: Remove when implemented
# Linkahead does not yet support deletion of FDOs.
continue
try:
url, _ = man_util.create_fdo(service['url'], repo['id'])
urls.append(url)
data, metadata = man_util.get_data_metadata(url)
man_util.purge_fdo(url)
except Exception as e: # pylint: disable=broad-exception-caught
pytest.skip(f"Setup unsuccessful with Exception: {str(e)}")
repo = service["repos"][repo['id']]
pid = url.split(f"{service['url']}/fdo/")[1]
# If possible, check with repo
if "retrieve" in repo["links"] and repo["links"]["retrieve"]:
api_config = repo["links"]["retrieve"]
match api_config["api_version"]:
case "Cordra-V1":
cordra_url = api_config["url"]
response = requests.get(cordra_url, params={"targetId": pid},
timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
any_checks_made = True
# If possible, check with handle system
if "handle" in repo["links"] and repo["links"]["handle"] != "":
# Handle system API lags behind for minutes - have to check
# against frontend instead
url = repo["links"]["handle"]["url"].split('api')[0]
response = requests.get(f'{url}{pid}', timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
any_checks_made = True
if data is not None:
response = requests.get(f'{url}{data}', timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
if metadata is not None:
response = requests.get(
f'{url}{metadata}', timeout=10)
assert response.status_code == HTTPStatus.NOT_FOUND
finally:
for url in urls:
man_util.purge_fdo(url)
if not any_checks_made:
pytest.skip('No checks with outside systems were possible.')
Loading