async def test_on_state_ringing(relay_calling):
    call = Call(calling=relay_calling)
    call.id = 'call-id'
    message = Message.from_json(
        '{"jsonrpc":"2.0","id":"uuid","method":"blade.broadcast","params":{"broadcaster_nodeid":"uuid","protocol":"signalwire-proto-test","channel":"notifications","event":"queuing.relay.events","params":{"event_type":"calling.call.state","event_channel":"signalwire-proto-test","timestamp":1569517309.4546909,"project_id":"project-uuid","space_id":"space-uuid","params":{"call_state":"ringing","direction":"outbound","device":{"type":"phone","params":{"from_number":"+12029999999","to_number":"+12028888888"}},"call_id":"call-id","node_id":"node-id","tag":"'
        + call.tag + '"}}}}')
    relay_calling.client.message_handler(message)
    assert call.state == 'ringing'
 async def read(self):
     async for msg in self.ws:
         logging.debug('RECV: \n' + msg.data)
         if msg.type == WSMsgType.TEXT:
             self.client.message_handler(Message.from_json(msg.data))
         elif msg.type == WSMsgType.CLOSED:
             logging.info('WebSocket Closed!')
             break
         elif msg.type == WSMsgType.ERROR:
             logging.info('WebSocket Error!')
             break
예제 #3
0
async def test_on_receive(relay_tasking):
    handler = Mock()
    await relay_tasking.receive(['home', 'office'], handler)

    message = Message.from_json(
        '{"jsonrpc":"2.0","id":"uuid","method":"blade.broadcast","params":{"broadcaster_nodeid":"uuid","protocol":"signalwire-proto-test","channel":"notifications","event":"queuing.relay.tasks","params":{"project_id":"project-uuid","space_id":"space-uuid","context":"office","message":{"key":"value","data":"random stuff"},"timestamp":1569859833,"event_channel":"signalwire-proto-test"}}}'
    )
    relay_tasking.client.message_handler(message)

    message = handler.call_args[0][0]
    assert isinstance(message, dict)
    assert message['key'] == 'value'
    assert message['data'] == 'random stuff'
    handler.assert_called_once()
async def test_on_receive(relay_calling):
    handler = Mock()
    await relay_calling.receive(['home', 'office'], handler)

    message = Message.from_json(
        '{"jsonrpc":"2.0","id":"uuid","method":"blade.broadcast","params":{"broadcaster_nodeid":"uuid","protocol":"signalwire-proto-test","channel":"notifications","event":"queuing.relay.events","params":{"event_type":"calling.call.receive","timestamp":1569514183.0130031,"project_id":"project-uuid","space_id":"space-uuid","params":{"call_state":"created","context":"office","device":{"type":"phone","params":{"from_number":"+12029999999","to_number":"+12028888888"}},"direction":"inbound","call_id":"call-id","node_id":"node-id"},"context":"office","event_channel":"signalwire-proto-test"}}}'
    )
    relay_calling.client.message_handler(message)

    call = handler.call_args[0][0]
    assert isinstance(call, Call)
    assert call.from_number == '+12029999999'
    assert call.to_number == '+12028888888'
    handler.assert_called_once()
예제 #5
0
async def test_receive(relay_messaging):
    handler = Mock()
    await relay_messaging.receive(['home', 'office'], handler)

    event = BladeMessage.from_json(
        '{"jsonrpc":"2.0","id":"uuid","method":"blade.broadcast","params":{"broadcaster_nodeid":"uuid","protocol":"signalwire-proto-test","channel":"notifications","event":"queuing.relay.messaging","params":{"event_type":"messaging.receive","space_id":"space-uuid","project_id":"project-uuid","context":"office","timestamp":1570191488.717304,"params":{"message_id":"875029c0-92cf-44ef-b6c0-d250123e833b","context":"office","direction":"outbound","tags":["t1","t2"],"from_number":"+12029999999","to_number":"+12028888888","body":"Hey There, Welcome at SignalWire!","media":[],"segments":1,"message_state":"received"},"event_channel":"signalwire-proto-test"}}}'
    )
    relay_messaging.client.message_handler(event)

    message = handler.call_args[0][0]
    assert isinstance(message, Message)
    assert message.id == '875029c0-92cf-44ef-b6c0-d250123e833b'
    assert message.from_number == '+12029999999'
    assert message.to_number == '+12028888888'
    assert message.state == 'received'
    assert message.tags == ['t1', 't2']
    handler.assert_called_once()
async def test_blade_disconnect(relay_client_to_connect):
  assert relay_client_to_connect._idle == False
  blade_disconnect = Message.from_json('{"id":"378d7dea-e581-4305-a7e7-d29173797f32","jsonrpc":"2.0","method":"blade.disconnect","params":{}}')
  relay_client_to_connect.message_handler(blade_disconnect)
  assert relay_client_to_connect._idle == True

  async def _reconnect():
    assert relay_client_to_connect._executeQueue.qsize() == 1
    relay_client_to_connect.connection.responses.append('{"jsonrpc":"2.0","id":"uuid","result":{"test":"done"}}')
    await relay_client_to_connect._connect()

  asyncio.create_task(_reconnect())
  message = Execute({ 'protocol': 'fake', 'method': 'testing', 'params': {} })
  result = await relay_client_to_connect.execute(message)

  assert relay_client_to_connect._idle == False
  assert relay_client_to_connect._executeQueue.qsize() == 0
  assert result['test'] == 'done'
예제 #7
0
 async def read(self):
   for response in self.responses:
     msg = Message.from_json(response)
     msg.id = await self.queue.get()
     self.client.message_handler(msg)