Exemplo n.º 1
0
 def test_download_csv(self):
     file_path, temp_path = Utility.download_csv(
         {"conversation_data": [{
             "test": "test_val"
         }]}, None)
     assert file_path.endswith(".csv")
     assert "tmp" in str(temp_path).lower()
Exemplo n.º 2
0
async def download_conversations(
    background_tasks: BackgroundTasks,
    request: HistoryQuery = HistoryQuery(),
    collection: str = Depends(Authentication.authenticate_and_get_collection),
):
    """Downloads conversation history of the bot, for the specified months."""
    conversation_data, message = HistoryProcessor.flatten_conversations(
        collection, request.month, request.sort_by_date)
    file, temp_path = Utility.download_csv(conversation_data, message)
    response = FileResponse(file,
                            filename=os.path.basename(file),
                            background=background_tasks)
    response.headers[
        "Content-Disposition"] = "attachment; filename=" + os.path.basename(
            file)
    background_tasks.add_task(Utility.delete_directory, temp_path)
    return response
Exemplo n.º 3
0
 def test_download_csv_error_message(self):
     with pytest.raises(AppException) as e:
         Utility.download_csv({"conversation_data": []}, "error_message")
     assert str(e).__contains__("error_message")
Exemplo n.º 4
0
 def test_download_csv_no_data(self):
     with pytest.raises(AppException) as e:
         Utility.download_csv({"conversation_data": []}, None)
     assert str(e).__contains__("No data available")