Exemple #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})
Exemple #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})
Exemple #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})
Exemple #4
0
def test_metadata_callback(req_store_real, das):
    req_store_real.put(TEST_ACQUISITION_REQ)
    req_id = TEST_ACQUISITION_REQ.id

    response = requests.post(get_metadata_callback_url(das.url, req_id=req_id),
                             json=TEST_METADATA_CALLBACK,
                             headers={'Authorization': TEST_AUTH_HEADER})

    assert response.status_code == 200
    assert req_store_real.get(req_id).state == 'FINISHED'
Exemple #5
0
def test_metadata_callback(req_store_real, das):
    req_store_real.put(TEST_ACQUISITION_REQ)
    req_id = TEST_ACQUISITION_REQ.id

    response = requests.post(
        get_metadata_callback_url(das.url, req_id=req_id),
        json=TEST_METADATA_CALLBACK,
        headers={'Authorization': TEST_AUTH_HEADER})

    assert response.status_code == 200
    assert req_store_real.get(req_id).state == 'FINISHED'
Exemple #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})
Exemple #7
0
def test_get_metadata_callback_url():
    callback_url = get_metadata_callback_url('https://some-test-das-url', 'some-test-id')
    assert callback_url == 'https://some-test-das-url/v1/das/callback/metadata/some-test-id'
Exemple #8
0
def test_get_metadata_callback_url():
    callback_url = get_metadata_callback_url('https://some-test-das-url',
                                             'some-test-id')
    assert callback_url == 'https://some-test-das-url/v1/das/callback/metadata/some-test-id'