示例#1
0
def stored_request_real(redis_client):
    new_req = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    new_req.timestamps['VALIDATED'] = 1449523225
    redis_client.hset(
        AcquisitionRequestStore.REDIS_HASH_NAME,
        AcquisitionRequestStore.get_request_redis_id(TEST_ACQUISITION_REQ),
        str(new_req))
    return new_req
def stored_request_real(redis_client):
    new_req = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    new_req.timestamps['VALIDATED'] = 1449523225
    redis_client.hset(
        AcquisitionRequestStore.REDIS_HASH_NAME,
        AcquisitionRequestStore.get_request_redis_id(TEST_ACQUISITION_REQ),
        str(new_req))
    return new_req
示例#3
0
def test_metadata_callback_failed(client, fake_time, mock_req_store, req_store_get):
    response = client.post(
        path=METADATA_PARSER_CALLBACK_PATH.format(req_id=TEST_ACQUISITION_REQ.id),
        data={'state': 'FAILED'})

    assert response.status == falcon.HTTP_200
    updated_request = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    updated_request.state = 'ERROR'
    updated_request.timestamps['ERROR'] = FAKE_TIMESTAMP
    mock_req_store.put.assert_called_with(updated_request)
示例#4
0
def test_metadata_callback_failed(client, fake_time, mock_req_store,
                                  req_store_get):
    response = client.post(path=METADATA_PARSER_CALLBACK_PATH.format(
        req_id=TEST_ACQUISITION_REQ.id),
                           data={'state': 'FAILED'})

    assert response.status == falcon.HTTP_200
    updated_request = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    updated_request.state = 'ERROR'
    updated_request.timestamps['ERROR'] = FAKE_TIMESTAMP
    mock_req_store.put.assert_called_with(updated_request)
示例#5
0
def test_downloader_callback_failed(client, fake_time, mock_req_store, req_store_get):
    failed_callback_req = dict(TEST_DOWNLOAD_CALLBACK)
    failed_callback_req['state'] = 'ERROR'

    response = client.post(
        path=DOWNLOAD_CALLBACK_PATH.format(req_id=TEST_ACQUISITION_REQ.id),
        data=failed_callback_req)

    assert response.status == falcon.HTTP_200

    updated_request = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    updated_request.state = 'ERROR'
    updated_request.timestamps['ERROR'] = FAKE_TIMESTAMP
    mock_req_store.put.assert_called_with(updated_request)
示例#6
0
def test_downloader_callback_failed(client, fake_time, mock_req_store,
                                    req_store_get):
    failed_callback_req = dict(TEST_DOWNLOAD_CALLBACK)
    failed_callback_req['state'] = 'ERROR'

    response = client.post(
        path=DOWNLOAD_CALLBACK_PATH.format(req_id=TEST_ACQUISITION_REQ.id),
        data=failed_callback_req)

    assert response.status == falcon.HTTP_200

    updated_request = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    updated_request.state = 'ERROR'
    updated_request.timestamps['ERROR'] = FAKE_TIMESTAMP
    mock_req_store.put.assert_called_with(updated_request)
示例#7
0
def test_get_from_old_base(req_store, redis_mock):
    old_request = dict(TEST_ACQUISITION_REQ_JSON)
    old_request.update({'unnecessary_field': 'blablabla'})
    redis_mock.hgetall.return_value = {
        b'fake-org-uuid:fake-id': json.dumps(old_request).encode()
    }

    acquisition_req = req_store.get('fake-id')

    assert acquisition_req == AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)
    redis_mock.hgetall.assert_called_with(
        AcquisitionRequestStore.REDIS_HASH_NAME)
示例#8
0
def test_get_requests_for_org(org_ids, acquisition_requests, das_api, client,
                              mock_req_store):
    das_api.acquisition_res._org_checker = MagicMock()
    mock_req_store.get_for_org.return_value = acquisition_requests

    response = client.get(path=ACQUISITION_PATH,
                          query_string='orgs=' + ','.join(org_ids))

    returned_requests = [
        AcquisitionRequest(**req_json) for req_json in response.json
    ]
    assert response.status == falcon.HTTP_200
    assert returned_requests == acquisition_requests * len(org_ids)
    assert mock_req_store.get_for_org.call_args_list == [
        call(id) for id in org_ids
    ]
示例#9
0
def test_get_requests(req_store_real, das):
    test_requests = [copy.deepcopy(TEST_ACQUISITION_REQ) for _ in range(3)]
    test_requests[1].id = 'qzawx'
    test_requests[2].orgUUID = 'some-other-org-uuid'
    for test_request in test_requests:
        req_store_real.put(test_request)

    response = requests.get(urljoin(das.url, ACQUISITION_PATH),
                            params={'orgs': TEST_ACQUISITION_REQ.orgUUID},
                            headers={'Authorization': TEST_AUTH_HEADER})

    assert response.status_code == 200
    returned_requests = [
        AcquisitionRequest(**req_json) for req_json in response.json()
    ]
    assert set(returned_requests) == set(test_requests[:-1])
示例#10
0
TEST_DOWNLOAD_REQUEST = {
    'orgUUID': TEST_ORG_UUID,
    'publicRequest': True,
    'source': 'http://some-fake-url',
    'category': 'other',
    'title': 'My test download',
}

TEST_ACQUISITION_REQ_JSON = dict(TEST_DOWNLOAD_REQUEST)
TEST_ACQUISITION_REQ_JSON.update({
    'state': 'VALIDATED',
    'id': 'fake-id',
    'timestamps': {},
})

TEST_ACQUISITION_REQ = AcquisitionRequest(**TEST_ACQUISITION_REQ_JSON)

TEST_ACQUISITION_REQ_STR = str(TEST_ACQUISITION_REQ)

TEST_DOWNLOAD_CALLBACK = {
    'id': TEST_ACQUISITION_REQ_JSON['id'],
    'state': 'DONE',
    'savedObjectId': 'fake-guid/000000_1',
    'objectStoreId': 'hdfs://some-fake-hdfs-path',
}

TEST_METADATA_CALLBACK = {'state': 'DONE'}

TEST_VCAP_SERVICES_TEMPLATE = """
 {{
  "redis28": [
示例#11
0
def test_get_request(das_api, client_swagger, req_store_get):
    das_api.request_management_res._org_checker = MagicMock()
    acquisition_request = client_swagger.rest.getRequest(
        req_id=TEST_ACQUISITION_REQ.id).result()
    assert AcquisitionRequest(
        **acquisition_request.__dict__) == TEST_ACQUISITION_REQ