-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added docs, README.md reference and pytest
- Loading branch information
Showing
3 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
tlslite.integration.tlsasynciodispatchermixin module | ||
================================================== | ||
|
||
.. automodule:: tlslite.integration.tlsasynciodispatchermixin | ||
:members: | ||
:special-members: __init__ | ||
:undoc-members: | ||
:show-inheritance: |
74 changes: 74 additions & 0 deletions
74
unit_tests/test_tlslite_integration_tlsasynciodispatchermixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import asyncio | ||
import unittest | ||
from unittest.mock import Mock | ||
from tlslite.integration.tlsasynciodispatchermixin import TLSAsyncioDispatcherMixIn | ||
|
||
|
||
class MockProtocol(asyncio.Protocol): | ||
|
||
def connection_lost(self, exc): | ||
self.in_write_event() | ||
|
||
def in_write_event(self): | ||
pass | ||
|
||
def readable(self): | ||
return True | ||
|
||
def writable(self): | ||
return True | ||
|
||
|
||
class TestTLSAsyncioDispatcherMixIn(unittest.TestCase): | ||
def setUp(self): | ||
self.protocol = TLSAsyncioDispatcherMixIn() | ||
self.protocol.__class__ = type('TestProtocol', (MockProtocol, TLSAsyncioDispatcherMixIn), {}) | ||
self.protocol.transport = Mock() | ||
self.protocol.tls_connection = Mock() | ||
|
||
def test_readable(self): | ||
self.protocol.wants_read_event = Mock(return_value=None) | ||
self.protocol._get_sibling_class = Mock(return_value=Mock(readable=Mock(return_value=True))) | ||
self.assertTrue(self.protocol.readable()) | ||
|
||
def test_writable(self): | ||
self.protocol.wants_write_event = Mock(return_value=None) | ||
self.protocol._get_sibling_class = Mock(return_value=Mock(writable=Mock(return_value=True))) | ||
self.assertTrue(self.protocol.writable()) | ||
|
||
def test_data_received(self): | ||
self.protocol.transport = Mock() | ||
self.protocol.sibling_class.data_received = Mock() | ||
self.protocol.data_received(b'test') | ||
self.protocol.sibling_class.data_received.assert_called_once_with(self.protocol, b'test') | ||
|
||
def test_connection_lost(self): | ||
self.protocol.in_write_event = Mock() | ||
self.protocol.connection_lost(None) | ||
self.protocol.in_write_event.assert_called_once() | ||
|
||
def test_connection_made(self): | ||
self.protocol.transport = Mock() | ||
self.protocol.sibling_class.connection_made = Mock() | ||
self.protocol.connection_made(self.protocol.transport) | ||
self.protocol.sibling_class.connection_made.assert_called_once_with(self.protocol.transport) | ||
|
||
def test_out_close_event(self): | ||
self.protocol.out_close_event() | ||
self.protocol.transport.close.assert_called_once() | ||
|
||
def test_recv(self): | ||
self.protocol.read_buffer = b"test" | ||
self.assertEqual(self.protocol.recv(), b"test") | ||
self.assertIsNone(self.protocol.read_buffer) | ||
|
||
def test_send(self): | ||
write_buffer = b"test" | ||
self.protocol.set_write_op = Mock() | ||
self.assertEqual(self.protocol.send(write_buffer), len(write_buffer)) | ||
self.protocol.set_write_op.assert_called_once_with(write_buffer) | ||
|
||
def test_close(self): | ||
self.protocol.set_close_op = Mock() | ||
self.protocol.close() | ||
self.protocol.set_close_op.assert_called_once() |