Exemplo n.º 1
0
    def post(self):
        """Create a request to ingest a BagIt resource"""
        upload_url = request.json['uploadUrl']
        callback_url = request.json.get('callbackUrl')
        self.validate_urls(callback_url, upload_url)

        ingest_request_id = str(uuid.uuid4())
        logger.debug('ingest_request_id=%r', ingest_request_id)

        create_ingest_progress(
            IngestProgress(ingest_request_id, upload_url, callback_url),
            app.config['DYNAMODB_RESOURCE'],
            app.config['DYNAMODB_TABLE_NAME'])

        ingest_request_id = send_new_ingest_request(
            sns_client=app.config['SNS_CLIENT'],
            topic_arn=app.config['SNS_TOPIC_ARN'],
            ingest_request_id=ingest_request_id,
            upload_url=upload_url,
            callback_url=callback_url
        )

        # Construct the URL where the user will be able to get the status
        # of their ingest request.
        location = api.url_for(
            IngestResource,
            id=ingest_request_id
        )

        # Now we set the Location response header.  There's no way to do this
        # without constructing our own Response object, so that's what we do
        # here.  See https://stackoverflow.com/q/25860304/1558022
        resp = make_response('', 202)
        resp.headers['Location'] = location
        return resp
Exemplo n.º 2
0
def test_creates_ingest_progress_with_callback(dynamodb_resource, table_name,
                                               guid):
    create_ingest_progress(IngestProgress(guid, bag_url, callback_url),
                           dynamodb_resource, table_name)

    expected_item = initialised_progress_item(guid, bag_url, callback_url)

    assert_stored_progress(expected_item, dynamodb_resource, table_name)
Exemplo n.º 3
0
def test_raises_if_id_is_already_saved(dynamodb_resource, table_name, guid):
    with pytest.raises(
            ValueError,
            match=f"Cannot create IngestProgress, id already exists '{guid}'."
    ):
        create_ingest_progress(IngestProgress(guid, bag_url, callback_url),
                               dynamodb_resource, table_name)

        create_ingest_progress(IngestProgress(guid, bag_url, callback_url),
                               dynamodb_resource, table_name)
Exemplo n.º 4
0
def test_raises_for_all_other_errors(dynamodb_resource, guid):
    with pytest.raises(ClientError) as err:
        create_ingest_progress(IngestProgress(guid, bag_url, callback_url),
                               dynamodb_resource=dynamodb_resource,
                               table_name='DoesNotExist')
    assert err.value.response['Error']['Code'] == 'ResourceNotFoundException'
Exemplo n.º 5
0
def test_raises_if_id_is_invalid(dynamodb_resource, table_name):
    with pytest.raises(ValueError, match='is not a valid ID'):
        create_ingest_progress(IngestProgress("", bag_url, callback_url),
                               dynamodb_resource, table_name)