Format for PEP8 test_api and samples (almost)

This commit is contained in:
Lee Miller 2022-05-24 23:04:55 +03:00
parent e12e9c4155
commit b25ed553bc
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 50 additions and 49 deletions

View File

@ -21,7 +21,8 @@ sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f'
# stream: 1, version: 2 # stream: 1, version: 2
sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79' sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79'
sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733 sample_factor = \
66858749573256452658262553961707680376751171096153613379801854825275240965733
# G * sample_factor # G * sample_factor
sample_point = ( sample_point = (
33567437183004486938355437500683826356288335339807546987348409590129959362313, 33567437183004486938355437500683826356288335339807546987348409590129959362313,
@ -36,9 +37,13 @@ sample_deterministic_addr4 = 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'
sample_daddr3_512 = 18875720106589866286514488037355423395410802084648916523381 sample_daddr3_512 = 18875720106589866286514488037355423395410802084648916523381
sample_daddr4_512 = 25152821841976547050350277460563089811513157529113201589004 sample_daddr4_512 = 25152821841976547050350277460563089811513157529113201589004
sample_statusbar_msg = "new status bar message" sample_statusbar_msg = 'new status bar message'
sample_inbox_msg_ids = ['27e644765a3e4b2e973ee7ccf958ea20', '51fc5531-3989-4d69-bbb5-68d64b756f5b', sample_inbox_msg_ids = [
'2c975c515f8b414db5eea60ba57ba455', 'bc1f2d8a-681c-4cc0-9a12-6067c7e1ac24'] '27e644765a3e4b2e973ee7ccf958ea20', '51fc5531-3989-4d69-bbb5-68d64b756f5b',
# second address in sample_test_subscription_address is for the announcement broadcast '2c975c515f8b414db5eea60ba57ba455', 'bc1f2d8a-681c-4cc0-9a12-6067c7e1ac24']
sample_test_subscription_address = ['BM-2cWQLCBGorT9pUGkYSuGGVr9LzE4mRnQaq', 'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw'] # second address in sample_subscription_addresses is
# for the announcement broadcast, but is it matter?
sample_subscription_addresses = [
'BM-2cWQLCBGorT9pUGkYSuGGVr9LzE4mRnQaq',
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw']
sample_subscription_name = 'test sub' sample_subscription_name = 'test sub'

View File

@ -12,8 +12,10 @@ from six.moves import xmlrpc_client # nosec
import psutil import psutil
from .samples import ( from .samples import (
sample_seed, sample_deterministic_addr3, sample_deterministic_addr4, sample_statusbar_msg, sample_deterministic_addr3, sample_deterministic_addr4, sample_seed,
sample_inbox_msg_ids, sample_test_subscription_address, sample_subscription_name) sample_inbox_msg_ids, sample_statusbar_msg,
sample_subscription_addresses, sample_subscription_name
)
from .test_process import TestProcessProto from .test_process import TestProcessProto
@ -114,43 +116,38 @@ class TestAPI(TestAPIProto):
) )
self.assertEqual( self.assertEqual(
len(json.loads( len(json.loads(
self.api.getInboxMessageById(hexlify(sample_inbox_msg_ids[2])))["inboxMessage"]), self.api.getInboxMessageById(
hexlify(sample_inbox_msg_ids[2])))["inboxMessage"]),
1 1
) )
self.assertEqual( self.assertEqual(
len(json.loads( len(json.loads(
self.api.getInboxMessagesByReceiver(sample_deterministic_addr4))["inboxMessages"]), self.api.getInboxMessagesByReceiver(
sample_deterministic_addr4))["inboxMessages"]),
4 4
) )
def test_message_trash(self): def test_message_trash(self):
"""Test message inbox methods""" """Test message inbox methods"""
messages_before_delete = len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]) messages_before_delete = len(
self.assertEqual( json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"])
self.api.trashMessage(hexlify(sample_inbox_msg_ids[0])), for msgid in sample_inbox_msg_ids[:2]:
'Trashed message (assuming message existed).' self.assertEqual(
) self.api.trashMessage(hexlify(msgid)),
self.assertEqual( 'Trashed message (assuming message existed).'
self.api.trashInboxMessage(hexlify(sample_inbox_msg_ids[1])), )
'Trashed inbox message (assuming message existed).' self.assertEqual(len(
) json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]
self.assertEqual( ), messages_before_delete - 2)
len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]), for msgid in sample_inbox_msg_ids[:2]:
messages_before_delete - 2 self.assertEqual(
) self.api.undeleteMessage(hexlify(msgid)),
self.assertEqual( 'Undeleted message'
self.api.undeleteMessage(hexlify(sample_inbox_msg_ids[0])), )
'Undeleted message' self.assertEqual(len(
) json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]
self.assertEqual( ), messages_before_delete)
self.api.undeleteMessage(hexlify(sample_inbox_msg_ids[1])),
'Undeleted message'
)
self.assertEqual(
len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]),
messages_before_delete
)
def test_clientstatus_consistency(self): def test_clientstatus_consistency(self):
"""If networkStatus is notConnected networkConnections should be 0""" """If networkStatus is notConnected networkConnections should be 0"""
@ -265,7 +262,9 @@ class TestAPI(TestAPIProto):
"""Testing the API commands related to subscriptions""" """Testing the API commands related to subscriptions"""
self.assertEqual( self.assertEqual(
self.api.addSubscription(sample_test_subscription_address[0], sample_subscription_name.encode('base64')), self.api.addSubscription(
sample_subscription_addresses[0],
sample_subscription_name.encode('base64')),
'Added subscription.' 'Added subscription.'
) )
@ -273,18 +272,23 @@ class TestAPI(TestAPIProto):
# check_address # check_address
for sub in json.loads(self.api.listSubscriptions())['subscriptions']: for sub in json.loads(self.api.listSubscriptions())['subscriptions']:
# special address, added when sqlThread starts # special address, added when sqlThread starts
if sub['address'] == sample_test_subscription_address[0]: if sub['address'] == sample_subscription_addresses[0]:
added_subscription = sub added_subscription = sub
self.assertEqual(
base64.decodestring(sub['label']), sample_subscription_name
)
self.assertTrue(sub['enabled'])
break break
self.assertEqual( self.assertEqual(
base64.decodestring(added_subscription['label']) if added_subscription['label'] else None, base64.decodestring(added_subscription['label'])
if added_subscription['label'] else None,
sample_subscription_name) sample_subscription_name)
self.assertTrue(added_subscription['enabled']) self.assertTrue(added_subscription['enabled'])
for s in json.loads(self.api.listSubscriptions())['subscriptions']: for s in json.loads(self.api.listSubscriptions())['subscriptions']:
# special address, added when sqlThread starts # special address, added when sqlThread starts
if s['address'] == sample_test_subscription_address[1]: if s['address'] == sample_subscription_addresses[1]:
self.assertEqual( self.assertEqual(
base64.decodestring(s['label']), base64.decodestring(s['label']),
'Bitmessage new releases/announcements') 'Bitmessage new releases/announcements')
@ -295,17 +299,16 @@ class TestAPI(TestAPIProto):
'Could not find Bitmessage new releases/announcements' 'Could not find Bitmessage new releases/announcements'
' in subscriptions') ' in subscriptions')
self.assertEqual( self.assertEqual(
self.api.deleteSubscription(sample_test_subscription_address[0]), self.api.deleteSubscription(sample_subscription_addresses[0]),
'Deleted subscription if it existed.') 'Deleted subscription if it existed.')
self.assertEqual( self.assertEqual(
self.api.deleteSubscription(sample_test_subscription_address[1]), self.api.deleteSubscription(sample_subscription_addresses[1]),
'Deleted subscription if it existed.') 'Deleted subscription if it existed.')
self.assertEqual( self.assertEqual(
json.loads(self.api.listSubscriptions())['subscriptions'], []) json.loads(self.api.listSubscriptions())['subscriptions'], [])
def test_send(self): def test_send(self):
"""Test message sending""" """Test message sending"""
# self.api.createDeterministicAddresses(self._seed, 1, 4)
addr = self._add_random_address('random_2') addr = self._add_random_address('random_2')
msg = base64.encodestring('test message') msg = base64.encodestring('test message')
msg_subject = base64.encodestring('test_subject') msg_subject = base64.encodestring('test_subject')
@ -330,13 +333,6 @@ class TestAPI(TestAPIProto):
break break
else: else:
raise KeyError raise KeyError
# Find the message in inbox
# for m in json.loads(
# self.api.getInboxMessagesByReceiver(
# 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'))['inboxMessages']:
# if m['subject'] == msg_subject:
# inbox_msg = m['message']
# break
except ValueError: except ValueError:
self.fail('sendMessage returned error or ackData is not hex') self.fail('sendMessage returned error or ackData is not hex')
except KeyError: except KeyError: