示例#1
0
 def test_failed_and_not_abandoned(self):
     profile = UserProfile(validated=True)
     event = FailedPrompt(
         phone_number="123456789",
         user_profile=profile,
         prompt=DRILL.prompts[2],
         drill_instance_id=uuid.uuid4(),
         response="b",
         abandoned=False,
     )
     dialog_state = DialogState(
         "123456789",
         seq="0",
         user_profile=profile,
         current_drill=DRILL,
         drill_instance_id=event.drill_instance_id,
         current_prompt_state=PromptState(DRILL.prompts[2].slug,
                                          start_time=NOW),
     )
     event.apply_to(dialog_state)
     self.assertEqual(
         PromptState(
             slug=DRILL.prompts[2].slug,
             start_time=NOW,
             last_response_time=event.created_time,
             failures=1,
         ),
         dialog_state.current_prompt_state,
     )
示例#2
0
 def test_user_revalidated(self):
     profile = UserProfile(validated=True, is_demo=True)
     dialog_state = DialogState(
         "123456789",
         "0",
         user_profile=profile,
         current_drill=DRILL,
         drill_instance_id=uuid.uuid4(),
         current_prompt_state=PromptState(slug=DRILL.prompts[0].slug,
                                          start_time=NOW),
     )
     event = UserValidated(
         phone_number="123456789",
         user_profile=profile,
         code_validation_payload=CodeValidationPayload(
             valid=True, is_demo=False, account_info={"foo": "bar"}),
     )
     event.apply_to(dialog_state)
     self.assertTrue(dialog_state.user_profile.validated)
     self.assertFalse(dialog_state.user_profile.is_demo)
     self.assertIsNone(dialog_state.current_drill)
     self.assertIsNone(dialog_state.current_prompt_state)
     self.assertIsNone(dialog_state.drill_instance_id)
     self.assertEqual({"foo": "bar"},
                      dialog_state.user_profile.account_info)
示例#3
0
 def _set_current_prompt(self, prompt_index: int, should_advance: bool):
     self.dialog_state.current_drill = self.drill
     underlying_prompt = self.drill.prompts[prompt_index]
     prompt = Mock(wraps=underlying_prompt)
     prompt.slug = underlying_prompt.slug
     prompt.messages = underlying_prompt.messages
     prompt.response_user_profile_key = underlying_prompt.response_user_profile_key
     prompt.max_failures = underlying_prompt.max_failures
     prompt.should_advance_with_answer.return_value = should_advance
     self.drill.prompts[prompt_index] = prompt
     self.dialog_state.current_prompt_state = PromptState(
         slug=prompt.slug, start_time=self.now)
示例#4
0
 def test_advanced_to_next_prompt(self):
     profile = UserProfile(validated=True)
     event = AdvancedToNextPrompt(
         phone_number="123456789",
         user_profile=profile,
         prompt=DRILL.prompts[1],
         drill_instance_id=uuid.uuid4(),
     )
     dialog_state = DialogState(
         "123456789",
         seq="0",
         user_profile=profile,
         current_drill=DRILL,
         drill_instance_id=event.drill_instance_id,
         current_prompt_state=PromptState(DRILL.prompts[0].slug,
                                          start_time=NOW),
     )
     event.apply_to(dialog_state)
     self.assertEqual(
         PromptState(DRILL.prompts[1].slug, start_time=event.created_time),
         dialog_state.current_prompt_state,
     )
示例#5
0
 def test_drill_completed(self):
     profile = UserProfile(validated=False)
     event = DrillCompleted("123456789",
                            user_profile=profile,
                            drill_instance_id=uuid.uuid4())
     dialog_state = DialogState(
         "123456789",
         seq="0",
         user_profile=profile,
         current_drill=DRILL,
         drill_instance_id=event.drill_instance_id,
         current_prompt_state=PromptState(DRILL.prompts[-1].slug,
                                          start_time=NOW),
     )
     event.apply_to(dialog_state)
     self.assertIsNone(dialog_state.drill_instance_id)
     self.assertIsNone(dialog_state.current_prompt_state)
     self.assertIsNone(dialog_state.current_drill)
示例#6
0
 def test_completed_and_not_stored(self):
     profile = UserProfile(validated=True)
     event = CompletedPrompt(
         "123456789",
         user_profile=profile,
         prompt=DRILL.prompts[0],
         drill_instance_id=uuid.uuid4(),
         response="go",
     )
     dialog_state = DialogState(
         "123456789",
         "0",
         user_profile=profile,
         current_drill=DRILL,
         current_prompt_state=PromptState(DRILL.prompts[0].slug, NOW),
     )
     event.apply_to(dialog_state)
     self.assertEqual(profile, dialog_state.user_profile)
     self.assertIsNone(dialog_state.current_prompt_state)
示例#7
0
 def test_drill_started(self):
     profile = UserProfile(validated=True)
     event = DrillStarted(
         phone_number="123456789",
         user_profile=profile,
         drill=DRILL,
         first_prompt=DRILL.prompts[0],
     )
     dialog_state = DialogState(phone_number="123456789",
                                seq="0",
                                user_profile=profile)
     event.apply_to(dialog_state)
     self.assertEqual(DRILL, dialog_state.current_drill)
     self.assertEqual(
         PromptState(slug=DRILL.prompts[0].slug,
                     start_time=event.created_time),
         dialog_state.current_prompt_state,
     )
     self.assertEqual(event.drill_instance_id,
                      dialog_state.drill_instance_id)
示例#8
0
    def test_opted_out_during_drill(self):
        profile = UserProfile(validated=True)
        event = OptedOut("123456789",
                         user_profile=profile,
                         drill_instance_id=uuid.uuid4())
        dialog_state = DialogState(
            "123456789",
            seq="0",
            user_profile=profile,
            current_drill=DRILL,
            drill_instance_id=event.drill_instance_id,
            current_prompt_state=PromptState(DRILL.prompts[-1].slug,
                                             start_time=NOW),
        )

        self.assertFalse(profile.opted_out)
        event.apply_to(dialog_state)
        self.assertTrue(profile.opted_out)
        self.assertIsNone(dialog_state.drill_instance_id)
        self.assertIsNone(dialog_state.current_prompt_state)
        self.assertIsNone(dialog_state.current_drill)
示例#9
0
 def test_completed_and_stored(self):
     profile = UserProfile(validated=True)
     event = CompletedPrompt(
         phone_number="123456789",
         user_profile=profile,
         prompt=DRILL.prompts[1],
         drill_instance_id=uuid.uuid4(),
         response="7",
     )
     dialog_state = DialogState(
         phone_number="123456789",
         seq="0",
         user_profile=profile,
         current_drill=DRILL,
         current_prompt_state=PromptState(slug=DRILL.prompts[0].slug,
                                          start_time=NOW),
     )
     event.apply_to(dialog_state)
     self.assertEqual(UserProfile(validated=True, self_rating_1="7"),
                      dialog_state.user_profile)
     self.assertIsNone(dialog_state.current_prompt_state)
示例#10
0
 def _set_current_prompt(self, prompt_index: int, drill: Optional[Drill] = None):
     if not drill:
         drill = self.drill
     self.dialog_state.current_drill = drill
     prompt = drill.prompts[prompt_index]
     self.dialog_state.current_prompt_state = PromptState(slug=prompt.slug, start_time=self.now)
示例#11
0
 def apply_to(self, dialog_state: DialogState) -> None:
     dialog_state.current_drill = self.drill
     dialog_state.drill_instance_id = self.drill_instance_id
     dialog_state.current_prompt_state = PromptState(
         slug=self.first_prompt.slug, start_time=self.created_time)
示例#12
0
 def apply_to(self, dialog_state: DialogState) -> None:
     dialog_state.current_prompt_state = PromptState(
         slug=self.prompt.slug, start_time=self.created_time)