summaryrefslogtreecommitdiff
path: root/tests/test_gresolver.py
blob: 4238df7741cc48297bd494e2ae6d2341f76efd83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- Mode: Python -*-

import unittest

import glib
import gio


class TestResolver(unittest.TestCase):
    def setUp(self):
        self.resolver = gio.resolver_get_default()

    def test_resolver_lookup_by_name(self):
        addresses = self.resolver.lookup_by_name("pygtk.org", cancellable=None)
        self.failUnless(isinstance(addresses[0], gio.InetAddress))

    def test_resolver_lookup_by_address(self):
        address = gio.inet_address_new_from_string("8.8.8.8")
        dns = self.resolver.lookup_by_address(address, cancellable=None)
        self.failUnlessEqual(dns, "google-public-dns-a.google.com")
    
    def test_resolver_lookup_by_name_async(self):
        def callback(resolver, result):
            try:
                addresses = resolver.lookup_by_name_finish(result)
                self.failUnless(isinstance(addresses[0], gio.InetAddress))
            finally:
                loop.quit()

        self.resolver.lookup_by_name_async(callback, "pygtk.org")

        loop = glib.MainLoop()
        loop.run()

    def test_resolver_lookup_by_address_async(self):
        def callback(resolver, result):
            try:
                dns = resolver.lookup_by_address_finish(result)
                self.failUnlessEqual(dns, "google-public-dns-b.google.com")
            finally:
                loop.quit()

        address = gio.inet_address_new_from_string("8.8.4.4")
        self.resolver.lookup_by_address_async(callback, address)

        loop = glib.MainLoop()
        loop.run()

""" Commented out because this requires an active internet connection and a
    router that supports SRV lookups

    def test_resolver_lookup_service(self):
        targets = self.resolver.lookup_service("xmpp-client", "tcp", "google.com")
        self.failUnless(isinstance(targets[0], gio.SrvTarget))

    def test_resolver_lookup_service_async(self):
        def callback(resolver, result):
            try:
                targets = resolver.lookup_service_finish(result)
                self.failUnless(isinstance(targets[0], gio.SrvTarget))
            finally:
                loop.quit()

        self.resolver.lookup_service_async(callback, "xmpp-client", "tcp", "google.com")

        loop = glib.MainLoop()
        loop.run()
"""