1 # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 2 # 3 # SPDX-License-Identifier: MPL-2.0 4 # 5 # This Source Code Form is subject to the terms of the Mozilla Public 6 # License, v. 2.0. If a copy of the MPL was not distributed with this 7 # file, you can obtain one at https://mozilla.org/MPL/2.0/. 8 # 9 # See the COPYRIGHT file distributed with this work for additional 10 # information regarding copyright ownership. 11 12 import dns.zone 13 import pytest 14 15 16 def zone_contains( 17 zone: dns.zone.Zone, rrset: dns.rrset.RRset, compare_ttl=False 18 ) -> bool: 19 """Check if a zone contains RRset""" 20 21 def compare_rrs(rr1, rrset): 22 rr2 = next((other_rr for other_rr in rrset if rr1 == other_rr), None) 23 if rr2 is None: 24 return False 25 if compare_ttl: 26 return rr1.ttl == rr2.ttl 27 return True 28 29 for _, node in zone.nodes.items(): 30 for rdataset in node: 31 for rr in rdataset: 32 if compare_rrs(rr, rrset): 33 return True 34 35 return False 36 37 38 def file_contents_contain(file, substr): 39 with open(file, "r", encoding="utf-8") as fp: 40 for line in fp: 41 if f"{substr}" in line: 42 return True 43 return False 44 45 46 def param(*args, **kwargs): 47 if "id" not in kwargs: 48 kwargs["id"] = args[0] # use first argument as test ID 49 return pytest.param(*args, **kwargs) 50