def setUp(self): main_session = BotSessionFactory(is_main=True) BotQuestionFactory( bot_session=main_session, question= "Hello I am Isabot. I am your consultant to help you to invest in a post-labour future.", ) BotQuestionFactory(bot_session=main_session, question="Hello, how are you?", position=1) BotQuestionFactory( bot_session=main_session, question="Do you work in the creative field?", alternative_question="Imagine that you do work in the field, ok?", accepted_keywords= "ok,yes,yep,yo,of course,certainly,I do,I work in the creative field", position=2, ) BotQuestionFactory( bot_session=main_session, question= "As a creative, do you work in (A) product design, (B) graphic design, (C) web design, (D) architecture or (E) art? Give me the letter of your choice.", alternative_question= "I am sorry, could you please specify between (A) product design, (B) graphic design, (C) web design, (D) architecture or (E) art by just typing in the letter in brackets?", accepted_keywords="A,B,C,D,E", position=3, ) BotSessionFactory(name="A session", entry_keyword="A") BotQuestionFactory( bot_session=main_session, question="Would you be up for that?", ) BotQuestionFactory( bot_session=main_session, question="Do you have any further questions?", alternative_question= "Great, thank you, it was nice talking to you. Your session has ended. Goodbye.", accepted_keywords="yeah,yes,yo,of course,sure", position=1, ) BotSessionFactory(name="B session", entry_keyword="B") BotQuestionFactory( bot_session=main_session, question="Would you be up for that?", ) BotQuestionFactory( bot_session=main_session, question="Do you have any further questions?", alternative_question= "Great, thank you, it was nice talking to you. Your session has ended. Goodbye.", accepted_keywords="yeah,yes,yo,of course,sure", position=1, )
def test_get_conversation_returns_error_if_no_question_for_bot_session( self): url = f"{self.live_server_url}/isabot/conversation/" response = requests.get(url) BotSessionFactory(is_main=True) self.assertEqual(response.status_code, 404)
def test_get_conversation_200(self): # GIVEN botsession = BotSessionFactory(is_main=True) BotQuestionFactory(bot_session=botsession, question="First question") # WHEN url = f"{self.live_server_url}/isabot/conversation/" response = requests.get(url) self.assertEqual(response.status_code, 200)
def test_get_conversation_creates_a_session(self): # GIVEN botsession = BotSessionFactory(is_main=True) BotQuestionFactory(bot_session=botsession, question="First question") # WHEN url = f"{self.live_server_url}/isabot/conversation/" response = requests.get(url) self.assertTrue(response.cookies._find("sessionid") != "")
def test_get_conversation_saves_current_question_on_conversation(self): # GIVEN botsession = BotSessionFactory(is_main=True) BotQuestionFactory(bot_session=botsession, question="First question") # WHEN url = f"{self.live_server_url}/isabot/conversation/" requests.get(url) # THEN conversation = Conversation.objects.first() self.assertEqual("First question", conversation.last_question)
def test_get_conversation_creates_conversation_object(self): # GIVEN botsession = BotSessionFactory(is_main=True) BotQuestionFactory(bot_session=botsession, question="First question") # WHEN url = f"{self.live_server_url}/isabot/conversation/" response = requests.get(url) conversation = Conversation.objects.first() session_id = response.cookies._find("sessionid") self.assertTrue(conversation is not None) self.assertEquals(session_id, conversation.session_id)
def test_get_conversation_response_keys(self): # GIVEN botsession = BotSessionFactory(is_main=True) BotQuestionFactory(bot_session=botsession, question="First question") # WHEN url = f"{self.live_server_url}/isabot/conversation/" response = requests.get(url) # THEN response_data = response.json() self.assertEqual(4, len(response_data)) self.assertTrue("text" in response_data) self.assertTrue("botSessionId" in response_data) self.assertTrue("questionId" in response_data) self.assertTrue("conversationId" in response_data)
def test_get_conversation_returns_correct_values(self): # GIVEN botsession = BotSessionFactory(is_main=True) question = BotQuestionFactory(bot_session=botsession, question="First question") # WHEN url = f"{self.live_server_url}/isabot/conversation/" response = requests.get(url) # THEN conversation = Conversation.objects.first() self.assertEqual("First question", response.json().get("text")) self.assertEqual(str(botsession.id), response.json().get("botSessionId")) self.assertEqual(str(question.id), response.json().get("questionId")) self.assertEqual(str(conversation.id), response.json().get("conversationId"))