예제 #1
0
    def handle_package(self, package):

        am_client = AMClient(ss_api_key=settings.ARCHIVEMATICA['api_key'],
                             ss_user_name=settings.ARCHIVEMATICA['username'],
                             ss_url=settings.ARCHIVEMATICA['baseurl'],
                             directory=self.tmp_dir)

        am_client.package_uuid = package.archivematica_identifier
        package_data = am_client.get_package_details()
        if isinstance(package_data, int):
            raise Exception(errors.error_lookup(package_data))

        if self.is_downloadable(package_data):
            try:
                download_path = am_client.download_package(
                    am_client.package_uuid)
                tmp_path = join(
                    self.tmp_dir,
                    f"{am_client.package_uuid}{self.get_extension(package_data)}"
                )
                move(download_path, tmp_path)
            except Exception as e:
                raise RoutineError(f"Error downloading data: {e}")
            package.type = package_data['package_type'].lower()
            package.data = package_data
        else:
            raise RoutineError(
                f"Package {package.archivematica_identifier} is not downloadable"
            )
예제 #2
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])
예제 #3
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])
예제 #4
0
 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])
예제 #5
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])
예제 #6
0
 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])
예제 #7
0
 def get_processing_config(self, client):
     """Returns a processing configuration file from Archivematica"""
     processing_config = client.get_processing_config()
     if isinstance(processing_config, int):
         raise Exception(errors.error_lookup(processing_config), processing_config)
     return processing_config
예제 #8
0
 def validate_rights_csv(self):
     file_obj = open(self.csv_filepath, "r")
     result = self.client.validate_csv("rights", file_obj)
     if isinstance(result, int):
         message = getattr(result, "message", error_lookup(result))
         raise Exception("Error validating CSV: {}".format(message))