async def chat_history_users(current_user: User = Depends( auth.get_current_user)): return { "data": { "users": ChatHistory.fetch_chat_users(current_user.get_bot()) } }
async def chat_history( sender: Text, current_user: User = Depends(auth.get_current_user) ): return { "data": { "history": list(ChatHistory.fetch_chat_history(current_user.bot, sender)) } }
async def chat_history_users(current_user: User = Depends( auth.get_current_user)): """ This function returns the list of the chatbot users """ return { "data": { "users": ChatHistory.fetch_chat_users(current_user.get_bot()) } }
async def chat_history(sender: Text, current_user: User = Depends(auth.get_current_user)): """ This function returns the chat history for a particular user of the chatbot """ return { "data": { "history": list(ChatHistory.fetch_chat_history(current_user.get_bot(), sender)) } }
def test_fetch_chat_history(self, mock_chat_history): history = ChatHistory.fetch_chat_history( sender="5e564fbcdcf0d5fad89e3acd", bot="tests") print(history) assert len(history) == 12 assert history[0]['event'] assert history[0]['time'] assert history[0]['date'] assert history[0]['text'] assert history[0]['is_exists'] == False or history[0]['is_exists'] assert history[0]['intent'] assert history[0]['confidence']
def test_fetch_chat_history(self, mock_chat_history): history = ChatHistory.fetch_chat_history( sender="5e564fbcdcf0d5fad89e3acd", bot="tests") print(history) assert len(history) == 12 assert history[0]["event"] assert history[0]["time"] assert history[0]["date"] assert history[0]["text"] assert history[0]["is_exists"] == False or history[0]["is_exists"] assert history[0]["intent"] assert history[0]["confidence"]
def test_fetch_chat_users_error(self, mock_get_tracker_and_domain): with pytest.raises(Exception): users = ChatHistory.fetch_chat_users(bot="tests") assert len(users) == 0
def test_fetch_chat_users_db_error(self, mock_mongo_processor): with pytest.raises(Exception): users = ChatHistory.fetch_chat_users(bot="tests") assert len(users) == 0
def test_conversation_steps(self, mock_chat_history): conversation_steps = ChatHistory.conversation_steps("tests") assert conversation_steps
async def conversation_time(current_user: User = Depends( auth.get_current_user)): """ This returns the duration of the chat that took place between the user and the chatbot """ return {"data": ChatHistory.conversation_time(current_user.get_bot())}
def test_conversation_time_empty(self, mock_chat_history_empty): conversation_time = ChatHistory.conversation_time("tests") assert not conversation_time
def test_visitor_hit_fallback(self, mock_chat_history): hit_fall_back = ChatHistory.visitor_hit_fallback("tests") assert hit_fall_back['fallback_count'] == 3 assert hit_fall_back['total_count'] == 31
def test_visitor_hit_fallback_error(self, mock_get_tracker_and_domain): with pytest.raises(Exception): hit_fall_back = ChatHistory.visitor_hit_fallback("tests") assert hit_fall_back['fallback_count'] == 0 assert hit_fall_back['total_count'] == 0
def test_fetch_chat_history_empty(self, mock_chat_history_empty): history = ChatHistory.fetch_chat_history(sender="123", bot="tests") assert len(history) == 0
def test_fetch_chat_history_error(self, mock_get_tracker_and_domain): with pytest.raises(Exception): history = ChatHistory.fetch_chat_history(sender="123", bot="tests") assert len(history) == 0
def test_visitor_hit_fallback_empty(self, mock_chat_history_empty): hit_fall_back = ChatHistory.visitor_hit_fallback("tests") assert hit_fall_back["fallback_count"] == 0 assert hit_fall_back["total_count"] == 0
async def visitor_hit_fallback(current_user: User = Depends( auth.get_current_user)): """ This function returns the number of times the bot hit a fallback (the bot admitting to not having a reply for a given text/query) for a given user """ return {"data": ChatHistory.visitor_hit_fallback(current_user.get_bot())}
async def visitor_hit_fallback(current_user: User = Depends( auth.get_current_user)): return {"data": ChatHistory.visitor_hit_fallback(current_user.get_bot())}
async def conversation_steps(current_user: User = Depends( auth.get_current_user)): """ This function returns the number of conversation steps that took place in the chat between the user and the chatbot """ return {"data": ChatHistory.conversation_steps(current_user.get_bot())}
def test_conversation_steps_empty(self, mock_chat_history_empy): conversation_steps = ChatHistory.conversation_steps("tests") assert not conversation_steps
def test_conversation_time(self, mock_chat_history): conversation_time = ChatHistory.conversation_time("tests") assert conversation_time
def test_fetch_chat_users_empty(self, mock_chat_history_empy): with pytest.raises(Exception): users = ChatHistory.fetch_chat_users(bot="tests") assert len(users) == 0
async def conversation_time(current_user: User = Depends( auth.get_current_user)): return {"data": ChatHistory.conversation_time(current_user.get_bot())}
def test_conversation_steps_error(self, mock_get_tracker_and_domain): with pytest.raises(Exception): conversation_steps = ChatHistory.conversation_steps("tests") assert not conversation_steps