def test_overridden_thread_local_behaves_like_fixed(self): resolver = MockResolver(self) resolver.define_actions([ (( "xn--4ca0bs.example.com", dns.rdatatype.A, dns.rdataclass.IN, False, (dns.flags.RD | dns.flags.AD), ), dns.resolver.Timeout()), (( "xn--4ca0bs.example.com", dns.rdatatype.A, dns.rdataclass.IN, True, (dns.flags.RD | dns.flags.AD), ), dns.resolver.Timeout()), ]) network.set_resolver(resolver) self.base.get_resolver.return_value = resolver with resolver: with self.assertRaises(TimeoutError): run_coroutine( network.repeated_query( "äöü.example.com".encode("idna"), dns.rdatatype.A, )) self.assertSequenceEqual(self.base.mock_calls, [ unittest.mock.call.get_resolver(), ])
def test_reconfigure_resolver_works_after_set_resolver(self): network.set_resolver(unittest.mock.sentinel.resolver) with unittest.mock.patch("dns.resolver.Resolver") as Resolver: network.reconfigure_resolver() Resolver.assert_called_with() self.assertEqual(network.get_resolver(), Resolver())
def test_overridden_thread_local_behaves_like_fixed(self): resolver = MockResolver(self) resolver.define_actions([ ( ( "xn--4ca0bs.example.com", dns.rdatatype.A, dns.rdataclass.IN, False, (dns.flags.RD | dns.flags.AD), ), dns.resolver.Timeout() ), ( ( "xn--4ca0bs.example.com", dns.rdatatype.A, dns.rdataclass.IN, True, (dns.flags.RD | dns.flags.AD), ), dns.resolver.Timeout() ), ]) network.set_resolver(resolver) self.base.get_resolver.return_value = resolver with resolver: with self.assertRaises(TimeoutError): run_coroutine(network.repeated_query( "äöü.example.com".encode("idna"), dns.rdatatype.A, )) self.assertSequenceEqual( self.base.mock_calls, [ unittest.mock.call.get_resolver(), ] )
def test_set_resolver(self): network.set_resolver(unittest.mock.sentinel.resolver) self.assertIs( network.get_resolver(), unittest.mock.sentinel.resolver, )