def test_get_jobs(self): """Test getting the jobs ran for a transfer""" response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, unit_uuid="ca480d94-892c-4d99-bbb1-290698406571", ).get_jobs() assert isinstance(response, list) assert len(response) > 0 expected_job_attributes = [ "link_uuid", "microservice", "name", "status", "tasks", "uuid", ] expected_task_attributes = ["exit_code", "uuid"] for job in response: assert sorted(job.keys()) == expected_job_attributes for task in job["tasks"]: assert sorted(task.keys()) == expected_task_attributes # Test filtering jobs by microservice response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, unit_uuid="ca480d94-892c-4d99-bbb1-290698406571", job_microservice="Clean up names", ).get_jobs() expected_jobs = [ "Sanitize Transfer name", "Sanitize object's file and directory names", ] microservice_jobs = sorted([job["name"] for job in response]) assert microservice_jobs == expected_jobs # Test filtering jobs by link_uuid response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, unit_uuid="ca480d94-892c-4d99-bbb1-290698406571", job_link_uuid="87e7659c-d5de-4541-a09c-6deec966a0c0", ).get_jobs() assert len(response) == 1 assert response[0]["name"] == "Verify mets_structmap.xml compliance" # Test filtering jobs by name response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, unit_uuid="ca480d94-892c-4d99-bbb1-290698406571", job_name="Verify metadata directory checksums", ).get_jobs() assert len(response) == 1 assert response[0]["name"] == "Verify metadata directory checksums"
def test_create_package_endpoint(self): """Test the package endpoint to ensure that it returns a UUID that we can then work with to monitor potential transfers. We don't get much feedback from the v2/beta endpoint so we just check that we do receive a UUID as anticipated. """ path = "/archivematica/archivematica-sampledata/SampleTransfers/DemoTransfer" response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_source="d1184f7f-d755-4c8d-831a-a3793b88f760", transfer_directory=path, transfer_name="amclient-transfer", processing_config="automated", ).create_package() uuid_ = response.get("id", "") try: uuid.UUID(uuid_, version=4) except ValueError: assert False # Provide a test for an absolute path, over relative above. path = ("/home/archivematica/archivematica-sampledata/SampleTransfers/" "DemoTransfer") response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_directory=path, transfer_name="amclient-transfer", processing_config="automated", ).create_package() uuid_ = response.get("id", "") try: uuid.UUID(uuid_, version=4) except ValueError: assert False # Provide a test for a non-standard transfer type path = "/archivematica/archivematica-sampledata/SampleTransfers/BagTransfer" response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_source="d1184f7f-d755-4c8d-831a-a3793b88f760", transfer_directory=path, transfer_name="amclient-transfer", transfer_type="unzipped bag", processing_config="automated", ).create_package() uuid_ = response.get("id", "") try: uuid.UUID(uuid_, version=4) except ValueError: assert False
def test_dips_no_dips(self): """Test that we get no DIPs from the Storage Service if there are none. """ dips = amclient.AMClient(ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=SS_API_KEY).dips() assert isinstance(dips, list) assert dips == []
def test_completed_transfers_bad_key(self): """Test getting completed transfers when a bad AM API key is provided. """ completed_transfers = amclient.AMClient( am_api_key="bad api key", am_user_name=AM_USER_NAME, am_url=AM_URL).completed_transfers() assert completed_transfers is errors.ERR_INVALID_RESPONSE
def test_download_dip_no_dip(self): """Test that we can try to download a DIP that does not exist.""" dip_uuid = "bad dip uuid" dip_path = amclient.AMClient( dip_uuid=dip_uuid, ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=SS_API_KEY, ).download_dip() assert dip_path is None
def test_completed_transfers_no_transfers(self): """Test getting completed transfers when there are no completed transfers to get. """ completed_transfers = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL).completed_transfers() assert (completed_transfers["message"] == "Fetched completed transfers successfully.") results = completed_transfers["results"] assert isinstance(results, list) assert len(results) == 0
def test_get_pipelines_none(self): """Test getting the pipelines available to the storage service where there is at least one pipeline available to the service. """ response = amclient.AMClient(ss_api_key=SS_API_KEY, ss_user_name=SS_USER_NAME, ss_url=SS_URL).get_pipelines() objects = response["objects"] assert objects == [] assert isinstance(objects, list) assert len(objects) == 0
def test_close_completed_ingests_no_ingests(self): """Test closing completed ingests when there are no completed ingests to close. """ response = amclient.AMClient(am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL).close_completed_ingests() close_succeeded = response["close_succeeded"] completed_ingests = response["completed_ingests"] assert close_succeeded == completed_ingests assert isinstance(close_succeeded, list) assert len(close_succeeded) == 0
def test_get_ingest_status_invalid_uuid(self): """Test the response from the server for a request to find the status of an ingest uuid that doesn't exist. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, sip_uuid="63fcc1b0-f83d-47e6-ac9d-a8f8d1fc2ab9", ).get_ingest_status() assert (errors.error_lookup(response) == errors.error_codes[ errors.ERR_INVALID_RESPONSE])
def test_get_processing_config(self): """Test retrieval of the default Processing MCP Config file from the Archivematica instance. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, processing_config="default", ).get_processing_config() processing_mcp_file = response assert "<processingMCP>" and "</processingMCP>" in processing_mcp_file
def test_aip2dips_no_dips(self): """Test that we get no DIPs when attempting to get all DIPs corresponding to an AIP that has none. """ aip_uuid = "3500aee0-08ca-40ff-8d2d-9fe9a2c3ae3b" dips = amclient.AMClient( aip_uuid=aip_uuid, ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=SS_API_KEY, ).aip2dips() assert isinstance(dips, list) assert len(dips) == 0
def test_get_package_details_invalid_uuid(self): """Test amlient's response when an invalid package uuid is provided to the get package details endpoint. """ package_uuid = "23129471-baad-f00d-88b6-eb4714afb5ac" response = amclient.AMClient( ss_api_key=SS_API_KEY, ss_user_name=SS_USER_NAME, ss_url=SS_URL, package_uuid=package_uuid, ).get_package_details() assert (errors.error_lookup(response) == errors.error_codes[ errors.ERR_INVALID_RESPONSE])
def test_dips_dips(self): """Test that we can get all DIPs in the Storage Service.""" dips = amclient.AMClient(ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=SS_API_KEY).dips() assert isinstance(dips, list) assert len(dips) == 2 for dip in dips: assert isinstance(dip, dict) assert "uuid" in dip assert amclient.is_uuid(dip["uuid"]) assert dip["package_type"] == "DIP" assert "DIPsStore" in dip["current_full_path"]
def test_get_package_details(self): """Test that amclient can retrieve details about a package.""" package_uuid = "23129471-09e3-467e-88b6-eb4714afb5ac" response = amclient.AMClient( ss_api_key=SS_API_KEY, ss_user_name=SS_USER_NAME, ss_url=SS_URL, package_uuid=package_uuid, ).get_package_details() status = response["status"] package_type = response["package_type"] assert status == "UPLOADED" assert package_type == "AIP"
def test_download_aip_fail(self): """Test that we can try to download an AIP that does not exist.""" aip_uuid = "bad-aip-uuid" # Changing the SS_API_KEY global var to generate the cassetes # for the new test cases makes all the other cassetes to fail. # Adding a local var to be able to generate the new cassetes. ss_api_key = "7021334bee4c9155c07e531608dd28a9d8039420" aip_path = amclient.AMClient( aip_uuid=aip_uuid, ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=ss_api_key, ).download_aip() assert aip_path is None
def test_approve_transfer(self): """Test the approval of a transfer waiting in the Archivematica pipeline.""" response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_directory="approve_1", transfer_type="standard", ).approve_transfer() message = response["message"] uuid = response["uuid"] assert message == "Approval successful." assert amclient.is_uuid(uuid)
def test_completed_ingests_ingests(self): """Test getting completed ingests when there are completed ingests to get. """ completed_ingests = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL).completed_ingests() assert completed_ingests[ "message"] == "Fetched completed ingests successfully." results = completed_ingests["results"] assert isinstance(results, list) assert len(results) == 2 for item in results: assert amclient.is_uuid(item)
def test_approve_non_existing_transfer(self): """If a transfer isn't available for us to approve, test the response from AMClient.py. The respons is a 404 and this is handled specifically by utils.py and the return is an error code. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_directory="approve_2", transfer_type="standard", ).approve_transfer() assert (errors.error_lookup(response) == errors.error_codes[ errors.ERR_INVALID_RESPONSE])
def test_close_completed_transfers_transfers(self): """Test closing completed transfers when there are completed transfers to close. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL).close_completed_transfers() close_succeeded = response["close_succeeded"] completed_transfers = response["completed_transfers"] assert close_succeeded == completed_transfers assert isinstance(close_succeeded, list) assert len(close_succeeded) == 2 for item in close_succeeded: assert amclient.is_uuid(item)
def test_get_transfer_status_invalid_uuid(self): """Test the successful return of the status for a non-existant transfer in Archivematica. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_uuid="7bffc8f7-baad-f00d-8120-b1c51c2ab5db", ).get_transfer_status() message = response["message"] message_type = response["type"] assert message == ("Cannot fetch unitTransfer with UUID 7bffc8f7-" "baad-f00d-8120-b1c51c2ab5db") assert message_type == "transfer"
def test_get_all_compressed_aips(self): """Test amclient's ability to report on all compressed AIPs in the storage service. """ response = amclient.AMClient(ss_api_key=SS_API_KEY, ss_user_name=SS_USER_NAME, ss_url=SS_URL).get_all_compressed_aips() expected_list = [ "6d32a85f-6715-43af-947c-83c9d7f0deac", "6f198696-e3b6-4f45-8ab3-b4cd4afd921a", "9c5edcdc-3e3f-499d-a016-a43b9db875b1", ] assert set(response.keys()) == set(expected_list) for aip in response.values(): assert aip["uuid"] in expected_list
def test_get_pipelines(self): """Test getting the pipelines available to the storage service where there is at least one pipeline available to the service. """ response = amclient.AMClient(ss_api_key=SS_API_KEY, ss_user_name=SS_USER_NAME, ss_url=SS_URL).get_pipelines() objects = response["objects"] pipelines = objects[0]["uuid"] resource_uri = objects[0]["resource_uri"] assert amclient.is_uuid(pipelines) assert resource_uri == "/api/v2/pipeline/f914af05-c7d2-4611-b2eb-61cd3426d9d2/" assert isinstance(objects, list) assert len(objects) > 0
def test_get_non_existing_processing_config(self): """Test retrieval of a Processing MCP Config file that does not exist in the Archivematica instance. Archivematica returns a 404 error and a HTML result. This test is volatile to both changes in AM's handling of this request failure in future, and changes to the error handling in AMClient.py. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, processing_config="badf00d", ).get_processing_config() assert (errors.error_lookup(response) == errors.error_codes[ errors.ERR_INVALID_RESPONSE])
def test_download_dip_dip(self): """Test that we can download a DIP when there is one.""" with TmpDir(TMP_DIR): dip_uuid = "c0e37bab-e51e-482d-a066-a277330de9a7" dip_path = amclient.AMClient( dip_uuid=dip_uuid, ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=SS_API_KEY, directory=TMP_DIR, ).download_dip() assert (dip_path == "{}/package-c0e37bab-e51e-482d-a066-a277330de9a7.7z". format(TMP_DIR)) assert os.path.isfile(dip_path)
def test_transferables(self): """Test that we can get all transferable entities in the Storage Service. """ transferables = amclient.AMClient( ss_api_key=SS_API_KEY, transfer_source=TRANSFER_SOURCE_UUID, ss_user_name=SS_USER_NAME, ss_url=SS_URL, transfer_path="", ).transferables() assert isinstance(transferables, dict) assert "directories" in transferables assert "entries" in transferables assert "properties" in transferables assert transferables["directories"] == ["ubuntu", "vagrant"]
def test_get_ingest_status(self): """Test the successful return of the status of an ingest for a valid SIP UUID. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, sip_uuid="23129471-09e3-467e-88b6-eb4714afb5ac", ).get_ingest_status() message = response["message"] message_type = response["type"] assert message == ( "Fetched status for 23129471-09e3-467e-88b6-eb4714afb5ac successfully." ) assert message_type == "SIP"
def test_get_transfer_status(self): """Test the successful return of the status of a transfer for a valid transfer UUID. """ response = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL, transfer_uuid="63fcc1b0-f83d-47e6-ac9d-a8f8d1fc2ab9", ).get_transfer_status() status = response["status"] message = response["message"] assert status == "COMPLETE" assert message == ( "Fetched status for 63fcc1b0-f83d-47e6-ac9d-a8f8d1fc2ab9 successfully." )
def test_unapproved_transfers_transfers(self): """Test getting unapproved transfers when there are unapproved transfers to get. """ unapproved_transfers = amclient.AMClient( am_api_key=AM_API_KEY, am_user_name=AM_USER_NAME, am_url=AM_URL).unapproved_transfers() assert (unapproved_transfers["message"] == "Fetched unapproved transfers successfully.") results = unapproved_transfers["results"] assert isinstance(results, list) assert len(results) == 1 for unapproved_transfer in results: assert "type" in unapproved_transfer assert "uuid" in unapproved_transfer assert "directory" in unapproved_transfer assert amclient.is_uuid(unapproved_transfer["uuid"])
def test_reingest_non_aip(self): """Test amclient's response to the initiation of a reingest for an AIP that does not exist. """ pipeline_uuid = "bb033eff-131e-48d5-980f-c4edab0cb038" aip_uuid = "bb033eff-131e-48d5-980f-c4edab0cb038" response = amclient.AMClient( ss_api_key=SS_API_KEY, ss_user_name=SS_USER_NAME, ss_url=SS_URL, pipeline_uuid=pipeline_uuid, aip_uuid=aip_uuid, reingest_type="standard", processing_config="default", ).reingest_aip() assert (errors.error_lookup(response) == errors.error_codes[ errors.ERR_INVALID_RESPONSE])
def test_aips2dips(self): """Test that we can get all AIPs in the Storage Service and their corresonding DIPs. """ aips2dips = amclient.AMClient(ss_url=SS_URL, ss_user_name=SS_USER_NAME, ss_api_key=SS_API_KEY).aips2dips() assert isinstance(aips2dips, dict) assert len(aips2dips) == 4 assert aips2dips["3500aee0-08ca-40ff-8d2d-9fe9a2c3ae3b"] == [] assert aips2dips["979cce65-2a6f-407f-a49c-1bcf13bd8571"] == [] assert aips2dips["721b98b9-b894-4cfb-80ab-624e52263300"] == [ "c0e37bab-e51e-482d-a066-a277330de9a7" ] assert aips2dips["99bb20ee-69c6-43d0-acf0-c566020357d2"] == [ "7e49afa4-116b-4650-8bbb-9341906bdb21" ]