Пример #1
0
def test_download_callback(req_store_real, das, metadata_parser_imposter):
    # arrange
    req_store_real.put(TEST_ACQUISITION_REQ)
    req_id = TEST_ACQUISITION_REQ.id

    # act
    response = requests.post(get_download_callback_url(das.url, req_id=req_id),
                             json=TEST_DOWNLOAD_CALLBACK,
                             headers={'Authorization': TEST_AUTH_HEADER})

    # assert
    assert response.status_code == 200
    assert req_store_real.get(req_id).state == 'DOWNLOADED'

    request_to_imposter = metadata_parser_imposter.wait_for_requests()[0]
    proper_metadata_req = {
        'orgUUID': TEST_ACQUISITION_REQ.orgUUID,
        'publicRequest': TEST_ACQUISITION_REQ.publicRequest,
        'source': TEST_ACQUISITION_REQ.source,
        'category': TEST_ACQUISITION_REQ.category,
        'title': TEST_ACQUISITION_REQ.title,
        'id': req_id,
        'idInObjectStore': TEST_DOWNLOAD_CALLBACK['savedObjectId'],
        'callbackUrl': get_metadata_callback_url('https://das.example.com',
                                                 req_id)
    }

    assert json.loads(request_to_imposter.body) == proper_metadata_req
    assert dict_is_part_of(request_to_imposter.headers,
                           {'authorization': TEST_AUTH_HEADER})
Пример #2
0
def test_uploader_request(req_store_real, das, metadata_parser_imposter):
    # arrange
    test_uploader_req = dict(TEST_DOWNLOAD_REQUEST)
    test_uploader_req.update({
        'idInObjectStore': 'fake-guid/000000_1',
        'objectStoreId': 'hdfs://some-fake-hdfs-path',
    })

    # act
    response = requests.post(
        urljoin(das.url, UPLOADER_REQUEST_PATH),
        json=test_uploader_req,
        headers={'Authorization': TEST_AUTH_HEADER})

    # assert
    assert response.status_code == 200
    stored_request = req_store_real.get_for_org(test_uploader_req['orgUUID'])[0]
    assert stored_request.state == 'DOWNLOADED'

    request_to_imposter = metadata_parser_imposter.wait_for_requests()[0]
    proper_metadata_req = {
        'orgUUID': TEST_ACQUISITION_REQ.orgUUID,
        'publicRequest': TEST_ACQUISITION_REQ.publicRequest,
        'source': TEST_ACQUISITION_REQ.source,
        'category': TEST_ACQUISITION_REQ.category,
        'title': TEST_ACQUISITION_REQ.title,
        'id': stored_request.id,
        'idInObjectStore': test_uploader_req['idInObjectStore'],
        'callbackUrl': get_metadata_callback_url('https://das.example.com', stored_request.id)
    }

    assert json.loads(request_to_imposter.body) == proper_metadata_req
    assert dict_is_part_of(request_to_imposter.headers, {'authorization': TEST_AUTH_HEADER})
Пример #3
0
def test_download_callback(req_store_real, das, metadata_parser_imposter):
    # arrange
    req_store_real.put(TEST_ACQUISITION_REQ)
    req_id = TEST_ACQUISITION_REQ.id

    # act
    response = requests.post(
        get_download_callback_url(das.url, req_id=req_id),
        json=TEST_DOWNLOAD_CALLBACK,
        headers={'Authorization': TEST_AUTH_HEADER})

    # assert
    assert response.status_code == 200
    assert req_store_real.get(req_id).state == 'DOWNLOADED'

    request_to_imposter = metadata_parser_imposter.wait_for_requests()[0]
    proper_metadata_req = {
        'orgUUID': TEST_ACQUISITION_REQ.orgUUID,
        'publicRequest': TEST_ACQUISITION_REQ.publicRequest,
        'source': TEST_ACQUISITION_REQ.source,
        'category': TEST_ACQUISITION_REQ.category,
        'title': TEST_ACQUISITION_REQ.title,
        'id': req_id,
        'idInObjectStore': TEST_DOWNLOAD_CALLBACK['savedObjectId'],
        'callbackUrl': get_metadata_callback_url('https://das.example.com', req_id)
    }

    assert json.loads(request_to_imposter.body) == proper_metadata_req
    assert dict_is_part_of(request_to_imposter.headers, {'authorization': TEST_AUTH_HEADER})
Пример #4
0
def test_acquisition_request(das_client, req_store_real, downloader_imposter):
    resp_object = das_client.rest.submitAcquisitionRequest(
        body=TEST_DOWNLOAD_REQUEST,
        _request_options={'headers': {'authorization': TEST_AUTH_HEADER}}).result()

    assert req_store_real.get(resp_object.id).state == 'VALIDATED'
    request_to_imposter = downloader_imposter.wait_for_requests()[0]
    assert json.loads(request_to_imposter.body) == {
        'source': TEST_DOWNLOAD_REQUEST['source'],
        'callback': get_download_callback_url('https://das.example.com', resp_object.id)
    }
    assert dict_is_part_of(request_to_imposter.headers, {'authorization': TEST_AUTH_HEADER})
Пример #5
0
def test_acquisition_request(das_client, req_store_real, downloader_imposter):
    resp_object = das_client.rest.submitAcquisitionRequest(
        body=TEST_DOWNLOAD_REQUEST,
        _request_options={
            'headers': {
                'authorization': TEST_AUTH_HEADER
            }
        }).result()

    assert req_store_real.get(resp_object.id).state == 'VALIDATED'
    request_to_imposter = downloader_imposter.wait_for_requests()[0]
    assert json.loads(request_to_imposter.body) == {
        'source':
        TEST_DOWNLOAD_REQUEST['source'],
        'callback':
        get_download_callback_url('https://das.example.com', resp_object.id)
    }
    assert dict_is_part_of(request_to_imposter.headers,
                           {'authorization': TEST_AUTH_HEADER})
Пример #6
0
def test_uploader_request(req_store_real, das, metadata_parser_imposter):
    # arrange
    test_uploader_req = dict(TEST_DOWNLOAD_REQUEST)
    test_uploader_req.update({
        'idInObjectStore': 'fake-guid/000000_1',
        'objectStoreId': 'hdfs://some-fake-hdfs-path',
    })

    # act
    response = requests.post(urljoin(das.url, UPLOADER_REQUEST_PATH),
                             json=test_uploader_req,
                             headers={'Authorization': TEST_AUTH_HEADER})

    # assert
    assert response.status_code == 200
    stored_request = req_store_real.get_for_org(
        test_uploader_req['orgUUID'])[0]
    assert stored_request.state == 'DOWNLOADED'

    request_to_imposter = metadata_parser_imposter.wait_for_requests()[0]
    proper_metadata_req = {
        'orgUUID':
        TEST_ACQUISITION_REQ.orgUUID,
        'publicRequest':
        TEST_ACQUISITION_REQ.publicRequest,
        'source':
        TEST_ACQUISITION_REQ.source,
        'category':
        TEST_ACQUISITION_REQ.category,
        'title':
        TEST_ACQUISITION_REQ.title,
        'id':
        stored_request.id,
        'idInObjectStore':
        test_uploader_req['idInObjectStore'],
        'callbackUrl':
        get_metadata_callback_url('https://das.example.com', stored_request.id)
    }

    assert json.loads(request_to_imposter.body) == proper_metadata_req
    assert dict_is_part_of(request_to_imposter.headers,
                           {'authorization': TEST_AUTH_HEADER})