Exemplo n.º 1
0
 def test_retrieve_ongoing_session_at_question2(self):
     session = UserSession.open(self.pconnection)
     session.user = self.user
     session.question = self.question2
     session.save()
     session = UserSession.open(self.pconnection)
     self.assertEquals(session.respond("b"), str(self.question3))
     self.assertEquals(session.question, self.question3)
Exemplo n.º 2
0
    def test_close_ongoing_session_at_trigger(self):
        session = UserSession.open(self.pconnection)
        session.user = self.user
        session.question = self.question2
        session.save()
        session = UserSession.open(self.pconnection)
        self.assertEquals(session.respond("c"), str(self.question3))
        self.assertEquals(session.question, self.question3)

        self.assertEquals(session.respond("trigger 13 m"), str(self.question1))
        self.assertEquals(session.question, self.question1)
Exemplo n.º 3
0
    def test_reset_session_on_sending_trigger(self):
        session = UserSession.open(self.pconnection)
        session.respond("trigger m 16")
        
        session = UserSession.open(self.pconnection)
        self.assertEquals(session.question, self.question1)
        session.respond("trigger f 12")

        self.assertEquals(session.question, self.question1)
        session = UserSession.open(self.pconnection)
        session.respond("a")

        self.assertEquals(session.question, self.question2)
Exemplo n.º 4
0
 def test_less_than_required_choices_reminds_user(self):
     self.question1.max_choices = 2
     self.question1.save()
     session = UserSession.open(self.pconnection)
     session.respond("trigger m 16")
     self.assertEquals(session.question.max_choices, 2)
     error = session.respond("a")
     self.assertEquals(error, "err_less_thank_expected_choices")
Exemplo n.º 5
0
 def test_end_session_on_reaching_max_num_allowed_retries(self):
     session = UserSession.open(self.pconnection1)
     session.question = self.question1
     session.user = self.user
     session.respond("t")
     session.respond("t")
     session.respond("t")
     self.assertEquals(session.question, None)
Exemplo n.º 6
0
 def test_correct_response_to_question_sends_next_question(self):
     session = UserSession.open(self.pconnection)
     self.assertEquals(session.question, None)
     response1 = session.respond("text")
     self.assertEquals(session.question, self.question1)
     response2 = session.respond("a")
     self.assertEquals(response2, str(self.question2))
     self.assertEquals(session.question, self.question2)
Exemplo n.º 7
0
 def test_wrong_response_to_question_sends_error(self):
     session = UserSession.open(self.pconnection)
     self.assertEquals(session.question, None)
     response1 = session.respond("text")
     self.assertEquals(session.question, self.question1)
     response2 = session.respond("django")
     self.assertEquals(response2, "error_parsing_response")
     self.assertEquals(session.question, self.question1)
Exemplo n.º 8
0
 def test_close_session_on_last_answer(self):
     session = UserSession.open(self.pconnection)
     user = session.user
     user.save()
     session.user = user
     session.question = self.question3
     self.assertEquals(session.respond("c"), "thanks")
     self.assertEquals(session.question, None)
     self.assertEquals(session.user, None)
Exemplo n.º 9
0
    def test_user_interaction_is_saved_when_successful(self):
        initial_number_of_responses = len(UserResponse.objects.all())
        initial_number_of_users = len(User.objects.all())

        session = UserSession.open(self.pconnection1)
        session.respond("trigger 14 f")
        self.assertEquals(len(User.objects.all()), initial_number_of_users + 1)
        session.respond("a")
        self.assertEquals(len(UserResponse.objects.all()), initial_number_of_responses + 1)
Exemplo n.º 10
0
    def test_junk_message(self):
        backend = PersistantBackend(slug="MockBackend1")
        backend.save()
        reporter = Reporter(alias="ReporterName1")
        reporter.save()
        pconnection = PersistantConnection(backend=backend, reporter=reporter, identity="1001")
        pconnection.save()
        session = UserSession.open(pconnection)

        self.assertEquals(session.respond("junk"), TRIGGER_INCORRECT_MESSAGE)
Exemplo n.º 11
0
 def test_respond_with_first_question_on_new_session_for_any_message(self):
     session = UserSession.open(self.pconnection)
     self.assertEquals(session.respond("text"), str(self.question1))
Exemplo n.º 12
0
 def test_open_new_session(self):
     session = UserSession.open(self.pconnection)
     self.assertEquals(session.question, None)
Exemplo n.º 13
0
 def test_user_location_from_registration(self):
     session = UserSession.open(self.pconnection)
     session.respond("trigger 14 f")
     latest_user = User.objects.all().order_by("-id")[0]
     self.assertEquals(latest_user.governorate, 3)
     self.assertEquals(latest_user.district, 4)
Exemplo n.º 14
0
 def test_user_demographics_saved_when_present(self):
     session = UserSession.open(self.pconnection1)
     session.respond("trigger 13 f")
     latest_user = User.objects.all().order_by("-id")[0]
     self.assertEquals(latest_user.age, 13)
     self.assertEquals(latest_user.gender, "f")
Exemplo n.º 15
0
 def test_junk_message(self):
     session = UserSession.open(self.pconnection)
     self.assertEquals(session.respond('junk'), TRIGGER_INCORRECT_MESSAGE )
Exemplo n.º 16
0
 def test_recreate_user_if_demographic_data_changes(self):
     session = UserSession.open(self.pconnection)
     session.respond("trigger m 16")
     session.respond("trigger m 12")
     self.assertEquals(len(User.objects.all()), 2)
Exemplo n.º 17
0
 def test_respond_with_first_question_on_new_session_for_any_message(self):
     session = UserSession.open(self.pconnection)
     user = session.user
     user.save()
     self.assertEquals(session.respond("trigger m 16"), str(self.question1))