Update metadata pointer salt values
This commit is contained in:
parent
c4919d56b1
commit
1df62717ef
@ -20,7 +20,7 @@ def define_account_tx_metadata(user: Account):
|
|||||||
)
|
)
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
account_metadata = get_cached_data(key=key)
|
account_metadata = get_cached_data(key=key)
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ def get_cached_operational_balance(blockchain_address: str):
|
|||||||
"""
|
"""
|
||||||
key = create_cached_data_key(
|
key = create_cached_data_key(
|
||||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||||
salt='cic.balances_data'
|
salt=':cic.balances_data'
|
||||||
)
|
)
|
||||||
cached_balance = get_cached_data(key=key)
|
cached_balance = get_cached_data(key=key)
|
||||||
if cached_balance:
|
if cached_balance:
|
||||||
|
@ -118,7 +118,7 @@ class MetadataRequestsHandler(Metadata):
|
|||||||
metadata_http_error_handler(result=result)
|
metadata_http_error_handler(result=result)
|
||||||
response_data = result.content
|
response_data = result.content
|
||||||
data = json.loads(response_data.decode('utf-8'))
|
data = json.loads(response_data.decode('utf-8'))
|
||||||
if result.status_code == 200 and self.cic_type == 'cic.person':
|
if result.status_code == 200 and self.cic_type == ':cic.person':
|
||||||
person = Person()
|
person = Person()
|
||||||
deserialized_person = person.deserialize(person_data=json.loads(data))
|
deserialized_person = person.deserialize(person_data=json.loads(data))
|
||||||
data = json.dumps(deserialized_person.serialize())
|
data = json.dumps(deserialized_person.serialize())
|
||||||
|
@ -9,4 +9,4 @@ from .base import MetadataRequestsHandler
|
|||||||
class PersonMetadata(MetadataRequestsHandler):
|
class PersonMetadata(MetadataRequestsHandler):
|
||||||
|
|
||||||
def __init__(self, identifier: bytes):
|
def __init__(self, identifier: bytes):
|
||||||
super().__init__(cic_type='cic.person', identifier=identifier)
|
super().__init__(cic_type=':cic.person', identifier=identifier)
|
||||||
|
@ -10,4 +10,4 @@ from .base import MetadataRequestsHandler
|
|||||||
class PhonePointerMetadata(MetadataRequestsHandler):
|
class PhonePointerMetadata(MetadataRequestsHandler):
|
||||||
|
|
||||||
def __init__(self, identifier: bytes):
|
def __init__(self, identifier: bytes):
|
||||||
super().__init__(cic_type='cic.msisdn', identifier=identifier)
|
super().__init__(cic_type=':cic.phone', identifier=identifier)
|
||||||
|
@ -219,7 +219,6 @@ def format_transactions(transactions: list, preferred_language: str, token_symbo
|
|||||||
formatted_transactions = ''
|
formatted_transactions = ''
|
||||||
if len(transactions) > 0:
|
if len(transactions) > 0:
|
||||||
for transaction in transactions:
|
for transaction in transactions:
|
||||||
|
|
||||||
recipient_phone_number = transaction.get('recipient_phone_number')
|
recipient_phone_number = transaction.get('recipient_phone_number')
|
||||||
sender_phone_number = transaction.get('sender_phone_number')
|
sender_phone_number = transaction.get('sender_phone_number')
|
||||||
value = transaction.get('to_value')
|
value = transaction.get('to_value')
|
||||||
@ -250,7 +249,7 @@ def process_display_user_metadata(user: Account, display_key: str):
|
|||||||
"""
|
"""
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
user_metadata = get_cached_data(key)
|
user_metadata = get_cached_data(key)
|
||||||
if user_metadata:
|
if user_metadata:
|
||||||
@ -287,7 +286,7 @@ def process_account_statement(user: Account, display_key: str, ussd_session: dic
|
|||||||
"""
|
"""
|
||||||
# retrieve cached statement
|
# retrieve cached statement
|
||||||
identifier = blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address)
|
identifier = blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address)
|
||||||
key = create_cached_data_key(identifier=identifier, salt='cic.statement')
|
key = create_cached_data_key(identifier=identifier, salt=':cic.statement')
|
||||||
transactions = get_cached_data(key=key)
|
transactions = get_cached_data(key=key)
|
||||||
|
|
||||||
token_symbol = retrieve_token_symbol()
|
token_symbol = retrieve_token_symbol()
|
||||||
@ -365,7 +364,7 @@ def process_start_menu(display_key: str, user: Account):
|
|||||||
|
|
||||||
key = create_cached_data_key(
|
key = create_cached_data_key(
|
||||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||||
salt='cic.balances_data'
|
salt=':cic.balances_data'
|
||||||
)
|
)
|
||||||
cache_data(key=key, data=json.dumps(balances_data))
|
cache_data(key=key, data=json.dumps(balances_data))
|
||||||
|
|
||||||
@ -417,7 +416,7 @@ def process_request(user_input: str, user: Account, ussd_session: Optional[dict]
|
|||||||
# retrieve metadata before any transition
|
# retrieve metadata before any transition
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
person_metadata = get_cached_data(key=key)
|
person_metadata = get_cached_data(key=key)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def has_sufficient_balance(state_machine_data: Tuple[str, dict, Account]) -> boo
|
|||||||
# get cached balance
|
# get cached balance
|
||||||
key = create_cached_data_key(
|
key = create_cached_data_key(
|
||||||
identifier=bytes.fromhex(user.blockchain_address[2:]),
|
identifier=bytes.fromhex(user.blockchain_address[2:]),
|
||||||
salt='cic.balances_data'
|
salt=':cic.balances_data'
|
||||||
)
|
)
|
||||||
cached_balance = get_cached_data(key=key)
|
cached_balance = get_cached_data(key=key)
|
||||||
operational_balance = compute_operational_balance(balances=json.loads(cached_balance))
|
operational_balance = compute_operational_balance(balances=json.loads(cached_balance))
|
||||||
|
@ -176,7 +176,7 @@ def edit_user_metadata_attribute(state_machine_data: Tuple[str, dict, Account]):
|
|||||||
blockchain_address = user.blockchain_address
|
blockchain_address = user.blockchain_address
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
user_metadata = get_cached_data(key=key)
|
user_metadata = get_cached_data(key=key)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ def has_cached_user_metadata(state_machine_data: Tuple[str, dict, Account]):
|
|||||||
# check for user metadata in cache
|
# check for user metadata in cache
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
user_metadata = get_cached_data(key=key)
|
user_metadata = get_cached_data(key=key)
|
||||||
return user_metadata is not None
|
return user_metadata is not None
|
||||||
|
@ -136,7 +136,7 @@ def process_balances_callback(result: list, param: str, status_code: int):
|
|||||||
blockchain_address = balances_data.get('address')
|
blockchain_address = balances_data.get('address')
|
||||||
key = create_cached_data_key(
|
key = create_cached_data_key(
|
||||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||||
salt='cic.balances_data'
|
salt=':cic.balances_data'
|
||||||
)
|
)
|
||||||
cache_data(key=key, data=json.dumps(balances_data))
|
cache_data(key=key, data=json.dumps(balances_data))
|
||||||
else:
|
else:
|
||||||
@ -226,7 +226,7 @@ def process_statement_callback(result, param: str, status_code: int):
|
|||||||
|
|
||||||
# cache account statement
|
# cache account statement
|
||||||
identifier = bytes.fromhex(param[2:])
|
identifier = bytes.fromhex(param[2:])
|
||||||
key = create_cached_data_key(identifier=identifier, salt='cic.statement')
|
key = create_cached_data_key(identifier=identifier, salt=':cic.statement')
|
||||||
data = json.dumps(processed_transactions)
|
data = json.dumps(processed_transactions)
|
||||||
|
|
||||||
# cache statement data
|
# cache statement data
|
||||||
|
@ -105,7 +105,7 @@ def test_get_user_metadata(caplog,
|
|||||||
assert 'Get latest data status: 200' in caplog.text
|
assert 'Get latest data status: 200' in caplog.text
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=identifier,
|
identifier=identifier,
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
cached_user_metadata = get_cached_data(key=key)
|
cached_user_metadata = get_cached_data(key=key)
|
||||||
assert cached_user_metadata
|
assert cached_user_metadata
|
||||||
|
@ -36,7 +36,7 @@ def test_has_cached_user_metadata(create_in_db_ussd_session,
|
|||||||
user = create_activated_user
|
user = create_activated_user
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
cache_data(key=key, data=json.dumps(person_metadata))
|
cache_data(key=key, data=json.dumps(person_metadata))
|
||||||
result = has_cached_user_metadata(state_machine_data=state_machine_data)
|
result = has_cached_user_metadata(state_machine_data=state_machine_data)
|
||||||
|
2
apps/cic-ussd/tests/fixtures/user.py
vendored
2
apps/cic-ussd/tests/fixtures/user.py
vendored
@ -115,6 +115,6 @@ def cached_user_metadata(create_activated_user, init_redis_cache, person_metadat
|
|||||||
user_metadata = json.dumps(person_metadata)
|
user_metadata = json.dumps(person_metadata)
|
||||||
key = generate_metadata_pointer(
|
key = generate_metadata_pointer(
|
||||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=create_activated_user.blockchain_address),
|
identifier=blockchain_address_to_metadata_pointer(blockchain_address=create_activated_user.blockchain_address),
|
||||||
cic_type='cic.person'
|
cic_type=':cic.person'
|
||||||
)
|
)
|
||||||
cache_data(key=key, data=user_metadata)
|
cache_data(key=key, data=user_metadata)
|
||||||
|
Loading…
Reference in New Issue
Block a user