Exemple #1
0
 def test_loading_of_yaml_file(self):
     """
     Just testing loading & getting of menu items, not the content
     of the file.
     """
     menu = self.loader.load_from_file(open('src/alexandria/examples/devquiz.yaml', 'r'))
     self.assertEquals(len(menu.stack), 4)
     self.assertEquals(dump_menu(menu), [
         (msg('What is your favorite programming language?', [
                 'java', 
                 'c', 
                 'python', 
                 'ruby', 
                 'javascript', 
                 'php', 
                 'other']), False),
         (msg('What is your favorite development operating system?', [
                 'windows', 
                 'apple', 
                 '*nix', 
                 'other']), False),
         (msg('What is your favorite development environment?', [
                 'netbeans', 
                 'eclipse', 
                 'vim', 
                 'emacs', 
                 'textmate', 
                 'notepad']), False),
         (msg('Thanks! You have completed the quiz.', []), True)
     ])
 
     
Exemple #2
0
 def test_validation(self):
     """
     the client should repeat the same coroutine if validation for the given
     input fails
     """
     client = TestingClient("test_client")
     menu = MenuSystem(
         prompt("What is your favorite color?", 
             validator=pick_one,
             options=(
             "red", "white", "blue"
         )),
         prompt("How old are you?", 
             validator=integer),
         end("Thanks & goodbye!")
     )
     
     client.answer("*120*USSD_SHORTCODE#", menu)
     client.answer("yellow", menu)
     client.answer("red", menu)
     client.answer("twenty nine", menu)
     client.answer("29", menu)
     
     self.assertEquals(client.outbox, [
         (msg("What is your favorite color?", ("red","white","blue")), False), # yellow => repeat
         (msg("What is your favorite color?", ("red","white","blue")), False), # red
         (msg("How old are you?", ()), False), # twenty nine => repeat
         (msg("How old are you?", ()), False), # 29
         (msg("Thanks & goodbye!", ()), True)
     ])
Exemple #3
0
 def test_stepping_through_system(self):
     """
     testing the perfect scenario
     """
     
     client = TestingClient("test_client")
     menu = MenuSystem(
         prompt("What is your name?"),
         prompt("What is your favorite color?", 
             validator=pick_one,
             options=(
             "red", "white", "blue"
         )),
         prompt("How old are you?", 
             validator=integer),
         end("Thanks & goodbye!")
     )
     
     
     client.answer("*120*USSD_SHORTCODE#", menu)
     client.answer("Simon de Haan", menu)
     client.answer("red", menu)
     client.answer("29", menu)
     
     self.assertEquals(client.outbox, [
         (msg("What is your name?", ()), False),
         (msg("What is your favorite color?", ("red","white","blue")), False),
         (msg("How old are you?", ()), False),
         (msg("Thanks & goodbye!", ()), True)
     ])
Exemple #4
0
 def test_generated_stack(self):
     """
     The question statement isn't a coroutine, it just generates a bit
     of the stack on the fly for us. This test checks if the generated
     stack is somewhat sane.
     """
     
     question_stack = question('Is your right thumb on your left hand?', {
         'no': 'Please see a doctor and press 1 to continue.',
         'yes': 'Correct! Please press 1 to continue'
     })
     
     [prompt, case] = question_stack
     
     prompt.next() # advance coroutine
     question_text, end_of_session = prompt.send((MenuSystem(), {}))
     
     # check that the dictionary keys are correctly translated to options
     # for the prompt
     self.assertEquals(question_text, 
                         msg("Is your right thumb on your left hand?", 
                             options=("yes","no"))) # FIXME strange sorting issue
     
     # Fake the answer by manually setting it in the session
     
     # check that the case statements reflect the options
     case.next()
     response_text, end_of_session = case.send((MenuSystem(), {
         "Is your right thumb on your left hand?": "no"
     }))
     self.assertEquals(response_text, "Please see a doctor and press 1 "
                                         "to continue.")
     self.assertFalse(end_of_session)
Exemple #5
0
 def test_character_response(self):
     """
     prompt() with a pick_one validator should accept character input 
     that match the menu values for the menu items
     """
     p = prompt(self.question_text, validator=pick_one, 
                 options=self.question_options)
     # advance coroutine to yield statement, FIXME use coroutine decorator
     p.next()
     question, end_of_session = p.send((MenuSystem(), self.session_store))
     
     self.assertEquals(question, msg(self.question_text, 
                         self.question_options))
     self.assertFalse(end_of_session)
     
     # advance again - FIXME this manual advancing is sloppy
     p.next()
     validated_answer = p.send("blue")
     self.assertEquals(validated_answer, "blue")
     
     # check session store
     self.assertEquals(self.session_store['What is your favorite color?'], 
                         "blue")