gajim-plural/test/integration/test_resolver.py

74 lines
1.9 KiB
Python
Raw Normal View History

import unittest
import time
import lib
lib.setup_env()
2017-08-09 15:34:58 +02:00
from gi.repository import GLib
2017-08-12 02:39:55 +02:00
from gajim.common import resolver
from gajim_mocks import *
from xmpp_mocks import IdleQueueThread
NONSENSE_NAME = 'sfsdfsdfsdf.sdfs.fsd'
JABBERCZ_TXT_NAME = '_xmppconnect.jabber.cz'
JABBERCZ_SRV_NAME = '_xmpp-client._tcp.jabber.cz'
2017-09-19 15:52:53 +02:00
TEST_LIST = [(NONSENSE_NAME, 'srv', False),
(JABBERCZ_SRV_NAME, 'srv', True)]
class TestResolver(unittest.TestCase):
'''
Test for LibAsyncNSResolver and NSLookupResolver. Requires working
network connection.
'''
def setUp(self):
2017-08-09 15:34:58 +02:00
self.main_context = GLib.MainContext()
self.main_context.push_thread_default()
self.main_loop = GLib.MainLoop(self.main_context)
self._reset()
self.resolver = None
def tearDown(self):
2017-08-09 15:34:58 +02:00
self.main_context.pop_thread_default()
def _reset(self):
self.expect_results = False
self.resolver = None
2017-08-09 15:34:58 +02:00
def testGioResolver(self):
self._reset()
2017-08-09 15:34:58 +02:00
self.resolver = resolver.GioResolver()
2017-08-09 15:34:58 +02:00
for name, type_, expect_results in TEST_LIST:
self.expect_results = expect_results
2017-08-09 15:34:58 +02:00
self._runGR(name, type_)
2017-08-09 15:34:58 +02:00
def _runGR(self, name, type_):
self.resolver.resolve(
host = name,
2017-08-09 15:34:58 +02:00
type_ = type_,
on_ready = self._myonready)
2017-08-09 15:34:58 +02:00
self.main_loop.run()
def _myonready(self, name, result_set):
if __name__ == '__main__':
from pprint import pprint
pprint('on_ready called ...')
pprint('hostname: %s' % name)
pprint('result set: %s' % result_set)
pprint('res.resolved_hosts: %s' % self.resolver.resolved_hosts)
pprint('')
if self.expect_results:
2017-08-09 15:34:58 +02:00
self.assertTrue(len(result_set) > 0)
else:
2017-08-09 15:34:58 +02:00
self.assertTrue(result_set == [])
self.main_loop.quit()
if __name__ == '__main__':
unittest.main()