Ejemplo n.º 1
0
async def chat_history(
    sender: Text, month: HistoryMonth = 1,current_user: User = Depends(auth.get_current_user)
):
    """
    Fetches the list of conversation with the agent by particular user
    """
    history, message = ChatHistory.fetch_chat_history(current_user.get_bot(), sender, month)
    return {"data": {"history": list(history)}, "message": message}
Ejemplo n.º 2
0
    def test_fetch_chat_history(self, monkeypatch):
        def events(*args, **kwargs):
            json_data = json.load(
                open("tests/testing_data/history/conversation.json"))
            return json_data['events'], None

        monkeypatch.setattr(ChatHistory, "fetch_user_history", events)

        history, message = ChatHistory.fetch_chat_history(
            sender="5e564fbcdcf0d5fad89e3acd", bot="tests")
        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"]
        assert message is None
Ejemplo n.º 3
0
 def test_fetch_chat_history_empty(self, mock_mongo_client_empty):
     history, message = ChatHistory.fetch_chat_history(sender="123",
                                                       bot="tests")
     assert len(history) == 0
     assert message is None
Ejemplo n.º 4
0
 def test_fetch_chat_history_error(self, mock_mongo_processor):
     with pytest.raises(Exception):
         history, message = ChatHistory.fetch_chat_history(sender="123",
                                                           bot="tests")
         assert len(history) == 0
         assert message is None