forked from openlp/openlp
Test cleanups
This commit is contained in:
parent
7cc56af2bb
commit
8806a06ab9
@ -206,9 +206,9 @@ def md5_hash(salt, data=None):
|
|||||||
"""
|
"""
|
||||||
log.debug('md5_hash(salt="{text}")'.format(text=salt))
|
log.debug('md5_hash(salt="{text}")'.format(text=salt))
|
||||||
hash_obj = hashlib.new('md5')
|
hash_obj = hashlib.new('md5')
|
||||||
hash_obj.update(salt.encode('ascii'))
|
hash_obj.update(salt)
|
||||||
if data:
|
if data:
|
||||||
hash_obj.update(data.encode('ascii'))
|
hash_obj.update(data)
|
||||||
hash_value = hash_obj.hexdigest()
|
hash_value = hash_obj.hexdigest()
|
||||||
log.debug('md5_hash() returning "{text}"'.format(text=hash_value))
|
log.debug('md5_hash() returning "{text}"'.format(text=hash_value))
|
||||||
return hash_value
|
return hash_value
|
||||||
@ -225,9 +225,9 @@ def qmd5_hash(salt, data=None):
|
|||||||
"""
|
"""
|
||||||
log.debug('qmd5_hash(salt="{text}"'.format(text=salt))
|
log.debug('qmd5_hash(salt="{text}"'.format(text=salt))
|
||||||
hash_obj = QHash(QHash.Md5)
|
hash_obj = QHash(QHash.Md5)
|
||||||
hash_obj.addData(salt.encode('ascii'))
|
hash_obj.addData(salt)
|
||||||
if data:
|
if data:
|
||||||
hash_obj.addData(data.encode('ascii'))
|
hash_obj.addData(data)
|
||||||
hash_value = hash_obj.result().toHex()
|
hash_value = hash_obj.result().toHex()
|
||||||
log.debug('qmd5_hash() returning "{hash}"'.format(hash=hash_value))
|
log.debug('qmd5_hash() returning "{hash}"'.format(hash=hash_value))
|
||||||
return hash_value
|
return hash_value
|
||||||
|
@ -364,7 +364,7 @@ class PJLink1(QTcpSocket):
|
|||||||
else:
|
else:
|
||||||
log.debug('({ip}) Setting hash with salt="{data}"'.format(ip=self.ip, data=data_check[2]))
|
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))
|
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:
|
else:
|
||||||
salt = None
|
salt = None
|
||||||
# We're connected at this point, so go ahead and do regular I/O
|
# We're connected at this point, so go ahead and do regular I/O
|
||||||
|
@ -147,7 +147,7 @@ class testProjectorUtilities(TestCase):
|
|||||||
hash_ = qmd5_hash(salt=salt.encode('ascii'), data=pin.encode('ascii'))
|
hash_ = qmd5_hash(salt=salt.encode('ascii'), data=pin.encode('ascii'))
|
||||||
|
|
||||||
# THEN: Validate return has is same
|
# 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):
|
def test_qmd5_hash_bad(self):
|
||||||
"""
|
"""
|
||||||
@ -157,7 +157,7 @@ class testProjectorUtilities(TestCase):
|
|||||||
hash_ = qmd5_hash(salt=pin.encode('ascii'), data=salt.encode('ascii'))
|
hash_ = qmd5_hash(salt=pin.encode('ascii'), data=salt.encode('ascii'))
|
||||||
|
|
||||||
# THEN: return data is different
|
# 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):
|
def test_md5_non_ascii_string(self):
|
||||||
"""
|
"""
|
||||||
|
@ -355,7 +355,7 @@ class TestPJLink(TestCase):
|
|||||||
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
|
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
|
||||||
|
|
||||||
# THEN: No Authentication signal should have been sent
|
# 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, 'waitForReadyRead')
|
||||||
@patch.object(pjlink_test, 'state')
|
@patch.object(pjlink_test, 'state')
|
||||||
@ -372,7 +372,7 @@ class TestPJLink(TestCase):
|
|||||||
"""
|
"""
|
||||||
# GIVEN: Test object and data
|
# GIVEN: Test object and data
|
||||||
pjlink = pjlink_test
|
pjlink = pjlink_test
|
||||||
pjlink_pin = TEST_PIN
|
pjlink.pin = TEST_PIN
|
||||||
mock_state.return_value = pjlink.ConnectedState
|
mock_state.return_value = pjlink.ConnectedState
|
||||||
mock_waitForReadyRead.return_value = True
|
mock_waitForReadyRead.return_value = True
|
||||||
|
|
||||||
@ -380,5 +380,5 @@ class TestPJLink(TestCase):
|
|||||||
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
|
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
|
||||||
|
|
||||||
# THEN: send_command should have the proper authentication
|
# 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))
|
"call(data='{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))
|
||||||
|
Loading…
Reference in New Issue
Block a user