コード例 #1
0
    def test_generate_transports(self):
        output = StringIO()
        with patch('wazo_confgend.plugins.pjsip_conf.transport_dao') as dao:
            dao.search.return_value = SearchResult(2, [
                PJSIPTransport(name='transport-udp',
                               options=[
                                   ['protocol', 'udp'],
                                   ['bind', '0.0.0.0:5060'],
                               ]),
                PJSIPTransport(name='transport-wss',
                               options=[
                                   ['protocol', 'wss'],
                                   ['bind', '0.0.0.0:5060'],
                               ]),
            ])

            self.generator.generate_transports(output)
            assert_config_equal(
                output.getvalue(), '''\
                [transport-udp]
                type = transport
                protocol = udp
                bind = 0.0.0.0:5060

                [transport-wss]
                type = transport
                protocol = wss
                bind = 0.0.0.0:5060
                ''')
コード例 #2
0
    def test_one_element_lines_section_no_language(self):
        uuid = str(uuid4())
        sccpline = [{
            'id': 13423,
            'category': u'lines',
            'name': u'100',
            'cid_name': u'jimmy',
            'cid_num': u'100',
            'user_id': u'1',
            'uuid': uuid,
            'language': None,
            'number': u'100',
            'context': u'a_context',
            'tenant_uuid': u'tenant-uuid',
            'enable_online_recording': 0,
        }]

        self._line_conf._generate_lines(sccpline, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [100](xivo_line_tpl)
            type = line
            cid_name = jimmy
            cid_num = 100
            setvar = XIVO_ORIGINAL_CALLER_ID="jimmy" <100>
            setvar = XIVO_USERID=1
            setvar = XIVO_USERUUID={uuid}
            setvar = WAZO_TENANT_UUID=tenant-uuid
            setvar = PICKUPMARK=100%a_context
            setvar = TRANSFER_CONTEXT=a_context
            setvar = WAZO_CHANNEL_DIRECTION=from-wazo
            setvar = WAZO_LINE_ID=13423
            context = a_context
        '''.format(uuid=uuid))
コード例 #3
0
    def test_generate_file(self):
        default_section = Mock(variables=[
            Mock(key='type', value='user'),
            Mock(key='max_members', value='50')
        ])
        default_section.name = 'default'
        general_section = Mock(variables=[])
        general_section.name = 'general'
        bridge1_section = Mock(variables=[
            Mock(key='record_conference', value='yes'),
            Mock(key='toto', value=None)
        ])
        bridge1_section.name = 'bridge-1'
        file_ = Mock(sections_ordered=[
            general_section,
            default_section,
            bridge1_section,
        ])
        self.asterisk_file_generator._generate_file(file_, self.output)

        assert_config_equal(self.output.getvalue(), '''
            [general]

            [default]
            type = user
            max_members = 50

            [bridge-1]
            record_conference = yes
            toto =
        ''')
コード例 #4
0
    def test_one_element_devices_section(self):
        sccpdevice = [{
            'category': u'devices',
            'name': u'SEPACA016FDF235',
            'device': u'SEPACA016FDF235',
            'line': u'103',
            'voicemail': u'103'
        }]

        sccpspeeddials = [{
            'exten': '1001',
            'fknum': 1,
            'label': 'user001',
            'supervision': 0,
            'user_id': 1229,
            'device': 'SEPACA016FDF235'
        }]

        device_conf = _SccpDeviceConf(sccpspeeddials)
        device_conf._generate_devices(sccpdevice, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [SEPACA016FDF235](xivo_device_tpl)
            type = device
            line = 103
            voicemail = 103
            speeddial = 1229-1
        ''')
コード例 #5
0
    def test_generate(self):
        result = self.generator.generate()

        assert_config_equal(result, '''
            chan_sip.so
            chan_skinny.so
        ''')
コード例 #6
0
    def test_one_element_general_section(self):
        items = [{'option_name': u'foo', 'option_value': u'bar'}]

        self._general_conf.generate(items, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [general]
            foo = bar
        ''')
コード例 #7
0
    def test_template_disallow_option_is_ignored(self):
        items = [
            {
                'option_name': 'disallow',
                'option_value': 'foobar'
            },
        ]

        self._line_conf._generate_template(items, self._output)

        assert_config_equal(self._output.getvalue(), '''
            [xivo_line_tpl](!)
        ''')
コード例 #8
0
    def test_template_empty_allow_option(self):
        items = [
            {
                'option_name': 'allow',
                'option_value': ''
            },
        ]

        self._line_conf._generate_template(items, self._output)

        assert_config_equal(self._output.getvalue(), '''
            [xivo_line_tpl](!)
        ''')
コード例 #9
0
    def test_generate_mode_custom(self, mock_moh_dao):
        moh_list = [
            MOH(name='bar', mode='custom', application='/bin/false rrr'),
        ]
        mock_moh_dao.find_all_by.return_value = moh_list

        value = self.generator.generate()

        assert_config_equal(
            value, '''
            [bar]
            mode = custom
            application = /bin/false rrr
        ''')
コード例 #10
0
    def test_generate_unknown_sort(self, mock_moh_dao):
        moh_list = [
            MOH(name='foo', mode='files', sort='rabbit'),
        ]
        mock_moh_dao.find_all_by.return_value = moh_list

        value = self.generator.generate()

        assert_config_equal(
            value, '''
            [foo]
            mode = files
            directory = /var/lib/asterisk/moh/foo
            sort = rabbit
        ''')
コード例 #11
0
    def test_template_directmedia_option(self):
        items = [
            {
                'option_name': 'directmedia',
                'option_value': 'no'
            },
        ]

        self._line_conf._generate_template(items, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [xivo_line_tpl](!)
            directmedia = 0
        ''')
コード例 #12
0
    def test_template_items(self):
        items = [
            {
                'option_name': 'foo',
                'option_value': 'bar'
            },
        ]

        self._device_conf._generate_template(items, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [xivo_device_tpl](!)
            foo = bar
        ''')
コード例 #13
0
    def test_generate_mode_files(self, mock_moh_dao):
        moh_list = [
            MOH(name='foo', mode='files', sort='alphabetical'),
        ]
        mock_moh_dao.find_all_by.return_value = moh_list

        value = self.generator.generate()

        assert_config_equal(
            value, '''
            [foo]
            mode = files
            directory = /var/lib/asterisk/moh/foo
            sort = alpha
        ''')
コード例 #14
0
    def test_one_device_no_line_no_voicemail(self):
        sccpdevice = [{
            'category': u'devices',
            'name': u'SEPACA016FDF235',
            'device': u'SEPACA016FDF235',
            'line': u'',
            'voicemail': u''
        }]

        self._device_conf._generate_devices(sccpdevice, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [SEPACA016FDF235](xivo_device_tpl)
            type = device
        ''')
コード例 #15
0
    def test_gen_bridge_profile(self):
        conferences = [
            Conference(id=1, max_users=50, record=True),
            Conference(id=2, max_users=0, record=False),
        ]
        self.confbridge_conf._gen_bridge_profile(conferences, self.output)

        assert_config_equal(
            self.output.getvalue(), '''
            [xivo-bridge-profile-1](wazo_default_bridge)
            type = bridge
            max_members = 50
            record_conference = yes

            [xivo-bridge-profile-2](wazo_default_bridge)
            type = bridge
            max_members = 0
            record_conference = no
        ''')
コード例 #16
0
    def test_speeddial_no_label(self):
        speedials = [{
            'exten': '1001',
            'fknum': 1,
            'label': None,
            'supervision': 0,
            'user_id': 1229,
            'device': 'SEPACA016FDF235'
        }]

        sccp_conf = _SccpSpeedDialConf()
        sccp_conf.generate(speedials, self._output)

        assert_config_equal(
            self._output.getvalue(), '''
            [1229-1]
            type = speeddial
            extension = 1001
            blf = 0
        ''')
コード例 #17
0
    def test_gen_user_profile(self):
        conferences = [
            Conference(id=1,
                       admin_pin=None,
                       music_on_hold=None,
                       quiet_join_leave=False,
                       announce_join_leave=False,
                       announce_user_count=False,
                       announce_only_user=False),
            Conference(id=2,
                       admin_pin='1234',
                       music_on_hold='Music',
                       quiet_join_leave=True,
                       announce_join_leave=True,
                       announce_user_count=True,
                       announce_only_user=True),
        ]
        self.confbridge_conf._gen_user_profile(conferences, self.output)

        assert_config_equal(
            self.output.getvalue(), '''
            [xivo-user-profile-1](wazo_default_user)
            type = user
            quiet = no
            announce_join_leave = no
            announce_user_count = no
            announce_only_user = no

            [xivo-user-profile-2](wazo_default_user)
            type = user
            quiet = yes
            announce_join_leave = yes
            announce_user_count = yes
            announce_only_user = yes
            music_on_hold_when_empty = yes
            music_on_hold_class = Music

            [xivo-admin-profile-2](xivo-user-profile-2)
            admin = yes
        ''')
コード例 #18
0
    def test_gen_default_menu(self):
        self.confbridge_conf._gen_default_menu(self.output)

        assert_config_equal(
            self.output.getvalue(), '''
        [xivo-default-user-menu]
        type = menu
        * = playback_and_continue(dir-multi1&digits/1&confbridge-mute-out&digits/4&confbridge-dec-list-vol-out&digits/5&confbridge-rest-list-vol-out&digits/6&confbridge-inc-list-vol-out&digits/7&confbridge-dec-talk-vol-out&digits/8&confbridge-rest-talk-vol-out&digits/9&confbridge-inc-talk-vol-out)
        1 = toggle_mute
        4 = decrease_listening_volume
        5 = reset_listening_volume
        6 = increase_listening_volume
        7 = decrease_talking_volume
        8 = reset_talking_volume
        9 = increase_talking_volume

        [xivo-default-admin-menu](xivo-default-user-menu)
        * = playback_and_continue(dir-multi1&digits/1&confbridge-mute-out&digits/2&confbridge-lock-out&digits/3&confbridge-remove-last-out&digits/4&confbridge-dec-list-vol-out&digits/5&confbridge-rest-list-vol-out&digits/6&confbridge-inc-list-vol-out&digits/7&confbridge-dec-talk-vol-out&digits/8&confbridge-rest-talk-vol-out&digits/9&confbridge-inc-talk-vol-out)
        2 = admin_toggle_conference_lock
        3 = admin_kick_last
        0 = admin_toggle_mute_participants
        ''')
コード例 #19
0
    def test_generate_file_when_not_found(self):
        file_ = None
        self.asterisk_file_generator._generate_file(file_, self.output)

        assert_config_equal(self.output.getvalue(), '''
        ''')
コード例 #20
0
    def test_generate_trunks(self):
        output = StringIO()
        name_1 = 'abcdef'
        label_1 = 'my-sip-trunk'
        with patch(
                'wazo_confgend.plugins.pjsip_conf.asterisk_conf_dao') as dao:
            dao.find_sip_trunk_settings.return_value = [
                {
                    'name':
                    name_1,
                    'label':
                    label_1,
                    'aor_section_options': [
                        ['type', 'aor'],
                        ['qualify_frequency', '60'],
                    ],
                    'auth_section_options': [
                        ['type', 'auth'],
                        ['username', 'iddqd'],
                    ],
                    'endpoint_section_options': [
                        ['type', 'endpoint'],
                        ['aors', name_1],
                        ['auth', name_1],
                        ['allow', '!all,ulaw'],
                        ['outbound_auth', 'outbound_auth_{}'.format(name_1)],
                    ],
                    'identify_section_options': [
                        ['type', 'identify'],
                        ['match', '54.172.60.0'],
                        ['match', '54.172.60.1'],
                        ['endpoint', name_1],
                    ],
                    'registration_section_options': [
                        ['type', 'registration'],
                        ['expiration', '120'],
                        [
                            'outbound_auth',
                            '*****@*****.**'
                        ],
                    ],
                    'registration_outbound_auth_section_options': [
                        ['type', 'auth'],
                        ['username', 'reg_username'],
                        ['password', 'secret'],
                    ],
                    'outbound_auth_section_options': [
                        ['type', 'auth'],
                        ['username', 'outbound_auth_username'],
                        ['password', 'secret'],
                    ],
                },
            ]

            self.generator.generate_trunks(output)
            result = output.getvalue()
            assert_config_equal(
                result, '''\
                ; {label_1}
                [{name_1}]
                type = endpoint
                aors = {name_1}
                auth = {name_1}
                allow = !all,ulaw
                outbound_auth = outbound_auth_{name_1}

                [{name_1}]
                type = aor
                qualify_frequency = 60

                [{name_1}]
                type = auth
                username = iddqd

                [{name_1}]
                type = identify
                match = 54.172.60.0
                match = 54.172.60.1
                endpoint = {name_1}

                [outbound_auth_{name_1}]
                type = auth
                username = outbound_auth_username
                password = secret

                [[email protected]]
                type = auth
                username = reg_username
                password = secret

                [{name_1}]
                type = registration
                expiration = 120
                outbound_auth = [email protected]
                '''.format(label_1=label_1, name_1=name_1))
コード例 #21
0
    def test_generate_users(self):
        output = StringIO()
        name_1 = 'abcdef'
        label_1 = 'my-sip-line'
        name_2 = 'defbca'
        label_2 = 'another-sip-line'
        with patch(
                'wazo_confgend.plugins.pjsip_conf.asterisk_conf_dao') as dao:
            dao.find_sip_user_settings.return_value = [
                {
                    'name':
                    name_1,
                    'label':
                    label_1,
                    'aor_section_options': [
                        ['type', 'aor'],
                        ['qualify_frequency', '60'],
                    ],
                    'auth_section_options': [
                        ['type', 'auth'],
                        ['username', 'iddqd'],
                    ],
                    'endpoint_section_options': [
                        ['type', 'endpoint'],
                        ['aors', name_1],
                        ['auth', name_1],
                        ['allow', '!all,ulaw'],
                    ],
                },
                {
                    'name':
                    name_2,
                    'label':
                    label_2,
                    'aor_section_options': [
                        ['type', 'aor'],
                        ['qualify_frequency', '42'],
                    ],
                    'auth_section_options': [
                        ['type', 'auth'],
                        ['username', 'idbehold'],
                    ],
                    'endpoint_section_options': [
                        ['type', 'endpoint'],
                        ['aors', name_2],
                        ['auth', name_2],
                        ['allow', '!all,ulaw,g729'],
                    ],
                },
            ]

            self.generator.generate_lines(output)
            result = output.getvalue()
            assert_config_equal(
                result, '''\
                ; {label_1}
                [{name_1}]
                type = endpoint
                aors = {name_1}
                auth = {name_1}
                allow = !all,ulaw

                [{name_1}]
                type = aor
                qualify_frequency = 60

                [{name_1}]
                type = auth
                username = iddqd

                ; {label_2}
                [{name_2}]
                type = endpoint
                aors = {name_2}
                auth = {name_2}
                allow = !all,ulaw,g729

                [{name_2}]
                type = aor
                qualify_frequency = 42

                [{name_2}]
                type = auth
                username = idbehold
                '''.format(
                    label_1=label_1,
                    label_2=label_2,
                    name_1=name_1,
                    name_2=name_2,
                ))