Ejemplo n.º 1
0
 def test_hide_units(self):
     """Test the hiding of a unit type (transfer or ingest) via the
     Archivematica API.
     """
     Result = collections.namedtuple('Result',
                                     'uuid unit_type expected data_type')
     hide_tests = [
         Result(uuid="fdf1f7d4-7b0e-46d7-a1cc-e1851f8b92ed",
                unit_type='transfer',
                expected={'removed': True},
                data_type=dict),
         Result(uuid="777a9d9e-baad-f00d-8c7e-00b75773672d",
                unit_type='transfer',
                expected=errors.ERR_INVALID_RESPONSE,
                data_type=int),
         Result(uuid="b72afa68-9e82-410d-9235-02fa10512e14",
                unit_type='ingest',
                expected={'removed': True},
                data_type=dict),
         Result(uuid="777a9d9e-baad-f00d-8c7e-00b75773672d",
                unit_type='ingest',
                expected=errors.ERR_INVALID_RESPONSE,
                data_type=int),
     ]
     for test in hide_tests:
         response = amclient.AMClient(am_api_key=AM_API_KEY,
                                      am_user_name=AM_USER_NAME,
                                      am_url=AM_URL).hide_unit(
                                          test.uuid, test.unit_type)
         assert isinstance(response, test.data_type)
         assert response == test.expected
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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 == []
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 def test_get_package_details_invalid_uuid(self):
     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]
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def test_get_package_details(self):
     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"
Ejemplo n.º 8
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]
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
 def test_close_completed_transfers_no_transfers(self):
     """Test closing completed transfers when there are no 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) == 0
def main(ss_url, ss_user, ss_api_key, aip_uuid, tmp_dir, output_dir):
    LOGGER.info('Starting DIP creation from AIP: %s', aip_uuid)

    if not os.path.isdir(tmp_dir):
        LOGGER.error('%s is not a valid temporary directory', tmp_dir)
        return 1

    if not os.path.isdir(output_dir):
        LOGGER.error('%s is not a valid output directory', output_dir)
        return 2

    # Create empty workspace directory
    tmp_dir = os.path.join(tmp_dir, aip_uuid)
    if os.path.exists(tmp_dir):
        LOGGER.warning('Workspace directory already exists, overwriting')
        shutil.rmtree(tmp_dir)
    try:
        os.makedirs(tmp_dir)
    except OSError:
        LOGGER.error('Could not create workspace directory: %s', tmp_dir)
        return 3

    LOGGER.info('Downloading AIP from Storage Service')

    am_client = amclient.AMClient(aip_uuid=aip_uuid,
                                  ss_url=ss_url,
                                  ss_user_name=ss_user,
                                  ss_api_key=ss_api_key,
                                  directory=tmp_dir)

    aip_file = am_client.download_aip()

    if not aip_file:
        LOGGER.error('Unable to download AIP')
        return 4

    LOGGER.info('Extracting AIP')
    aip_dir = extract_aip(aip_file, aip_uuid, tmp_dir)

    if not aip_dir:
        return 5

    LOGGER.info('Creating DIP')
    dip_dir = create_dip(aip_dir, aip_uuid, output_dir)

    if not dip_dir:
        LOGGER.error('Unable to create DIP')
        return 6

    # Remove workspace directory
    shutil.rmtree(tmp_dir)

    LOGGER.info('DIP created in: %s', dip_dir)
Ejemplo n.º 15
0
 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']
Ejemplo n.º 16
0
    def test_get_all_compressed_aips(self):
        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
Ejemplo n.º 17
0
 def test_reingest_non_aip(self):
     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]
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
 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)
Ejemplo n.º 20
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]
Ejemplo n.º 21
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]
Ejemplo n.º 22
0
 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)
Ejemplo n.º 23
0
 def test_close_completed_ingests_ingests(self):
     """Test closing completed ingests when there are 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) == 2
     for item in close_succeeded:
         assert amclient.is_uuid(item)
Ejemplo n.º 24
0
 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"
Ejemplo n.º 25
0
 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']
Ejemplo n.º 26
0
 def test_extract_aip_success(self):
     """Test that we can download and extract an AIP."""
     with TmpDir(TMP_DIR):
         # Download the AIP first
         aip_path = amclient.AMClient(aip_uuid=AIP_UUID,
                                      ss_url=SS_URL,
                                      ss_user_name=SS_USER_NAME,
                                      ss_api_key=SS_API_KEY,
                                      directory=TMP_DIR).download_aip()
         # Then test extraction
         aip_dir = create_dip.extract_aip(aip_path, AIP_UUID, TMP_DIR)
         assert (aip_dir == '{}/{}-{}'.format(TMP_DIR, TRANSFER_NAME,
                                              AIP_UUID))
         assert os.path.isdir(aip_dir)
Ejemplo n.º 27
0
 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'
Ejemplo n.º 28
0
    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.')
Ejemplo n.º 29
0
 def test_aip2dips_dips(self):
     """Test that we can get all of the DIPs from the Storage Service for a
     given AIP.
     """
     aip_uuid = '721b98b9-b894-4cfb-80ab-624e52263300'
     dip_uuid = 'c0e37bab-e51e-482d-a066-a277330de9a7'
     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) == 1
     dip = dips[0]
     assert isinstance(dip, dict)
     assert dip['package_type'] == 'DIP'
     assert dip['uuid'] == dip_uuid
Ejemplo n.º 30
0
    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