def get_or_create_tracker_store(store: TrackerStore) -> None: slot_key = "location" slot_val = "Easter Island" tracker = store.get_or_create_tracker(UserMessage.DEFAULT_SENDER_ID) ev = SlotSet(slot_key, slot_val) tracker.update(ev) assert tracker.get_slot(slot_key) == slot_val store.save(tracker) again = store.get_or_create_tracker(UserMessage.DEFAULT_SENDER_ID) assert again.get_slot(slot_key) == slot_val
def test_tracker_store_storage_and_retrieval(store: TrackerStore): tracker = store.get_or_create_tracker("some-id") # the retrieved tracker should be empty assert tracker.sender_id == "some-id" # Action listen should be in there assert list(tracker.events) == [ActionExecuted(ACTION_LISTEN_NAME)] # lets log a test message intent = {"name": "greet", "confidence": 1.0} tracker.update(UserUttered("/greet", intent, [])) assert tracker.latest_message.intent.get("name") == "greet" store.save(tracker) # retrieving the same tracker should result in the same tracker retrieved_tracker = store.get_or_create_tracker("some-id") assert retrieved_tracker.sender_id == "some-id" assert len(retrieved_tracker.events) == 2 assert retrieved_tracker.latest_message.intent.get("name") == "greet" # getting another tracker should result in an empty tracker again other_tracker = store.get_or_create_tracker("some-other-id") assert other_tracker.sender_id == "some-other-id" assert len(other_tracker.events) == 1