def test_dial_success(self): expected = { 'class': 'dial_success', 'exten': sentinel.exten, } result = CTIMessageFormatter.dial_success(sentinel.exten) assert_that(result, equal_to(expected))
def test_dial_success(self): expected = { 'class': 'dial_success', 'exten': s.exten, } result = CTIMessageFormatter.dial_success(s.exten) assert_that(result, equal_to(expected))
def notify(self, phone_id, status): event = CTIMessageFormatter.phone_hintstatus_update(phone_id, status) self._ctiserver.send_cti_event(event) bus_event = EndpointStatusUpdateEvent(config['uuid'], phone_id, status) self._bus_producer.publish_event( config['bus']['exchange_name'], config['bus']['routing_keys']['endpoint_status'], bus_event, )
def test_on_originate_success(self): connection = Mock(CTI) line = {'protocol': 'SCCP', 'name': 'zzzz'} self.user_service_manager._on_originate_success(connection, sentinel.exten, line) self._call_manager.answer_next_ringing_call.assert_called_once_with(connection, 'SCCP/zzzz') expected_message = CTIMessageFormatter.dial_success(sentinel.exten) connection.send_message.assert_called_once_with(expected_message)
def test_on_originate_success(self): connection = Mock(CTI) line = {'protocol': 'SCCP', 'name': 'zzzz'} self.user_service_manager._on_originate_success(connection, sentinel.exten, line) self._call_manager.answer_next_ringing_call.assert_called_once_with(connection, 'SCCP/zzzz') expected_message = CTIMessageFormatter.dial_success(sentinel.exten) connection.send_message.assert_called_once_with(expected_message)
def deliver_chat_message(self, from_, to, alias, text): destination_xivo_uuid, destination_user_uuid = to if destination_xivo_uuid != self._xivo_uuid: return destination_user_id = dao.user.get_by_uuid(destination_user_uuid)['id'] destination = '{}/{}'.format(destination_xivo_uuid, destination_user_id) msg = CTIMessageFormatter.chat(from_, to, alias, text) self._cti_server.send_to_cti_client(destination, msg)
def test_error_message(self): for exception, msg_string in self.exception_msg_map.iteritems(): self.connection.reset_mock() self.handler.handle(exception) expected_message = CTIMessageFormatter.ipbxcommand_error( msg_string) self.connection.send_message.assert_called_once_with( expected_message)
def test_report_ipbxcommand_error(self): msg = 'Ad libitum' expected = { 'class': 'ipbxcommand', 'error_string': msg, } result = CTIMessageFormatter.ipbxcommand_error(msg) assert_that(result, equal_to(expected), 'Error message')
def test_report_ipbxcommand_error(self): msg = 'Ad libitum' expected = { CLASS: 'ipbxcommand', 'error_string': msg, } result = CTIMessageFormatter.ipbxcommand_error(msg) assert_that(result, equal_to(expected), 'Error message')
def test_login_id(self): expected = { 'class': 'login_id', 'sessionid': s.session_id, 'wazoversion': xivo_cti.CTI_PROTOCOL_VERSION } result = CTIMessageFormatter.login_id(s.session_id) assert_that(result, equal_to(expected))
def test_people_search_result(self): search_result = { 'term': 'Bob', 'column_headers': [ 'Firstname', 'Lastname', 'Phone number', 'Mobile', 'Fax', 'Email', 'Agent' ], 'column_types': [ None, 'name', 'number_office', 'number_mobile', 'fax', 'email', 'relation_agent' ], 'results': [{ 'column_values': [ 'Bob', 'Marley', '5555555', '5556666', '5553333', '*****@*****.**', None ], 'relations': { 'agent': None, 'user': None, 'endpoint': None }, 'source': 'my_ldap_directory' }, { 'column_values': [ 'Charlie', 'Boblin', '5555556', '5554444', '5552222', '*****@*****.**', None ], 'relations': { 'agent': { 'id': 12, 'xivo_id': 'ad2f36c7-b0f3-48da-a63c-37434fed479b' }, 'user': { 'id': 34, 'xivo_id': 'ad2f36c7-b0f3-48da-a63c-37434fed479b' }, 'endpoint': { 'id': 56, 'xivo_id': 'ad2f36c7-b0f3-48da-a63c-37434fed479b' }, }, 'source': 'internal' }] } result = CTIMessageFormatter.people_search_result(search_result) expected = dict(search_result) expected.update({'class': 'people_search_result'}) assert_that(result, equal_to(expected))
def test_people_search_result(self): search_result = { "term": "Bob", "column_headers": [ "Firstname", "Lastname", "Phone number", "Mobile", "Fax", "Email", "Agent" ], "column_types": [ None, "name", "number_office", "number_mobile", "fax", "email", "relation_agent" ], "results": [{ "column_values": [ "Bob", "Marley", "5555555", "5556666", "5553333", "*****@*****.**", None ], "relations": { "agent": None, "user": None, "endpoint": None }, "source": "my_ldap_directory" }, { "column_values": [ "Charlie", "Boblin", "5555556", "5554444", "5552222", "*****@*****.**", None ], "relations": { "agent": { "id": 12, "xivo_id": "ad2f36c7-b0f3-48da-a63c-37434fed479b" }, "user": { "id": 34, "xivo_id": "ad2f36c7-b0f3-48da-a63c-37434fed479b" }, "endpoint": { "id": 56, "xivo_id": "ad2f36c7-b0f3-48da-a63c-37434fed479b" }, }, "source": "internal" }] } result = CTIMessageFormatter.people_search_result(search_result) expected = dict(search_result) expected.update({'class': 'people_search_result'}) assert_that(result, equal_to(expected))
def test_people_headers_result(self): headers = {'column_headers': s.headers, 'column_types': s.types} expected = { 'class': 'people_headers_result', 'column_headers': s.headers, 'column_types': s.types } result = CTIMessageFormatter.people_headers_result(headers) assert_that(result, equal_to(expected))
def test_people_export_personal_contacts_csv_result(self): result = 'firstname,lastname\r\nBob,the Buidler\r\n,Alice,Wonderland\r\n' expected = { 'class': 'people_export_personal_contacts_csv_result', 'csv_contacts': result } result = CTIMessageFormatter.people_export_personal_contacts_csv_result( result) assert_that(result, equal_to(expected))
def notify(self, phone_id, status): cti_event = CTIMessageFormatter.phone_hintstatus_update( phone_id, status) self._ctiserver.send_cti_event(cti_event) bus_event = EndpointStatusUpdateEvent(phone_id, status) user_id = self._innerdata.xod_config['phones'].keeplist[phone_id][ 'iduserfeatures'] user_uuid = self._innerdata.xod_config['users'].keeplist[str( user_id)]['uuid'] headers = {'user_uuid:{uuid}'.format(uuid=user_uuid): True} self._bus_publisher.publish(bus_event, headers=headers)
def get_relations(self, user_id): logger.debug('User %s is requesting his relations', user_id) xuserid = 'xivo/{user_id}'.format(user_id=user_id) try: line_id = dao.user.get_line(user_id)['id'] except NoSuchLineException: line_id = None agent_id = dao.user.get_agent_id(user_id) msg = CTIMessageFormatter.relations(self._uuid, user_id, line_id, agent_id) self._cti_server.send_to_cti_client(xuserid, msg)
def test_delete_queue_members(self): queue_member_ids = xrange(1, 4) expected = { 'class': 'getlist', 'listname': 'queuemembers', 'function': 'delconfig', 'tipbxid': 'xivo', 'list': [1, 2, 3], } result = CTIMessageFormatter.delete_queue_members(queue_member_ids) self.assertEqual(result, expected)
def test_people_personal_contact_raw_update(self): source = 'personal' source_entry_id = '123456789' expected = { 'class': 'people_personal_contact_raw_update', 'source': source, 'source_entry_id': source_entry_id, } result = CTIMessageFormatter.people_personal_contact_raw_update( source, source_entry_id) assert_that(result, equal_to(expected))
def test_delete_queue_members(self): queue_member_ids = xrange(1, 4) expected = { 'class': 'getlist', 'listname': 'queuemembers', 'function': 'delconfig', 'tipbxid': 'xivo', 'list': [1, 2, 3], } result = CTIMessageFormatter.delete_queue_members(queue_member_ids) self.assertEqual(result, expected)
def test_update_agent_status(self): agent_id = 42 agent_status = {'availability': AgentStatus.logged_out, 'availability_since': 123456789} expected_result = {'class': 'getlist', 'listname': 'agents', 'function': 'updatestatus', 'tipbxid': 'xivo', 'tid': agent_id, 'status': agent_status} result = CTIMessageFormatter.update_agent_status(agent_id, agent_status) self.assertEqual(result, expected_result)
def test_people_headers_result(self): headers = { 'column_headers': sentinel.headers, 'column_types': sentinel.types } expected = { 'class': 'people_headers_result', 'column_headers': sentinel.headers, 'column_types': sentinel.types } result = CTIMessageFormatter.people_headers_result(headers) assert_that(result, equal_to(expected))
def test_update_queue_member_config(self): queue_member = Mock(QueueMember, id=12) queue_member.to_cti_config.return_value = s.config expected = { 'class': 'getlist', 'listname': 'queuemembers', 'function': 'updateconfig', 'tipbxid': 'xivo', 'tid': 12, 'config': s.config, } result = CTIMessageFormatter.update_queue_member_config(queue_member) self.assertEqual(result, expected)
def test_user_status_update(self): result = CTIMessageFormatter.user_status_update( s.xivo_uuid, s.user_uuid, s.user_id, s.status) assert_that( result, equal_to({ 'class': 'user_status_update', 'data': { 'xivo_uuid': s.xivo_uuid, 'user_uuid': s.user_uuid, 'user_id': s.user_id, 'status': s.status, } }))
def test_update_queue_member_config(self): queue_member = Mock(QueueMember, id=12) queue_member.to_cti_config.return_value = sentinel.config expected = { 'class': 'getlist', 'listname': 'queuemembers', 'function': 'updateconfig', 'tipbxid': 'xivo', 'tid': 12, 'config': sentinel.config, } result = CTIMessageFormatter.update_queue_member_config(queue_member) self.assertEqual(result, expected)
def test_endpoint_status_update(self): key = ('xivo-uuid', 42) status = 0 result = CTIMessageFormatter.endpoint_status_update(key, status) assert_that( result, equal_to({ 'class': 'endpoint_status_update', 'data': { 'xivo_uuid': 'xivo-uuid', 'endpoint_id': 42, 'status': 0, } }))
def test_agent_status_update(self): key = ('xivo-uuid', 42) status = 'logged_out' result = CTIMessageFormatter.agent_status_update(key, status) assert_that( result, equal_to({ 'class': 'agent_status_update', 'data': { 'xivo_uuid': 'xivo-uuid', 'agent_id': 42, 'status': 'logged_out', } }))
def test_getlist_update_status_user(self): result = CTIMessageFormatter.getlist_update_status_users( s.user_id, s.status) assert_that( result, equal_to({ 'class': 'getlist', 'function': 'updatestatus', 'listname': 'users', 'tipbxid': 'xivo', 'tid': s.user_id, 'status': { 'availstate': s.status } }))
def test_relations_no_endpoint_no_agent(self): xivo_uuid = 'my-xivo-uuid' user_id = '42' result = CTIMessageFormatter.relations(xivo_uuid, user_id, None, None) assert_that( result, equal_to({ 'class': 'relations', 'data': { 'xivo_uuid': xivo_uuid, 'user_id': 42, 'endpoint_id': None, 'agent_id': None } }))
def test_people_favorite_update(self): source = 'internal' source_entry_id = '123456789' enabled = True set_favorite_result = { 'class': 'people_favorite_update', 'source': source, 'source_entry_id': source_entry_id, 'favorite': enabled } result = CTIMessageFormatter.people_favorite_update( source, source_entry_id, enabled) expected = dict(set_favorite_result) expected.update({'class': 'people_favorite_update'}) assert_that(result, equal_to(expected))
def test_update_phone_hinstatus(self): hint = 8 phone_id = '42' result = CTIMessageFormatter.phone_hintstatus_update(phone_id, hint) assert_that( result, equal_to({ 'class': 'getlist', 'listname': 'phones', 'function': 'updatestatus', 'tipbxid': 'xivo', 'tid': phone_id, 'status': { 'hintstatus': hint } }))
def test_people_personal_contact_raw_result(self): source = 'personal' source_entry_id = '123456789' contact_infos = {'firstname': 'Bob', 'lastname': 'The Builder'} expected = { 'class': 'people_personal_contact_raw_result', 'source': source, 'source_entry_id': source_entry_id, 'contact_infos': { 'firstname': 'Bob', 'lastname': 'The Builder' } } result = CTIMessageFormatter.people_personal_contact_raw_result( source, source_entry_id, contact_infos) assert_that(result, equal_to(expected))
def test_people_personal_contacts_result(self): personal_contacts_result = { 'column_headers': [ 'Firstname', 'Lastname', 'Phone number', 'Mobile', 'Fax', 'Email', 'Agent', 'Favorite', 'Personal' ], 'column_types': [ None, 'name', 'number_office', 'number_mobile', 'fax', 'email', 'relation_agent', 'favorite', 'personal' ], 'results': [{ 'column_values': [ 'Bob', 'Marley', '5555555', '5556666', '5553333', '*****@*****.**', None, True, True ], 'relations': { 'agent': None, 'user': None, 'endpoint': None }, 'source': 'personal' }, { 'column_values': [ 'Charlie', 'Boblin', '5555556', '5554444', '5552222', '*****@*****.**', None, False, True ], 'relations': { 'agent': None, 'user': None, 'endpoint': None }, 'source': 'personal' }] } result = CTIMessageFormatter.people_personal_contacts_result( personal_contacts_result) expected = dict(personal_contacts_result) expected.update({'class': 'people_personal_contacts_result'}) assert_that(result, equal_to(expected))
def test_update_agent_status(self): agent_id = 42 agent_status = { 'availability': AgentStatus.logged_out, 'availability_since': 123456789 } expected_result = { 'class': 'getlist', 'listname': 'agents', 'function': 'updatestatus', 'tipbxid': 'xivo', 'tid': agent_id, 'status': agent_status } result = CTIMessageFormatter.update_agent_status( agent_id, agent_status) self.assertEqual(result, expected_result)
def test_relations(self): xivo_uuid = 'my-xivo-uuid' user_id = '42' endpoint_id = '50' agent_id = '24' result = CTIMessageFormatter.relations(xivo_uuid, user_id, endpoint_id, agent_id) assert_that( result, equal_to({ 'class': 'relations', 'data': { 'xivo_uuid': xivo_uuid, 'user_id': 42, 'endpoint_id': 50, 'agent_id': 24 } }))
def test_people_search_result(self): search_result = { "term": "Bob", "column_headers": ["Firstname", "Lastname", "Phone number", "Mobile", "Fax", "Email", "Agent"], "column_types": [None, "name", "number_office", "number_mobile", "fax", "email", "relation_agent"], "results": [ { "column_values": ["Bob", "Marley", "5555555", "5556666", "5553333", "*****@*****.**", None], "relations": { "agent": None, "user": None, "endpoint": None }, "source": "my_ldap_directory" }, { "column_values": ["Charlie", "Boblin", "5555556", "5554444", "5552222", "*****@*****.**", None], "relations": { "agent": { "id": 12, "xivo_id": "ad2f36c7-b0f3-48da-a63c-37434fed479b" }, "user": { "id": 34, "xivo_id": "ad2f36c7-b0f3-48da-a63c-37434fed479b" }, "endpoint": { "id": 56, "xivo_id": "ad2f36c7-b0f3-48da-a63c-37434fed479b" }, }, "source": "internal" } ] } result = CTIMessageFormatter.people_search_result(search_result) expected = dict(search_result) expected.update({'class': 'people_search_result'}) assert_that(result, equal_to(expected))
def _on_login_id(self, userlogin, xivo_version, cti_connection): if cti_connection != self._connection: return LoginID.deregister_callback(self._on_login_id) if xivo_version != xivo_cti.CTI_PROTOCOL_VERSION: logger.info( '%s failed to connect: the client protocol version %s is different from the server protocol version %s', userlogin, xivo_version, xivo_cti.CTI_PROTOCOL_VERSION) msg = 'wazoversion_client:{};{}'.format( xivo_version, xivo_cti.CTI_PROTOCOL_VERSION) self._fatal('login_id', msg) return self._username = userlogin LoginPass.register_callback_params(self._on_login_pass, ['password', 'cti_connection']) msg = CTIMessageFormatter.login_id(self._session_id) self._send_msg(msg)
def _on_auth_success(self, token_data): if not token_data: return self._user_uuid = token_data['xivo_user_uuid'] try: user_config = dao.user.get_by_uuid(self._user_uuid) except NoSuchUserException: return self._fatal('login_pass', 'user_not_found') self._cti_profile_id = user_config.get('cti_profile_id') if not self._cti_profile_id: logger.info('%s failed to login, profile %s', self._username, self._cti_profile_id) return self._fatal('login_pass', 'login_password') self._authenticated = True self._auth_token = token_data['token'] self._user_id = str(user_config['id']) msg = CTIMessageFormatter.login_pass(self._cti_profile_id) LoginCapas.register_callback_params( self._on_login_capas, ['capaid', 'state', 'cti_connection']) self._send_msg(msg) self._on_auth_complete()
def test_people_import_personal_contacts_csv_result(self): result = { 'failed': [{ 'line': 3, 'errors': ['missing fields'] }], 'created': [{ 'firstname': 'Toto', 'lastname': 'BĂ©langer' }, { 'firstname': 'Tata', 'lastanem': 'Bergeron' }] } expected = { 'class': 'people_import_personal_contacts_csv_result', 'failed': result['failed'], 'created_count': len(result['created']) } result = CTIMessageFormatter.people_import_personal_contacts_csv_result( result) assert_that(result, equal_to(expected))
def _send_headers_result(self, user_id, headers): xuserid = 'xivo/{user_id}'.format(user_id=user_id) message = CTIMessageFormatter.people_headers_result(headers) self._cti_server.send_to_cti_client(xuserid, message)
def notify(self, agent_id): agent_status = dao.agent.agent_status(agent_id) cti_message = CTIMessageFormatter.update_agent_status(agent_id, agent_status) self.cti_server.send_cti_event(cti_message)
def _send_lookup_result(self, user_id, result): xuserid = 'xivo/{user_id}'.format(user_id=user_id) message = CTIMessageFormatter.people_search_result(result) self._cti_server.send_to_cti_client(xuserid, message)