Changes to get test suite to pass again.

This commit is contained in:
PhilipWafula 2021-10-07 16:51:26 +03:00
parent 355f8d86f2
commit 0edbfbc29c
Signed by untrusted user: mango-habanero
GPG Key ID: B00CE9034DA19FB7
4 changed files with 20 additions and 21 deletions

View File

@ -28,7 +28,6 @@ def test_filter_statement_transactions(transactions_list):
def test_generate(activated_account,
cache_default_token_data,
cache_statement,
cache_preferences,
celery_session_worker,
init_cache,
@ -37,22 +36,22 @@ def test_generate(activated_account,
preferences,
preferences_metadata_url,
transactions_list):
with requests_mock.Mocker(real_http=False) as request_mocker:
request_mocker.register_uri('GET', preferences_metadata_url, status_code=200, reason='OK', json=preferences)
statement_transactions = filter_statement_transactions(transactions_list)
for transaction in statement_transactions:
querying_party = activated_account.blockchain_address
recipient_transaction, sender_transaction = transaction_actors(transaction)
if recipient_transaction.get('blockchain_address') == querying_party:
generate(querying_party, None, recipient_transaction)
if sender_transaction.get('blockchain_address') == querying_party:
generate(querying_party, None, sender_transaction)
time.sleep(2)
identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address))
key = cache_data_key(identifier, ':cic.statement')
statement = get_cached_data(key)
statement = json.loads(statement)
assert len(statement) == 1
statement_transactions = filter_statement_transactions(transactions_list)
for transaction in statement_transactions:
querying_party = activated_account.blockchain_address
recipient_transaction, sender_transaction = transaction_actors(transaction)
if recipient_transaction.get('blockchain_address') == querying_party:
recipient_transaction['alt_blockchain_address'] = sender_transaction.get('blockchain_address')
generate(querying_party, None, recipient_transaction)
if sender_transaction.get('blockchain_address') == querying_party:
sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address')
generate(querying_party, None, sender_transaction)
time.sleep(2)
identifier = bytes.fromhex(activated_account.blockchain_address)
key = cache_data_key(identifier, ':cic.statement')
statement = get_cached_data(key)
statement = json.loads(statement)
assert len(statement) == 1
def test_get_cached_statement(activated_account, cache_statement, statement):

View File

@ -57,7 +57,7 @@ def test_menu_processor(activated_account,
available_balance=available_balance,
token_symbol=token_symbol)
identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address))
identifier = bytes.fromhex(activated_account.blockchain_address)
key = cache_data_key(identifier, ':cic.adjusted_balance')
adjusted_balance = 45931650.64654012
cache_data(key, json.dumps(adjusted_balance))
@ -108,7 +108,7 @@ def test_menu_processor(activated_account,
display_key = 'ussd.kenya.display_user_metadata'
ussd_menu = UssdMenu.find_by_name('display_user_metadata')
name = ussd_menu.get('name')
identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address))
identifier = bytes.fromhex(activated_account.blockchain_address)
person_metadata = PersonMetadata(identifier)
cached_person_metadata = person_metadata.get_cached_metadata()
resp = response(activated_account, display_key, name, init_database, generic_ussd_session)

View File

@ -114,6 +114,7 @@ def test_statement_callback(activated_account, mocker, transactions_list):
s_statement_callback.apply_async().get()
statement_transactions = filter_statement_transactions(transactions_list)
recipient_transaction, sender_transaction = transaction_actors(statement_transactions[0])
sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address')
mock_statement_generate.assert_called_with(
(activated_account.blockchain_address, sender_transaction), {}, queue='cic-ussd')

View File

@ -4,7 +4,6 @@ import random
import uuid
# external imports
from chainlib.eth.address import to_checksum_address
from faker import Faker
from faker_e164.providers import E164Provider
@ -21,7 +20,7 @@ def phone_number() -> str:
def blockchain_address() -> str:
return to_checksum_address('0x' + os.urandom(20).hex())
return os.urandom(20).hex().lower()
def session_id() -> str: