def test_creates_fake_srv_if_no_srvs_available(self): base = unittest.mock.Mock() nattempts = object() with unittest.mock.patch( "aioxmpp.network.lookup_srv", new=base.lookup_srv) as lookup_srv: lookup_srv.return_value = None result = run_coroutine(network.find_xmpp_host_addr( asyncio.get_event_loop(), base.domain, attempts=nattempts )) calls = list(base.mock_calls) self.assertSequenceEqual( calls, [ unittest.mock.call.domain.encode("IDNA"), unittest.mock.call.lookup_srv( service="xmpp-client", domain=base.domain.encode(), nattempts=nattempts ) ] ) self.assertSequenceEqual( result, [ (0, 0, (base.domain.encode(), 5222)), ] )
def test_returns_items_if_available(self): base = unittest.mock.Mock() base.lookup_srv = CoroutineMock() nattempts = object() items = object() with unittest.mock.patch("aioxmpp.network.lookup_srv", new=base.lookup_srv) as lookup_srv: lookup_srv.return_value = items result = run_coroutine( network.find_xmpp_host_addr(asyncio.get_event_loop(), base.domain, attempts=nattempts)) calls = list(base.mock_calls) self.assertSequenceEqual(calls, [ unittest.mock.call.domain.encode("IDNA"), unittest.mock.call.lookup_srv(service="xmpp-client", domain=base.domain.encode(), nattempts=nattempts) ]) self.assertIs(result, items)
def test_propagates_ValueError_from_lookup_srv(self): base = unittest.mock.Mock() nattempts = object() with unittest.mock.patch("aioxmpp.network.lookup_srv", new=base.lookup_srv) as lookup_srv: lookup_srv.side_effect = ValueError() with self.assertRaises(ValueError): run_coroutine( network.find_xmpp_host_addr(asyncio.get_event_loop(), base.domain, attempts=nattempts))
def test_propagates_ValueError_from_lookup_srv(self): base = unittest.mock.Mock() nattempts = object() with unittest.mock.patch( "aioxmpp.network.lookup_srv", new=base.lookup_srv) as lookup_srv: lookup_srv.side_effect = ValueError() with self.assertRaises(ValueError): run_coroutine(network.find_xmpp_host_addr( asyncio.get_event_loop(), base.domain, attempts=nattempts ))