added six.assertRegex() & few more changes
This commit is contained in:
parent
b47827fb54
commit
7da2369b93
|
@ -7,6 +7,7 @@ import base64
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import six
|
||||||
|
|
||||||
try: # nosec
|
try: # nosec
|
||||||
from xmlrpclib import ServerProxy, ProtocolError
|
from xmlrpclib import ServerProxy, ProtocolError
|
||||||
|
@ -126,94 +127,50 @@ class TestAPI(TestAPIProto):
|
||||||
|
|
||||||
def test_create_deterministic_addresses(self):
|
def test_create_deterministic_addresses(self):
|
||||||
"""Test creation of deterministic addresses"""
|
"""Test creation of deterministic addresses"""
|
||||||
if PY3:
|
self.assertEqual(
|
||||||
self.assertEqual(
|
self.api.getDeterministicAddress(self._seed.decode('utf-8'), 4, 1),
|
||||||
self.api.getDeterministicAddress(self._seed.decode('utf-8'), 4, 1),
|
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
|
||||||
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
|
self.assertEqual(
|
||||||
self.assertEqual(
|
self.api.getDeterministicAddress(self._seed.decode('utf-8'), 3, 1),
|
||||||
self.api.getDeterministicAddress(self._seed.decode('utf-8'), 3, 1),
|
'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN')
|
||||||
'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN')
|
six.assertRegex(
|
||||||
self.assertRegex(
|
self, self.api.getDeterministicAddress(self._seed.decode('utf-8'), 2, 1),
|
||||||
self.api.getDeterministicAddress(self._seed.decode('utf-8'), 2, 1),
|
r'^API Error 0002:')
|
||||||
r'^API Error 0002:')
|
|
||||||
|
|
||||||
# This is here until the streams will be implemented
|
# This is here until the streams will be implemented
|
||||||
self.assertRegex(
|
six.assertRegex(
|
||||||
self.api.getDeterministicAddress(self._seed.decode('utf-8'), 3, 2),
|
self, self.api.getDeterministicAddress(self._seed.decode('utf-8'), 3, 2),
|
||||||
r'API Error 0003:')
|
r'API Error 0003:')
|
||||||
self.assertRegex(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 1, 4, 2),
|
self, self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 1, 4, 2),
|
||||||
r'API Error 0003:')
|
r'API Error 0003:')
|
||||||
|
|
||||||
self.assertRegex(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses('', 1),
|
self, self.api.createDeterministicAddresses('', 1),
|
||||||
r'API Error 0001:')
|
r'API Error 0001:')
|
||||||
self.assertRegex(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 1, 2),
|
self, self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 1, 2),
|
||||||
r'API Error 0002:')
|
r'API Error 0002:')
|
||||||
self.assertRegex(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 0),
|
self, self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 0),
|
||||||
r'API Error 0004:')
|
r'API Error 0004:')
|
||||||
self.assertRegex(
|
six.assertRegex(
|
||||||
self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 1000),
|
self, self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 1000),
|
||||||
r'API Error 0005:')
|
r'API Error 0005:')
|
||||||
|
|
||||||
addresses = json.loads(
|
addresses = json.loads(
|
||||||
self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 2, 4)
|
self.api.createDeterministicAddresses(self._seed.decode('utf-8'), 2, 4)
|
||||||
)['addresses']
|
)['addresses']
|
||||||
self.assertEqual(len(addresses), 2)
|
self.assertEqual(len(addresses), 2)
|
||||||
self.assertEqual(addresses[0], 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
|
self.assertEqual(addresses[0], 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
|
||||||
for addr in addresses:
|
for addr in addresses:
|
||||||
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
||||||
else:
|
|
||||||
self.assertEqual(
|
|
||||||
self.api.getDeterministicAddress(self._seed, 4, 1),
|
|
||||||
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
|
|
||||||
self.assertEqual(
|
|
||||||
self.api.getDeterministicAddress(self._seed, 3, 1),
|
|
||||||
'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN')
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.getDeterministicAddress(self._seed, 2, 1),
|
|
||||||
r'^API Error 0002:')
|
|
||||||
|
|
||||||
# This is here until the streams will be implemented
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.getDeterministicAddress(self._seed, 3, 2),
|
|
||||||
r'API Error 0003:')
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.createDeterministicAddresses(self._seed, 1, 4, 2),
|
|
||||||
r'API Error 0003:')
|
|
||||||
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.createDeterministicAddresses('', 1),
|
|
||||||
r'API Error 0001:')
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.createDeterministicAddresses(self._seed, 1, 2),
|
|
||||||
r'API Error 0002:')
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.createDeterministicAddresses(self._seed, 0),
|
|
||||||
r'API Error 0004:')
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.createDeterministicAddresses(self._seed, 1000),
|
|
||||||
r'API Error 0005:')
|
|
||||||
|
|
||||||
addresses = json.loads(
|
|
||||||
self.api.createDeterministicAddresses(self._seed, 2, 4)
|
|
||||||
)['addresses']
|
|
||||||
self.assertEqual(len(addresses), 2)
|
|
||||||
self.assertEqual(addresses[0], 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
|
|
||||||
for addr in addresses:
|
|
||||||
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
|
||||||
|
|
||||||
def test_create_random_address(self):
|
def test_create_random_address(self):
|
||||||
"""API command 'createRandomAddress': basic BM-address validation"""
|
"""API command 'createRandomAddress': basic BM-address validation"""
|
||||||
addr = self._add_random_address('random_1')
|
addr = self._add_random_address('random_1')
|
||||||
if PY3:
|
six.assertRegex(self, addr, r'^BM-')
|
||||||
self.assertRegex(addr, r'^BM-')
|
six.assertRegex(self, addr[3:], r'[a-zA-Z1-9]+$')
|
||||||
self.assertRegex(addr[3:], r'[a-zA-Z1-9]+$')
|
|
||||||
else:
|
|
||||||
self.assertRegexpMatches(addr, r'^BM-')
|
|
||||||
self.assertRegexpMatches(addr[3:], r'[a-zA-Z1-9]+$')
|
|
||||||
# Whitepaper says "around 36 character"
|
# Whitepaper says "around 36 character"
|
||||||
self.assertLessEqual(len(addr[3:]), 40)
|
self.assertLessEqual(len(addr[3:]), 40)
|
||||||
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
self.assertEqual(self.api.deleteAddress(addr), 'success')
|
||||||
|
@ -431,48 +388,25 @@ class TestAPI(TestAPIProto):
|
||||||
|
|
||||||
def test_chan(self):
|
def test_chan(self):
|
||||||
"""Testing chan creation/joining"""
|
"""Testing chan creation/joining"""
|
||||||
if PY3:
|
# Create chan with known address
|
||||||
# Create chan with known address
|
self.assertEqual(
|
||||||
self.assertEqual(
|
self.api.createChan(self._seed.decode("utf-8")),
|
||||||
self.api.createChan(self._seed.decode("utf-8")),
|
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'
|
||||||
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'
|
)
|
||||||
)
|
# cleanup
|
||||||
# cleanup
|
self.assertEqual(
|
||||||
self.assertEqual(
|
self.api.leaveChan('BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'),
|
||||||
self.api.leaveChan('BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'),
|
'success'
|
||||||
'success'
|
)
|
||||||
)
|
# Join chan with addresses of version 3 or 4
|
||||||
# Join chan with addresses of version 3 or 4
|
for addr in (
|
||||||
for addr in (
|
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK',
|
||||||
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK',
|
'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN'
|
||||||
'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN'
|
):
|
||||||
):
|
self.assertEqual(self.api.joinChan(self._seed.decode("utf-8"), addr), 'success')
|
||||||
self.assertEqual(self.api.joinChan(self._seed.decode("utf-8"), addr), 'success')
|
self.assertEqual(self.api.leaveChan(addr), 'success')
|
||||||
self.assertEqual(self.api.leaveChan(addr), 'success')
|
# Joining with wrong address should fail
|
||||||
# Joining with wrong address should fail
|
six.assertRegex(
|
||||||
self.assertRegex(
|
self, self.api.joinChan(self._seed.decode("utf-8"), 'BM-2cWzSnwjJ7yRP3nLEW'),
|
||||||
self.api.joinChan(self._seed.decode("utf-8"), 'BM-2cWzSnwjJ7yRP3nLEW'),
|
r'^API Error 0008:'
|
||||||
r'^API Error 0008:'
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.assertEqual(
|
|
||||||
self.api.createChan(self._seed),
|
|
||||||
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'
|
|
||||||
)
|
|
||||||
# cleanup
|
|
||||||
self.assertEqual(
|
|
||||||
self.api.leaveChan('BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'),
|
|
||||||
'success'
|
|
||||||
)
|
|
||||||
# Join chan with addresses of version 3 or 4
|
|
||||||
for addr in (
|
|
||||||
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK',
|
|
||||||
'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN'
|
|
||||||
):
|
|
||||||
self.assertEqual(self.api.joinChan(self._seed, addr), 'success')
|
|
||||||
self.assertEqual(self.api.leaveChan(addr), 'success')
|
|
||||||
# Joining with wrong address should fail
|
|
||||||
self.assertRegexpMatches(
|
|
||||||
self.api.joinChan(self._seed, 'BM-2cWzSnwjJ7yRP3nLEW'),
|
|
||||||
r'^API Error 0008:'
|
|
||||||
)
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ class TestProcessProto(unittest.TestCase):
|
||||||
thread_names = subprocess.check_output([
|
thread_names = subprocess.check_output([
|
||||||
"ps", "-L", "-o", "comm=", "--pid",
|
"ps", "-L", "-o", "comm=", "--pid",
|
||||||
str(self.process.pid)
|
str(self.process.pid)
|
||||||
]).split()
|
]).decode('utf-8').split()
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
thread_names = []
|
thread_names = []
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user