File: test_utils.py

package info (click to toggle)
python-ws4py 0.6.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 676 kB
  • sloc: python: 4,552; makefile: 137; javascript: 96
file content (29 lines) | stat: -rw-r--r-- 871 bytes parent folder | download
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
# -*- coding: utf-8 -*-
import unittest

try:
    from unittest.mock import MagicMock
except ImportError:
    from mock import MagicMock

from ws4py import format_addresses
from ws4py.websocket import WebSocket


class WSUtilities(unittest.TestCase):
    def test_format_address(self):
        m = MagicMock()
        m.getsockname.return_value = ('127.0.0.1', 52300, None, None)
        m.getpeername.return_value = ('127.0.0.1', 4800, None, None)
        ws = WebSocket(sock=m)

        log = format_addresses(ws)
        self.assertEqual(log, "[Local => 127.0.0.1:52300 | Remote => 127.0.0.1:4800]")

if __name__ == '__main__':
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    for testcase in [WSUtilities]:
        tests = loader.loadTestsFromTestCase(testcase)
        suite.addTests(tests)
    unittest.TextTestRunner(verbosity=2).run(suite)