def test_parse_single_service(): service_params = ("_abc._tcp.local", "service", ["10.0.10.1"], 123, {"foo": "bar"}) message = dns_utils.add_service(dns.DnsMessage(), *service_params) parsed = mdns.parse_services(message) assert len(parsed) == 1 dns_utils.assert_service(parsed[0], *service_params)
def test_parse_with_name_and_type(): service_params = ("_abc._tcp.local", "service", [], 0, {}) message = dns_utils.add_service(dns.DnsMessage(), *service_params) parsed = mdns.parse_services(message) assert len(parsed) == 1 dns_utils.assert_service(parsed[0], *service_params)
def test_parse_with_port_and_address(): service_params = ("_abc._tcp.local", "service", ["10.0.0.1"], 123, {}) message = dns_utils.add_service(dns.DnsMessage(), *service_params) parsed = mdns.parse_services(message) assert len(parsed) == 1 dns_utils.assert_service(parsed[0], *service_params)
def test_parse_double_service(): service1_params = ("_abc._tcp.local", "service1", "10.0.10.1", 123, {"foo": "bar"}) service2_params = ( "_def._tcp.local", "service2", "10.0.10.2", 456, {"fizz": "buzz"}, ) message = dns_utils.add_service(mdns.DnsMessage(), *service1_params) message = dns_utils.add_service(message, *service2_params) parsed = mdns.parse_services(message) assert len(parsed) == 2 dns_utils.assert_service(parsed[0], *service1_params) dns_utils.assert_service(parsed[1], *service2_params)