Ejemplo n.º 1
0
    def test_single_options_single_digits(self):
        m = Menu(test_contacts)
        assert len(m.get_options('2')) == 1
        assert m.get_options('2')[0]['number'] == '1'

        assert len(m.get_options('3')) == 1
        assert m.get_options('3')[0]['number'] == '2'
Ejemplo n.º 2
0
def phonebook():
    response = twilio.twiml.Response()
    digits = request.values.get('Digits', None)
    menu = Menu(contacts)
    options = menu.get_options(digits)
    if len(options) == 0:
        log.debug("no numbers found")
        response.say("no numbers found")
        # how do redirect without duplication of code?
    elif len(options) == 1:
        log.debug("calling %s" % (options[0]['name']))
        response.say("calling " + options[0]['name'])
        response.dial(options[0]['number'])
    else:
        log.debug("no numbers found")
        response.say("more than 1 number found")
        # do nothing for now, could offer a menu later
    return str(response)
Ejemplo n.º 3
0
    def test_multi_options_multi_digits(self):
        m = Menu(test_contacts)

        for name in ['tum', 'tun', 'uuo']:
            self.assertEqual(len(m.get_options(ntd(name))), 3)
Ejemplo n.º 4
0
    def test_single_options_multi_digits(self):
        m = Menu(test_contacts)

        for name in ['matt', 'dad', 'da', 'ad']:
            self.assertEqual(len(m.get_options(ntd(name))), 1)
            self.assertEqual(test_contacts[name], m.get_options(ntd(name))[0]['number'])
Ejemplo n.º 5
0
 def test_no_digits(self):
     m = Menu(test_contacts)
     self.assertEqual(m.get_options(''), [])
Ejemplo n.º 6
0
 def test_bad_digits(self):
     m = Menu(test_contacts)
     with self.assertRaises(AssertionError):
         m.get_options('xx')