Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35 (#17)
* Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35
This commit adds unit tests for current api functionality.
- currently no mocking, all tests are run on the device.
- the library is now compatible with python 2.7 and python 3.5, use tox for tests
- schema checks are done with voluptuous
refactoring:
- protocol is separated into its own file, smartplug adapted to receive protocol worker as parameter.
- cleaned up the initialization routine, initialization is done on use, not on creation of smartplug
- added model and features properties, identity kept for backwards compatibility
- no more storing of local variables outside _sys_info, paves a way to handle state changes sanely (without complete reinitialization)
* Fix CI warnings, remove unused leftover code
* Rename _initialize to _fetch_sysinfo, as that's what it does.
* examples.cli: fix identify call, prettyprint sysinfo, update readme which had false format for led setting
* Add tox-travis for automated testing.
2016-12-16 22:51:56 +00:00
|
|
|
from unittest import TestCase
|
2017-04-14 12:24:58 +00:00
|
|
|
from ..protocol import TPLinkSmartHomeProtocol
|
Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35 (#17)
* Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35
This commit adds unit tests for current api functionality.
- currently no mocking, all tests are run on the device.
- the library is now compatible with python 2.7 and python 3.5, use tox for tests
- schema checks are done with voluptuous
refactoring:
- protocol is separated into its own file, smartplug adapted to receive protocol worker as parameter.
- cleaned up the initialization routine, initialization is done on use, not on creation of smartplug
- added model and features properties, identity kept for backwards compatibility
- no more storing of local variables outside _sys_info, paves a way to handle state changes sanely (without complete reinitialization)
* Fix CI warnings, remove unused leftover code
* Rename _initialize to _fetch_sysinfo, as that's what it does.
* examples.cli: fix identify call, prettyprint sysinfo, update readme which had false format for led setting
* Add tox-travis for automated testing.
2016-12-16 22:51:56 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
class TestTPLinkSmartHomeProtocol(TestCase):
|
|
|
|
def test_encrypt(self):
|
|
|
|
d = json.dumps({'foo': 1, 'bar': 2})
|
|
|
|
encrypted = TPLinkSmartHomeProtocol.encrypt(d)
|
2017-01-17 13:38:23 +00:00
|
|
|
# encrypt adds a 4 byte header
|
|
|
|
encrypted = encrypted[4:]
|
Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35 (#17)
* Refactor & add unittests for almost all functionality, add tox for running tests on py27 and py35
This commit adds unit tests for current api functionality.
- currently no mocking, all tests are run on the device.
- the library is now compatible with python 2.7 and python 3.5, use tox for tests
- schema checks are done with voluptuous
refactoring:
- protocol is separated into its own file, smartplug adapted to receive protocol worker as parameter.
- cleaned up the initialization routine, initialization is done on use, not on creation of smartplug
- added model and features properties, identity kept for backwards compatibility
- no more storing of local variables outside _sys_info, paves a way to handle state changes sanely (without complete reinitialization)
* Fix CI warnings, remove unused leftover code
* Rename _initialize to _fetch_sysinfo, as that's what it does.
* examples.cli: fix identify call, prettyprint sysinfo, update readme which had false format for led setting
* Add tox-travis for automated testing.
2016-12-16 22:51:56 +00:00
|
|
|
self.assertEqual(d, TPLinkSmartHomeProtocol.decrypt(encrypted))
|
2018-08-08 14:52:03 +00:00
|
|
|
|
|
|
|
def test_encrypt_unicode(self):
|
|
|
|
d = "{'snowman': '\u2603'}"
|
|
|
|
|
|
|
|
e = bytes([208, 247, 132, 234, 133, 242, 159, 254, 144, 183,
|
|
|
|
141, 173, 138, 104, 240, 115, 84, 41])
|
|
|
|
|
|
|
|
encrypted = TPLinkSmartHomeProtocol.encrypt(d)
|
|
|
|
# encrypt adds a 4 byte header
|
|
|
|
encrypted = encrypted[4:]
|
|
|
|
|
|
|
|
self.assertEqual(e, encrypted)
|
|
|
|
|
|
|
|
def test_decrypt_unicode(self):
|
|
|
|
e = bytes([208, 247, 132, 234, 133, 242, 159, 254, 144, 183,
|
|
|
|
141, 173, 138, 104, 240, 115, 84, 41])
|
|
|
|
|
|
|
|
d = "{'snowman': '\u2603'}"
|
|
|
|
|
|
|
|
self.assertEqual(d, TPLinkSmartHomeProtocol.decrypt(e))
|