def test_bulk_search_task_download_sync_timeout(bulk_search_task: BulkSearchTask): bulk_search_task.state = BulkSearchTaskState.IN_PROGRESS # download will never be ready bs_update_json = copy.deepcopy(bs_status_json) bs_update_json['results'][0]['state'] = 'IN_PROGRESS' bs_status_url = f'https://datalake.cert.orangecyberdefense.com/api/v2/mrti/bulk-search/tasks/' responses.add(responses.POST, bs_status_url, json=bs_update_json, status=200) with pytest.raises(TimeoutError): bulk_search_task.download_sync(timeout=0.2)
def test_bulk_search_task_download_sync_failed(bulk_search_task: BulkSearchTask): bulk_search_task.state = BulkSearchTaskState.IN_PROGRESS bs_update_json = copy.deepcopy(bs_status_json) bs_update_json['results'][0]['state'] = 'CANCELLED' bs_status_url = f'https://datalake.cert.orangecyberdefense.com/api/v2/mrti/bulk-search/tasks/' responses.add(responses.POST, bs_status_url, json=bs_update_json, status=200) with pytest.raises(BulkSearchFailedError) as err: bulk_search_task.download_sync() assert err.value.failed_state == BulkSearchTaskState.CANCELLED
async def test_bulk_search_task_download_async_timeout(bulk_search_task: BulkSearchTask): with responses.RequestsMock() as response_context: # pytest.mark.asyncio is not compatible with responses decorator bulk_search_task.state = BulkSearchTaskState.IN_PROGRESS # download will never be ready bs_update_json = copy.deepcopy(bs_status_json) bs_update_json['results'][0]['state'] = 'IN_PROGRESS' bs_status_url = f'https://datalake.cert.orangecyberdefense.com/api/v2/mrti/bulk-search/tasks/' response_context.add(responses.POST, bs_status_url, json=bs_update_json, status=200) loop = asyncio.get_event_loop() task = loop.create_task(bulk_search_task.download_async(timeout=0.2)) with pytest.raises(TimeoutError): await task
def test_bulk_search_task_download_sync(bulk_search_task: BulkSearchTask): bs_status_url = 'https://datalake.cert.orangecyberdefense.com/api/v2/mrti/bulk-search/tasks/' responses.add(responses.POST, bs_status_url, json=bs_status_json, status=200) bulk_search_task.state = BulkSearchTaskState.IN_PROGRESS # download is not ready yet task_uuid = bulk_search_task.uuid bs_download_url = f'https://datalake.cert.orangecyberdefense.com/api/v2/mrti/bulk-search/task/{task_uuid}/' expected_result = "bulk search download" responses.add(responses.GET, bs_download_url, json=expected_result, status=200) download_result = bulk_search_task.download_sync() assert download_result == expected_result