diff options
| author | Bob Halley <halley@dnspython.org> | 2021-02-18 09:46:20 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-18 09:46:20 -0800 |
| commit | 9ed0320f1f150065edfbd818be939d1b8d1729c3 (patch) | |
| tree | 1d24e0c8e817d5e6629391db4b44d6ad7f7c1126 | |
| parent | a9dc095ad49d1e1a11197af31b188bb7c50d85de (diff) | |
| parent | 7d4d4715b5ebbe01cc4e4a0da662116263d747b1 (diff) | |
| download | dnspython-9ed0320f1f150065edfbd818be939d1b8d1729c3.tar.gz | |
Merge pull request #636 from kimbo/kl/zone-contains
make `name in zone` consistent with `zone[name]`
| -rw-r--r-- | dns/zone.py | 5 | ||||
| -rw-r--r-- | tests/test_zone.py | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/dns/zone.py b/dns/zone.py index c9c1c20..ac95763 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -162,8 +162,9 @@ class Zone(dns.transaction.TransactionManager): key = self._validate_name(key) return self.nodes.get(key) - def __contains__(self, other): - return other in self.nodes + def __contains__(self, key): + key = self._validate_name(key) + return key in self.nodes def find_node(self, name, create=False): """Find a node in the zone, possibly creating it. diff --git a/tests/test_zone.py b/tests/test_zone.py index 66f3ad5..26adc87 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -872,5 +872,15 @@ class VersionedZoneTestCase(unittest.TestCase): rds = txn.get('example.', 'soa') self.assertEqual(rds[0].serial, 1) + def testNameInZoneWithStr(self): + z = dns.zone.from_text(example_text, 'example.', relativize=False) + self.assertTrue('ns1.example.' in z) + self.assertTrue('bar.foo.example.' in z) + + def testNameInZoneWhereNameIsNotValid(self): + z = dns.zone.from_text(example_text, 'example.', relativize=False) + with self.assertRaises(KeyError): + self.assertTrue(1 in z) + if __name__ == '__main__': unittest.main() |
