2008-09-01 01:40:06 +02:00
|
|
|
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
|
2008-09-01 01:40:06 +02:00
|
|
|
|
2009-01-11 14:49:03 +01:00
|
|
|
from gajim_mocks import *
|
|
|
|
from xmpp_mocks import IdleQueueThread
|
2008-09-01 01:40:06 +02:00
|
|
|
|
|
|
|
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),
|
2010-02-08 15:08:40 +01:00
|
|
|
(JABBERCZ_SRV_NAME, 'srv', True)]
|
2008-09-01 01:40:06 +02:00
|
|
|
|
|
|
|
class TestResolver(unittest.TestCase):
|
2010-02-08 15:08:40 +01:00
|
|
|
'''
|
|
|
|
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)
|
2010-02-08 15:08:40 +01:00
|
|
|
self._reset()
|
|
|
|
self.resolver = None
|
|
|
|
|
|
|
|
def tearDown(self):
|
2017-08-09 15:34:58 +02:00
|
|
|
self.main_context.pop_thread_default()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _reset(self):
|
|
|
|
self.expect_results = False
|
|
|
|
self.resolver = None
|
|
|
|
|
2017-08-09 15:34:58 +02:00
|
|
|
def testGioResolver(self):
|
2010-02-08 15:08:40 +01:00
|
|
|
self._reset()
|
2017-08-09 15:34:58 +02:00
|
|
|
self.resolver = resolver.GioResolver()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-09 15:34:58 +02:00
|
|
|
for name, type_, expect_results in TEST_LIST:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.expect_results = expect_results
|
2017-08-09 15:34:58 +02:00
|
|
|
self._runGR(name, type_)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-09 15:34:58 +02:00
|
|
|
def _runGR(self, name, type_):
|
2010-02-08 15:08:40 +01:00
|
|
|
self.resolver.resolve(
|
|
|
|
host = name,
|
2017-08-09 15:34:58 +02:00
|
|
|
type_ = type_,
|
2010-02-08 15:08:40 +01:00
|
|
|
on_ready = self._myonready)
|
2017-08-09 15:34:58 +02:00
|
|
|
|
|
|
|
self.main_loop.run()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
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)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2017-08-09 15:34:58 +02:00
|
|
|
self.assertTrue(result_set == [])
|
|
|
|
self.main_loop.quit()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2008-09-01 01:40:06 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2010-02-08 15:08:40 +01:00
|
|
|
unittest.main()
|