You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
import struct
|
|
import unittest
|
|
import mock
|
|
|
|
from os.path import dirname, realpath
|
|
from sys import argv, path
|
|
path.append(dirname(dirname(realpath(__file__))) + '/lib')
|
|
|
|
from DnsClient import DnsClient
|
|
|
|
class TestDnsClient(unittest.TestCase):
|
|
def setUp(self):
|
|
self._remote_addr = ('10.1.0.10', 1212)
|
|
|
|
self._client = DnsClient(self._remote_addr[0], self._remote_addr[1])
|
|
self._client._client = mock.Mock()
|
|
self._client._proto = mock.Mock()
|
|
|
|
def testGetIp(self):
|
|
request = mock.Mock()
|
|
response = mock.Mock()
|
|
response._answers = [('foo', 1, 1, 15, '\x01\x02\x03\x04')]
|
|
self._client._proto.createRequest.return_value = request
|
|
self._client._client.getRemoteAddr.return_value = self._remote_addr
|
|
self._client._client.issue.return_value = response
|
|
self.assertEqual(self._client.getIp('foo'), '1.2.3.4')
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(TestDnsClient)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|
|
|
|
# vim: set ft=python et ts=8 sw=4 sts=4:
|