def test_did_gets_converted_on_build_xml(self, validate_patch,
                                          convert_phone_number_patch):
     u = UserAuthenticationModifyRequest(
         sip_user_id='*****@*****.**')
     self.assertFalse(convert_phone_number_patch.called)
     u.did = '617-555-1213'
     u.to_xml()
     self.assertTrue(convert_phone_number_patch.called)
    def test_set_credentials_passes_broadsoft_instance(self, init_patch,
                                                       post_patch):
        i = instance_factory(instance='prod')
        UserAuthenticationModifyRequest.set_credentials(
            new_password='******',
            did=6175551212,
            sip_user_id='*****@*****.**',
            broadsoftinstance=i)

        for call in init_patch.call_args_list:
            args, kwargs = call
            self.assertEqual(kwargs['broadsoftinstance'].api_url, i.api_url)
Exemplo n.º 3
0
    def set_auth_creds(self, req_object):
        self.prep_attributes()

        if self.did is None:
            raise ValueError("can't run Account.set_auth_creds() without a did")

        if self.sip_password is None:
            self.generate_sip_password()

        if self.sip_user_id is None:
            self.derive_sip_user_id(did=self.did)

        u = UserAuthenticationModifyRequest()
        self.inject_broadsoftinstance(child=u)
        u.did = self.did
        u.sip_user_id = self.sip_user_id
        u.new_password = self.sip_password

        req_object.commands.append(u)
    def test_to_xml(self):
        self.maxDiff = None

        # this one should only build out XML for what we provide.

        # here's a fully populated request
        u = UserAuthenticationModifyRequest(
            sip_user_id='*****@*****.**',
            did=6175551212,
            new_password='******')

        target_xml = \
            '<command xmlns="" xsi:type="UserAuthenticationModifyRequest">' + \
                '<userId>[email protected]</userId>' + \
                '<userName>6175551212</userName>' + \
                '<newPassword>newp</newPassword>' + \
            '</command>'

        cmd = u.build_command_xml()
        self.assertEqual(target_xml, ET.tostring(cmd).decode('utf-8'))
    def test_validate(self):
        u = UserAuthenticationModifyRequest()
        with self.assertRaises(ValueError):
            u.validate()

        # no password
        u = UserAuthenticationModifyRequest(
            sip_user_id='*****@*****.**', did='61755512121')
        with self.assertRaises(ValueError):
            u.validate()

        # no did
        u = UserAuthenticationModifyRequest(
            sip_user_id='*****@*****.**',
            new_password='******')
        with self.assertRaises(ValueError):
            u.validate()

        # bad did
        u = UserAuthenticationModifyRequest(
            sip_user_id='*****@*****.**',
            new_password='******',
            did='abc')
        with self.assertRaises(ValueError):
            u.validate()

        # no sip user id
        u = UserAuthenticationModifyRequest(did='6175551212',
                                            new_password='******')
        with self.assertRaises(ValueError):
            u.validate()
 def test_build_command_xml_calls_validate(self, validate_patch):
     u = UserAuthenticationModifyRequest(
         sip_user_id='*****@*****.**')
     self.assertFalse(validate_patch.called)
     u.build_command_xml()
     self.assertTrue(validate_patch.called)
 def test_did_converted_on_init(self):
     u = UserAuthenticationModifyRequest(did='617-555-1212')
     self.assertEqual('6175551212', u.did)