From 8806a06ab9c449ac0142634a69069bc68a497aea Mon Sep 17 00:00:00 2001 From: Ken Roberts Date: Fri, 17 Jun 2016 19:45:02 -0700 Subject: [PATCH] Test cleanups --- openlp/core/common/__init__.py | 8 ++++---- openlp/core/lib/projector/pjlink1.py | 2 +- .../openlp_core_common/test_projector_utilities.py | 4 ++-- .../functional/openlp_core_lib/test_projector_pjlink1.py | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index 488fbc63b..a5c86314c 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -206,9 +206,9 @@ def md5_hash(salt, data=None): """ log.debug('md5_hash(salt="{text}")'.format(text=salt)) hash_obj = hashlib.new('md5') - hash_obj.update(salt.encode('ascii')) + hash_obj.update(salt) if data: - hash_obj.update(data.encode('ascii')) + hash_obj.update(data) hash_value = hash_obj.hexdigest() log.debug('md5_hash() returning "{text}"'.format(text=hash_value)) return hash_value @@ -225,9 +225,9 @@ def qmd5_hash(salt, data=None): """ log.debug('qmd5_hash(salt="{text}"'.format(text=salt)) hash_obj = QHash(QHash.Md5) - hash_obj.addData(salt.encode('ascii')) + hash_obj.addData(salt) if data: - hash_obj.addData(data.encode('ascii')) + hash_obj.addData(data) hash_value = hash_obj.result().toHex() log.debug('qmd5_hash() returning "{hash}"'.format(hash=hash_value)) return hash_value diff --git a/openlp/core/lib/projector/pjlink1.py b/openlp/core/lib/projector/pjlink1.py index 302fc13ee..330e02b73 100644 --- a/openlp/core/lib/projector/pjlink1.py +++ b/openlp/core/lib/projector/pjlink1.py @@ -364,7 +364,7 @@ class PJLink1(QTcpSocket): else: log.debug('({ip}) Setting hash with salt="{data}"'.format(ip=self.ip, data=data_check[2])) log.debug('({ip}) pin="{data}"'.format(ip=self.ip, data=self.pin)) - salt = md5_hash(salt=data_check[2], data=self.pin) + salt = md5_hash(salt=data_check[2].encode('ascii'), data=self.pin.encode('ascii')) else: salt = None # We're connected at this point, so go ahead and do regular I/O diff --git a/tests/functional/openlp_core_common/test_projector_utilities.py b/tests/functional/openlp_core_common/test_projector_utilities.py index aebdd7509..72609956d 100644 --- a/tests/functional/openlp_core_common/test_projector_utilities.py +++ b/tests/functional/openlp_core_common/test_projector_utilities.py @@ -147,7 +147,7 @@ class testProjectorUtilities(TestCase): hash_ = qmd5_hash(salt=salt.encode('ascii'), data=pin.encode('ascii')) # THEN: Validate return has is same - self.assertEquals(hash_.decode('ascii'), test_hash, 'Qt-MD5 should have returned a good hash') + self.assertEquals(hash_, test_hash, 'Qt-MD5 should have returned a good hash') def test_qmd5_hash_bad(self): """ @@ -157,7 +157,7 @@ class testProjectorUtilities(TestCase): hash_ = qmd5_hash(salt=pin.encode('ascii'), data=salt.encode('ascii')) # THEN: return data is different - self.assertNotEquals(hash_.decode('ascii'), test_hash, 'Qt-MD5 should have returned a bad hash') + self.assertNotEquals(hash_, test_hash, 'Qt-MD5 should have returned a bad hash') def test_md5_non_ascii_string(self): """ diff --git a/tests/functional/openlp_core_lib/test_projector_pjlink1.py b/tests/functional/openlp_core_lib/test_projector_pjlink1.py index 1c56e5bec..815b26493 100644 --- a/tests/functional/openlp_core_lib/test_projector_pjlink1.py +++ b/tests/functional/openlp_core_lib/test_projector_pjlink1.py @@ -355,7 +355,7 @@ class TestPJLink(TestCase): pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE) # THEN: No Authentication signal should have been sent - mock_authentication.assert_called_with(pjlink.name, 'projectorAuthentication should have been called') + mock_authentication.emit.assert_called_with(pjlink.name) @patch.object(pjlink_test, 'waitForReadyRead') @patch.object(pjlink_test, 'state') @@ -372,7 +372,7 @@ class TestPJLink(TestCase): """ # GIVEN: Test object and data pjlink = pjlink_test - pjlink_pin = TEST_PIN + pjlink.pin = TEST_PIN mock_state.return_value = pjlink.ConnectedState mock_waitForReadyRead.return_value = True @@ -380,5 +380,5 @@ class TestPJLink(TestCase): pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE) # THEN: send_command should have the proper authentication - self.assertEquals("{test}".format(test=mock_send_command.call_args_list[0]), + self.assertEquals("{test}".format(test=mock_send_command.call_args), "call(data='{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))