Ejemplo n.º 1
0
    def test_paginate_should_not_mangle_non_compound_request(self):
        from broadsoft.requestobjects.GroupAccessDeviceAddRequest import GroupAccessDeviceAddRequest
        g = GroupAccessDeviceAddRequest()

        b = BroadsoftObject()
        reqs = b.paginate_request(request=g)
        self.assertEqual([g], reqs)
Ejemplo n.º 2
0
    def test_init_calls_derive_broadsoftinstance(
            self, derive_broadsoft_instance_patch):
        # implicit instance
        b = BroadsoftObject()
        self.assertTrue(derive_broadsoft_instance_patch.called)
        call = derive_broadsoft_instance_patch.call_args_list[0]
        args, kwargs = call
        self.assertEqual(kwargs['instance'], 'prod')
        derive_broadsoft_instance_patch.called = False

        # test instance
        b = BroadsoftObject(instance='test')
        self.assertTrue(derive_broadsoft_instance_patch.called)
        call = derive_broadsoft_instance_patch.call_args_list[1]
        args, kwargs = call
        self.assertEqual(kwargs['instance'], 'test')
        derive_broadsoft_instance_patch.called = False

        # prod instance
        b = BroadsoftObject(instance='prod')
        self.assertTrue(derive_broadsoft_instance_patch.called)
        call = derive_broadsoft_instance_patch.call_args_list[2]
        args, kwargs = call
        self.assertEqual(kwargs['instance'], 'prod')
        derive_broadsoft_instance_patch.called = False
Ejemplo n.º 3
0
    def __init__(self, behavior='email', busy_to_voicemail=True, cc_email=None, did=None, email=None, mwi=None,
                 no_answer_to_voicemail=True, rings=3, straight_to_voicemail=False, send_cc=False, sip_user_id=None,
                 type='broadsoft', transfer_on_zero=False, transfer_number=None, sip_password=None, surgemail_domain=None,
                 **kwargs):
        self.behavior = behavior                            # "email" or "store" (on server)
        self.busy_to_voicemail = busy_to_voicemail
        self.cc_email = cc_email
        self.did = did
        self.email = email
        self.mwi = mwi
        self.no_answer_to_voicemail = no_answer_to_voicemail
        self.rings = rings
        self.send_cc = send_cc
        self.sip_password = sip_password
        self.sip_user_id = sip_user_id
        self.straight_to_voicemail = straight_to_voicemail
        self.surgemail_domain=surgemail_domain
        self.transfer_on_zero = transfer_on_zero
        self.transfer_number = transfer_number
        self.type = type                                    # broadsoft or unity

        BroadsoftObject.__init__(self, **kwargs)

        if self.surgemail_domain is None:
            self.surgemail_domain = self.broadsoftinstance.surgemail_domain
Ejemplo n.º 4
0
    def __init__(self, default_device_count=36, did=None, extension=None, last_name=None, first_name=None,
                 sip_user_id=None, kname=None, email=None, services=None, service_pack=None,
                 sip_password=None, voicemail='broadsoft', voicemail_mwi=None, **kwargs):
        self.default_device_count = default_device_count
        self.did = did
        self.email = email
        self.first_name = first_name
        self.kname = kname
        self.last_name = last_name
        self.service_pack = self.default_service_pack
        if service_pack:
            self.service_pack = service_pack
        self.services = self.load_default_services()
        if services:
            if type(services) == str:
                services = [services]
            self.services = services
        self.voicemail = voicemail

        # these are optional; will be derived by broadsoft.RequestObjects as needed
        self.extension = extension
        self.sip_user_id = sip_user_id

        # fully optional
        self.devices = []  # Devices associated with this Account (should be broadsoft.Device objects)
        self.sip_password = sip_password
        self.voicemail_mwi = voicemail_mwi

        self.old_did = self.did
        BroadsoftObject.__init__(self, **kwargs)
Ejemplo n.º 5
0
    def test_from_xml_calls_prep_attributes_and_check_if_object_fetched(
            self, prep_attributes_patch, check_if_object_fetched_patch):
        b = BroadsoftObject()
        prep_attributes_patch.called = False
        check_if_object_fetched_patch.called = False

        b.from_xml()
        self.assertTrue(prep_attributes_patch.called)
        self.assertTrue(check_if_object_fetched_patch.called)
Ejemplo n.º 6
0
    def test_derive_broadsoftinstance(self):
        self.assertIsInstance(
            BroadsoftObject.derive_broadsoft_instance(instance='prod'),
            broadsoft.requestobjects.lib.BroadsoftRequest.BroadsoftInstance)

        self.assertIsInstance(
            BroadsoftObject.derive_broadsoft_instance(instance='test'),
            broadsoft.requestobjects.lib.BroadsoftRequest.TestBroadsoftInstance
        )
Ejemplo n.º 7
0
    def test_logout_passes_broadsoftinstance(self, logout_patch):
        i = broadsoft.requestobjects.lib.BroadsoftRequest.instance_factory(
            instance='test')
        o = BroadsoftObject(broadsoftinstance=i)
        o.logout()

        call = logout_patch.call_args_list[0]
        args, kwargs = call
        self.assertIsInstance(
            kwargs['broadsoftinstance'], broadsoft.requestobjects.lib.
            BroadsoftRequest.TestBroadsoftInstance)
Ejemplo n.º 8
0
    def test_init_calls_setup_logging(self, setup_logging_patch):
        b = BroadsoftObject(logging_level='info')
        self.assertTrue(setup_logging_patch.called)
        args, kwargs = setup_logging_patch.call_args_list[0]
        self.assertEqual('info', kwargs['logging_level'])

        setup_logging_patch.called = False
        b = BroadsoftObject(logging_level='debug')
        self.assertTrue(setup_logging_patch.called)
        args, kwargs = setup_logging_patch.call_args_list[1]
        self.assertEqual('debug', kwargs['logging_level'])
Ejemplo n.º 9
0
    def test_deriving_logging_dir(self, exists_patch, makedirs_patch):
        # should default to default_logging_dir
        b = BroadsoftObject()
        self.assertEqual(b.logging_dir, BroadsoftObject.default_logging_dir)

        # should be able to override
        b = BroadsoftObject(logging_dir='/garbage')
        self.assertEqual(b.logging_dir, '/garbage')

        # drops trailing slash
        b = BroadsoftObject(logging_dir='/garbage/')
        self.assertEqual(b.logging_dir, '/garbage')
Ejemplo n.º 10
0
    def test_check_if_object_fetched_call(self):
        # failed call, should be set to False
        xml = """<ns0:BroadsoftDocument xmlns:ns0="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" protocol="OCI"><sessionId>VPN-18-101-101-100.MIT.EDU,2017-08-02 21:54:52.755707,2221805120</sessionId><command echo="" type="Error" xsi:type="c:ErrorResponse"><summary>[Error 4008] User not found: [email protected]</summary><summaryEnglish>[Error 4008] User not found: [email protected]</summaryEnglish></command></ns0:BroadsoftDocument>"""
        xml = ET.fromstring(xml)
        b = BroadsoftObject()
        b.xml = xml
        b.check_if_object_fetched()
        self.assertFalse(b.fetched)

        # successful call, should be set to True
        xml = """<ns0:BroadsoftDocument xmlns:ns0="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" protocol="OCI"><sessionId>VPN-18-101-101-100.MIT.EDU,2017-08-02 22:15:09.487547,7641180547</sessionId><command echo="" xsi:type="UserGetResponse21"><serviceProviderId>MIT-SP</serviceProviderId><groupId>MIT-GP</groupId><lastName>Hall</lastName><firstName>Lecture</firstName><callingLineIdLastName>Hall</callingLineIdLastName><callingLineIdFirstName>Lecture</callingLineIdFirstName><hiraganaLastName>Hall</hiraganaLastName><hiraganaFirstName>Lecture</hiraganaFirstName><phoneNumber>6172251563</phoneNumber><extension>51563</extension><language>English</language><timeZone>America/New_York</timeZone><timeZoneDisplayName>(GMT-04:00) (US) Eastern Time</timeZoneDisplayName><defaultAlias>[email protected]</defaultAlias><accessDeviceEndpoint><accessDevice><deviceLevel>Group</deviceLevel><deviceName>E51-335</deviceName></accessDevice><linePort>[email protected]</linePort><staticRegistrationCapable>true</staticRegistrationCapable><useDomain>true</useDomain><supportVisualDeviceManagement>false</supportVisualDeviceManagement></accessDeviceEndpoint><emailAddress>[email protected]</emailAddress><countryCode>1</countryCode></command></ns0:BroadsoftDocument>"""
        xml = ET.fromstring(xml)
        b = BroadsoftObject()
        b.xml = xml
        b.check_if_object_fetched()
        self.assertTrue(b.fetched)
Ejemplo n.º 11
0
    def provision(self):
        BroadsoftObject.prep_attributes(self)

        if not self.sip_password:
            self.generate_sip_password()

        # each new account gets 36 non-specific devices attached to it. we're doing no device management in broadsoft.
        if len(self.devices) == 0 or self.devices is None:
            self.attach_default_devices()

        BroadsoftObject.provision(self)

        # set up voicemail
        # Not making this part atomic since it seems reasonable to not make the entire request fail if this part does.
        if self.voicemail:
            self.activate_voicemail()
Ejemplo n.º 12
0
    def test_setup_logging_passes_logging_level_info(self):
        import logging

        # reset handlers so that setup_logger can do its thing as if called for the first time (may have been set by
        # earlier test)
        logger = logging.getLogger('broadsoftapi')
        logger.handlers = []

        # initial call
        b = BroadsoftObject(logging_level='info')
        logger = logging.getLogger('broadsoftapi')
        self.assertEqual(20, logger.level)

        # subsequent call shouldn't clobber prior setting...first should always
        # win, which seems the least confusing option should there be a malformed
        # call later in the stack that forgets to set level, which seems more likely
        # than needing to change level mid request
        b = BroadsoftObject(logging_level='debug')
        logger = logging.getLogger('broadsoftapi')
        self.assertEqual(20, logger.level)
Ejemplo n.º 13
0
    def from_xml(self, get_devices=True):
        BroadsoftObject.from_xml(self)
        self.devices = list()
        if self.xml:
            cmd = self.xml.findall('command')[0]
            if cmd.findall('phoneNumber'):
                self.did = cmd.findall('phoneNumber')[0].text
            if cmd.findall('firstName'):
                self.first_name = cmd.findall('firstName')[0].text
            if cmd.findall('lastName'):
                self.last_name = cmd.findall('lastName')[0].text
            if cmd.findall('extension'):
                self.extension = cmd.findall('extension')[0].text
            if cmd.findall('defaultAlias'):
                self.sip_user_id = cmd.findall('defaultAlias')[0].text
            if cmd.findall('emailAddress'):
                self.email = cmd.findall('emailAddress')[0].text

        if get_devices:
            self.load_devices()
Ejemplo n.º 14
0
    def test_derive_logging_level_object(self):
        import logging

        self.assertEqual(
            logging.INFO,
            BroadsoftObject.derive_logging_level_object(logging_level='info'))
        self.assertEqual(
            logging.INFO,
            BroadsoftObject.derive_logging_level_object(logging_level='INFO'))
        self.assertEqual(
            logging.DEBUG,
            BroadsoftObject.derive_logging_level_object(logging_level='debug'))
        self.assertEqual(
            logging.DEBUG,
            BroadsoftObject.derive_logging_level_object(logging_level='DEBUG'))
        with self.assertRaises(ValueError):
            BroadsoftObject.derive_logging_level_object(logging_level='gaga')
Ejemplo n.º 15
0
 def test_pass_broadsoftinstance(self, prep_attributes_patch):
     b = BroadsoftObject(broadsoftinstance='a')
     self.assertEqual('a', b.broadsoftinstance)