Пример #1
0
    def test_mc_say(self):
        say = Mc.say()
        say.set_text('testing text')
        self.assertEqual('testing text', say.get_request_data()['text'])

        self.assertEqual('testing text2',
                         Mc.say('testing text2').get_request_data()['text'])
Пример #2
0
def ivr_play(digit, call):
    """
    Returns an Mc object for playing an URL file, or saying bye statements
    """
    mocean_command = McBuilder()

    # Create mocean commands for say action
    english_reject_say_action = Mc.say('Ok bye!')
    chinese_reject_say_action = Mc.say('那再见啦!').set_language('cmn-CN')

    # Sample music from downloaded from:
    # http://amachamusic.chagasi.com/music_konekonoosanpo.html
    play_action = Mc.play(
        f'http://{call.host}/audio/konekonoosanpo.mp3')  # nopep8

    if digit is not None and len(digit) > 0:
        mocean_command.add(play_action)
    else:
        if call.language == LanguageChoice.LANG_CNM_CN:
            mocean_command.add(chinese_reject_say_action)
        else:
            # default to english
            mocean_command.add(english_reject_say_action)

    return mocean_command
Пример #3
0
    def test_mc_play(self):
        play = Mc.play()
        play.set_files('testing file')
        self.assertEqual('testing file', play.get_request_data()['file'])

        self.assertEqual('testing file2',
                         Mc.play('testing file2').get_request_data()['file'])
Пример #4
0
    def test_mc_dial(self):
        dial = Mc.dial()
        dial.set_to('testing to')
        self.assertEqual('testing to', dial.get_request_data()['to'])

        self.assertEqual('testing to2',
                         Mc.dial('testing to2').get_request_data()['to'])
Пример #5
0
def ivr_get_language(digit, call):
    """
    Returns an Mc object for 2nd phase of IVR
    """

    # Define a mocean command builder
    mocean_command = McBuilder()
    # Create mocean commands for say action
    english_say_action = Mc.say(
        'Would you like to listen to some music? Press any key to proceed.'
    ).set_barge_in(True)  # nopep8
    chinese_say_action = Mc.say('你想听听音乐吗?若想,请按任意一键').set_language(
        'cmn-CN').set_barge_in(True)  # nopep8
    english_say_action_proceed = Mc.say(
        'Invalid input, we would assume you have picked English').set_barge_in(
            True)  # nopep8

    # Cleansing digit cache
    english_say_action.set_clear_digit_cache(True)
    chinese_say_action.set_clear_digit_cache(True)
    english_say_action_proceed.set_clear_digit_cache(True)

    # Create mocean command for collect
    collect_action = Mc.collect(f'http://{call.host}/voice/collect-command')
    collect_action.set_minimum(1).set_maximum(1).set_timeout(5000)
    # set a random character to avoid default '#' character termination
    collect_action.set_terminators('x')

    if is_digit(digit):
        # Convert input string into number
        digit = float(digit)
        if digit == 1:
            # Pressed 1 for english
            mocean_command.add(english_say_action)
            call.set_language(LanguageChoice.LANG_EN_US)
        elif digit == 2:
            # Pressed 2 for chinese
            mocean_command.add(chinese_say_action)
            call.set_language(LanguageChoice.LANG_CNM_CN)
        else:
            # Invalid input, but we should assume English and proceed
            mocean_command.add(english_say_action_proceed)
            # Since english_say_action_proceed has cleared digit cache
            # we should not clear digit cache for the subsequent actions
            english_say_action.set_clear_digit_cache(False)
            mocean_command.add(english_say_action)
            call.set_language(LanguageChoice.LANG_EN_US)
        # Add a collect action for proceeding action
        mocean_command.add(collect_action)
    else:
        mocean_command.add(english_say_action_proceed)
        # Since english_say_action_proceed has cleared digit cache
        # we should not clear digit cache for the subsequent actions
        english_say_action.set_clear_digit_cache(False)
        mocean_command.add(english_say_action)
        call.set_language(LanguageChoice.LANG_EN_US)
        # Add a collect action for proceeding action
        mocean_command.add(collect_action)
    return mocean_command
Пример #6
0
    def test_mc_collect(self):
        collect = Mc.collect()
        collect.set_event_url('testing event url')
        collect.set_minimum(1)
        collect.set_maximum(10)
        collect.set_timeout(500)
        self.assertEqual('testing event url',
                         collect.get_request_data()['event-url'])

        collect = Mc.collect('testing event url2')
        collect.set_minimum(1)
        collect.set_maximum(10)
        collect.set_timeout(500)
        self.assertEqual('testing event url2',
                         collect.get_request_data()['event-url'])
Пример #7
0
    def test_setter_method(self):
        voice = self.get_client_obj().voice

        voice.set_to('test to')
        self.assertIsNotNone(voice._params['mocean-to'])
        self.assertEqual('test to', voice._params['mocean-to'])

        voice.set_event_url('test event url')
        self.assertIsNotNone(voice._params['mocean-event-url'])
        self.assertEqual('test event url', voice._params['mocean-event-url'])

        voice.set_mocean_command('test mocean command')
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual('test mocean command',
                         voice._params['mocean-command'])

        voice.set_resp_format('json')
        self.assertIsNotNone(voice._params['mocean-resp-format'])
        self.assertEqual('json', voice._params['mocean-resp-format'])

        # test multiple call control commands
        voice = self.get_client_obj().voice
        voice.set_mocean_command([{'action': 'say'}])
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual(json.dumps([{
            'action': 'say'
        }]), voice._params['mocean-command'])

        voice = self.get_client_obj().voice
        builder_params = McBuilder().add(Mc.say("hello world"))
        voice.set_mocean_command(builder_params)
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual(json.dumps(builder_params.build()),
                         voice._params['mocean-command'])

        voice = self.get_client_obj().voice
        mc_params = Mc.say('hello world')
        voice.set_mocean_command(mc_params)
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual(json.dumps(McBuilder().add(mc_params).build()),
                         voice._params['mocean-command'])
Пример #8
0
    def test_add(self):
        play = Mc.play('testing file')

        builder = McBuilder()
        builder.add(play)
        self.assertEqual(1, len(builder.build()))
        self.assertEqual(play.get_request_data(), builder.build()[0])

        play.set_files('testing file2')
        builder.add(play)
        self.assertEqual(2, len(builder.build()))
        self.assertEqual(play.get_request_data(), builder.build()[1])
Пример #9
0
def ivr_init(call):
    """
    Returns mocean command JSON when it first initialised
    """
    # Create mocean commands for say action
    record_action = Mc.record()
    english_say_action = Mc.say(
        'Welcome to Mocean Voice IVR. For English, please press 1.'
    ).set_barge_in(True)  # nopep8
    chinese_say_action = Mc.say('中文请按二').set_language('cmn-CN').set_barge_in(
        True)  # nopep8
    # Create mocean command for collect
    collect_action = Mc.collect(f'http://{call.host}/voice/collect-command')
    collect_action.set_minimum(1).set_maximum(1).set_timeout(5000)

    # Adding mocean_command actions into mocean_command
    mocean_command = McBuilder()  # create builder
    mocean_command.add(record_action)  # adding record actions
    mocean_command.add(english_say_action)  # say it in english
    mocean_command.add(chinese_say_action)  # say it in chinese
    mocean_command.add(collect_action)  # adding collect action

    return False, mocean_command.build()
Пример #10
0
 def test_mc_record(self):
     self.assertEqual('record', Mc.record().get_request_data()['action'])
Пример #11
0
    def test_mc_sleep(self):
        sleep = Mc.sleep()
        sleep.set_duration(10000)
        self.assertEqual(10000, sleep.get_request_data()['duration'])

        self.assertEqual(20000, Mc.sleep(20000).get_request_data()['duration'])