async def test_write_linked_escaped(self): # Given envelope = LinkedResponse('/unit/5', '/unit/3') expected = '@linked(node:"/unit/5",lane:"/unit/3")' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async def test_write_linked(self): # Given envelope = LinkedResponse('test', 'foo') expected = '@linked(node:test,lane:foo)' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async def test_write_linked_body_string(self): # Given envelope = LinkedResponse('/unit/5', '/unit/3', body=Text.create_from('spam and \\ham/')) expected = '@linked(node:"/unit/5",lane:"/unit/3")"spam and \\ham/"' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async def test_write_linked_body_bool(self): # Given envelope = LinkedResponse('/unit/5', '/unit/3', body=Bool.create_from(False)) expected = '@linked(node:"/unit/5",lane:"/unit/3")false' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
async def test_write_linked_body_float(self): # Given envelope = LinkedResponse('/unit/5', '/unit/3', body=Num.create_from(-100.0)) expected = '@linked(node:"/unit/5",lane:"/unit/3")-100.0' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
def test_linked_response_empty_body(self): # Given node_uri = 'foo_linked_node' lane_uri = 'bar_linked_lane' # When actual = LinkedResponse(node_uri, lane_uri) # Then self.assertEqual('foo_linked_node', actual.node_uri) self.assertEqual('bar_linked_lane', actual.lane_uri) self.assertEqual('linked', actual.tag) self.assertEqual('foo_linked_node/bar_linked_lane', actual.route) self.assertEqual(Absent.get_absent(), actual.body) self.assertIsInstance(actual.form, LinkedResponseForm)
async def test_write_linked_prio_rate(self): # Given envelope = LinkedResponse('/unit/5', '/unit/3', prio=22.11, rate=0.2, body=Text.create_from('spam and \\ham/')) expected = '@linked(node:"/unit/5",lane:"/unit/3",prio:22.11,rate:0.2)"spam and \\ham/"' # When actual = await envelope.to_recon() # Then self.assertEqual(expected, actual)
def test_unlinked_form_mold(self): # Given form = UnlinkedResponseForm() envelope = LinkedResponse('unlinked_node', 'unlinked_lane', prio=9, rate=10, body=Text.create_from('Baz')) # When actual = form.mold(envelope) # Then self.assertIsInstance(actual, RecordMap) self.assertEqual(2, actual.size) self.assertEqual('unlinked', actual.tag) self.assertEqual('unlinked_node', actual.get_item(0).value.get_item(0).value.value) self.assertEqual('unlinked_lane', actual.get_item(0).value.get_item(1).value.value) self.assertEqual(9, actual.get_item(0).value.get_item(2).value.value) self.assertEqual(10, actual.get_item(0).value.get_item(3).value.value) self.assertEqual('Baz', actual.get_item(1).value)
def test_linked_response_existing_body(self): # Given node_uri = 'foo_linked_node' lane_uri = 'bar_linked_lane' body = Text.create_from('Linked_Body') priority = 1.13 rate = 3.11 # When actual = LinkedResponse(node_uri, lane_uri, priority, rate, body) # Then self.assertEqual('foo_linked_node', actual.node_uri) self.assertEqual('bar_linked_lane', actual.lane_uri) self.assertEqual('linked', actual.tag) self.assertEqual('foo_linked_node/bar_linked_lane', actual.route) self.assertEqual(body, actual.body) self.assertIsInstance(actual.form, LinkedResponseForm)
async def test_downlink_model_receive_message_linked(self): # Given with SwimClient() as client: downlink = EventDownlinkModel(client) downlink.connection = MockConnection.get_mock_connection() downlink.connection.owner = downlink linked_message = LinkedResponse('linked_node', 'linked_lane') downlink.connection.messages_to_receive.append(linked_message) # When actual = downlink.open() while not actual.linked.is_set(): pass # Then self.assertEqual(downlink, actual) self.assertTrue(actual.linked.is_set())