Exemplo n.º 1
0
 def test_case_statements_with_no_response(self):
     """
     case() should return False if none of the callbacks return True
     """
     
     case_statement = case(
         (lambda ms, session_store: False, prompt("1")),
         (lambda ms, session_store: False, prompt("2")),
         (lambda ms, session_store: False, prompt("3")),
     )
     
     # advance
     case_statement.next()
     self.assertFalse(any(case_statement.send((MenuSystem(), {}))))
Exemplo n.º 2
0
 def test_coroutines_returning_nothing(self):
     """
     the client should forward to the next coroutine if a given coroutine 
     does not return a message to return to the client
     """
     
     client = TestingClient("test_client")
     menu = MenuSystem(
         prompt("What is your age?", validator=integer),
         case(
             (lambda ms, session: False, prompt("This should never be displayed"))
         ),
         end("Goodbye!")
     )
     
     client.answer("*120*USSD_SHORTCODE#", menu)
     client.answer("29", menu)
     
     self.assertEquals(client.outbox, [
         ("What is your age?", False),
         ("Goodbye!", True)
     ])
Exemplo n.º 3
0
 def test_case_statements(self):
     """
     case() accepts a list of (callback, coroutine) tuples. 
     The callback is given the instance of the menu system and the session 
     store return True or False. 
     """
     
     def test_one(menu_system, session_store):
         return "one" in session_store
     
     def test_two(menu_system, session_store):
         return "two" in session_store
     
     def test_three(menu_system, session_store):
         return "three" in session_store
     
     case_statement = case(
         (test_one, prompt("test one")),
         (test_two, prompt("test two")),
         (test_three, prompt("test three"))
     )
     
     # the first two prompts shouldn't respond with this session store
     session_store = {
         "three": "exists"
     }
     
     # advance
     case_statement.next()
     response_text, end_of_session = case_statement.send(
                                         (MenuSystem(), session_store))
     self.assertEquals(response_text, "test three")
     self.assertFalse(end_of_session)
     
     # advance
     case_statement.next()
     validated_answer = case_statement.send("ok")
     self.assertEquals(validated_answer, "ok")
Exemplo n.º 4
0
     'English',
     'Zulu',
     'Afrikaans',
     'Sotho',
 ), validator=pick_one),
 prompt(_('You will be asked to answer 3 questions regarding HIV. '
     'Answer them correctly and stand a chance to win airtime! Press 1 to continue.'
 )),
 pick_first_unanswered(
     prompt(_('Can traditional medicine cure HIV/AIDS?'), **yes_or_no),
     prompt(_('Is an HIV test at any government clinic free of charge?'), **yes_or_no),
     prompt(_('Is it possible to test HIV-negative for up to 3-months after becoming HIV-infected?'), **yes_or_no),
 ),
 # do(print_storage),    
 case(
         (check_question, prompt('Correct! Press 1 to continue.'))
 ),
 pick_first_unanswered(
     prompt(_('Can HIV be transmitted by sweat?'), **yes_or_no),
     prompt(_('Is there a herbal medication that can cure HIV/AIDS?'), **yes_or_no),
     prompt(_('Does a CD4-count reflect the strength of a person\'s immune system?'), **yes_or_no),
 ),
 pick_first_unanswered(
     prompt(_('Can HIV be transmitted through a mother\'s breast milk?'), **yes_or_no),
     prompt(_('Is it possible for an HIV positive woman to deliver an HIV negative baby?'), **yes_or_no)
 ),
 case(
     (all_questions_answered, prompt(_('Thank you you\'ve answered all questions! Press 1 to continue.'))),
     (more_questions_left, prompt(_('Dial in again to answer the remaining questions Press 1 to continue.'))),
 ),
 prompt(_('For more information about HIV/AIDS please phone the Aids '+