Exemple #1
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 #2
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 #3
0
 def test_subclassing(self):
     """
     The client's send method must be subclassed
     """
     client = DumbClient()
     menu = MenuSystem(end("thanks!"))
     
     self.assertRaises(NotImplementedError, client.answer, "*120*USSD_SHORTCODE#", menu)
Exemple #4
0
 def test_end_response(self):
     """
     end() closes off a session with a good bye message. The end_of_message
     boolean flag should be true.
     """
     
     e = end("So long, and thanks for all the fish")
     e.next()
     message, end_of_session = e.send((MenuSystem(), {}))
     self.assertEquals(message, "So long, and thanks for all the fish")
     self.assertTrue(end_of_session)
Exemple #5
0
def get_menu():
    return MenuSystem(
        prompt('What is your favorite programming language?', options=(
        'java', 'c', 'python', 'ruby', 'javascript', 'php', 'other'
        ), validator=pick_one),
        prompt('What is your favorite development operating system?', options=(
            'windows', 'apple', '*nix', 'other'
        ), validator=pick_one),
        prompt('What is your favorite development environment?', options=(
            'netbeans', 'eclipse', 'vim', 'emacs', 'textmate', 'notepad'
        ), validator=pick_one),
        end('Thanks! You have completed the quiz')
    )
Exemple #6
0
 def test_deactivation(self):
     """
     After completing a menu the client should deactivate the session, closing
     it from further use.
     """
     client = TestingClient("test_client")
     menu = MenuSystem(end("thanks!"))
     client.answer("*120*USSD_SHORTCODE#", menu)
     self.assertEquals(client.outbox, [
         ("thanks!", True)
     ])
     
     from alexandria.sessions.db.models import Client as BackendClient
     backend_client = BackendClient.objects.filter(**client.uuid())[0]
     self.assertFalse(backend_client.active)
Exemple #7
0
def get_menu():
    return MenuSystem(
        prompt('Which solution is your favorite?', options=(
        'Tbl1-Edu', 
        'Tbl2-Edu', 
        'Tbl3-Commun. info', 
        'Tbl4-Mob. consc.', 
        'Tbl5-Health 1', 
        'Tbl5-Health 2', 
        'Tbl6-Sec',
        'Tbl7-Sec',
        'Tbl8-Sec',
        'Tbl8-Edu'
        ), validator=pick_one),
        end('Thanks for voting!')
    )
Exemple #8
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)
     ])
Exemple #9
0
 def do_end(self, *args, **kwargs):
     return end(*args)