From 1df62717ef98b6f615f7ecc5013e82c71fd91fed Mon Sep 17 00:00:00 2001 From: Philip Wafula Date: Sat, 1 May 2021 14:52:54 +0000 Subject: [PATCH] Update metadata pointer salt values --- apps/cic-ussd/cic_ussd/account.py | 2 +- apps/cic-ussd/cic_ussd/balance.py | 2 +- apps/cic-ussd/cic_ussd/metadata/base.py | 2 +- apps/cic-ussd/cic_ussd/metadata/person.py | 2 +- apps/cic-ussd/cic_ussd/metadata/phone.py | 2 +- apps/cic-ussd/cic_ussd/processor.py | 9 ++++----- .../cic-ussd/cic_ussd/state_machine/logic/transaction.py | 2 +- apps/cic-ussd/cic_ussd/state_machine/logic/user.py | 2 +- apps/cic-ussd/cic_ussd/state_machine/logic/validator.py | 2 +- apps/cic-ussd/cic_ussd/tasks/callback_handler.py | 4 ++-- .../tests/cic_ussd/metadata/test_user_metadata.py | 2 +- .../cic_ussd/state_machine/logic/test_validator_logic.py | 2 +- apps/cic-ussd/tests/fixtures/user.py | 2 +- 13 files changed, 17 insertions(+), 18 deletions(-) diff --git a/apps/cic-ussd/cic_ussd/account.py b/apps/cic-ussd/cic_ussd/account.py index 91fac0c..647ca86 100644 --- a/apps/cic-ussd/cic_ussd/account.py +++ b/apps/cic-ussd/cic_ussd/account.py @@ -20,7 +20,7 @@ def define_account_tx_metadata(user: Account): ) key = generate_metadata_pointer( identifier=identifier, - cic_type='cic.person' + cic_type=':cic.person' ) account_metadata = get_cached_data(key=key) diff --git a/apps/cic-ussd/cic_ussd/balance.py b/apps/cic-ussd/cic_ussd/balance.py index 6d68247..99297a8 100644 --- a/apps/cic-ussd/cic_ussd/balance.py +++ b/apps/cic-ussd/cic_ussd/balance.py @@ -80,7 +80,7 @@ def get_cached_operational_balance(blockchain_address: str): """ key = create_cached_data_key( identifier=bytes.fromhex(blockchain_address[2:]), - salt='cic.balances_data' + salt=':cic.balances_data' ) cached_balance = get_cached_data(key=key) if cached_balance: diff --git a/apps/cic-ussd/cic_ussd/metadata/base.py b/apps/cic-ussd/cic_ussd/metadata/base.py index 6f2d1ff..e646d8a 100644 --- a/apps/cic-ussd/cic_ussd/metadata/base.py +++ b/apps/cic-ussd/cic_ussd/metadata/base.py @@ -118,7 +118,7 @@ class MetadataRequestsHandler(Metadata): metadata_http_error_handler(result=result) response_data = result.content 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() deserialized_person = person.deserialize(person_data=json.loads(data)) data = json.dumps(deserialized_person.serialize()) diff --git a/apps/cic-ussd/cic_ussd/metadata/person.py b/apps/cic-ussd/cic_ussd/metadata/person.py index 57dec98..63501f4 100644 --- a/apps/cic-ussd/cic_ussd/metadata/person.py +++ b/apps/cic-ussd/cic_ussd/metadata/person.py @@ -9,4 +9,4 @@ from .base import MetadataRequestsHandler class PersonMetadata(MetadataRequestsHandler): def __init__(self, identifier: bytes): - super().__init__(cic_type='cic.person', identifier=identifier) + super().__init__(cic_type=':cic.person', identifier=identifier) diff --git a/apps/cic-ussd/cic_ussd/metadata/phone.py b/apps/cic-ussd/cic_ussd/metadata/phone.py index 46d508c..d1de6c5 100644 --- a/apps/cic-ussd/cic_ussd/metadata/phone.py +++ b/apps/cic-ussd/cic_ussd/metadata/phone.py @@ -10,4 +10,4 @@ from .base import MetadataRequestsHandler class PhonePointerMetadata(MetadataRequestsHandler): def __init__(self, identifier: bytes): - super().__init__(cic_type='cic.msisdn', identifier=identifier) + super().__init__(cic_type=':cic.phone', identifier=identifier) diff --git a/apps/cic-ussd/cic_ussd/processor.py b/apps/cic-ussd/cic_ussd/processor.py index a2bf363..195343a 100644 --- a/apps/cic-ussd/cic_ussd/processor.py +++ b/apps/cic-ussd/cic_ussd/processor.py @@ -219,7 +219,6 @@ def format_transactions(transactions: list, preferred_language: str, token_symbo formatted_transactions = '' if len(transactions) > 0: for transaction in transactions: - recipient_phone_number = transaction.get('recipient_phone_number') sender_phone_number = transaction.get('sender_phone_number') value = transaction.get('to_value') @@ -250,7 +249,7 @@ def process_display_user_metadata(user: Account, display_key: str): """ key = generate_metadata_pointer( 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) if user_metadata: @@ -287,7 +286,7 @@ def process_account_statement(user: Account, display_key: str, ussd_session: dic """ # retrieve cached statement 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) token_symbol = retrieve_token_symbol() @@ -365,7 +364,7 @@ def process_start_menu(display_key: str, user: Account): key = create_cached_data_key( identifier=bytes.fromhex(blockchain_address[2:]), - salt='cic.balances_data' + salt=':cic.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 key = generate_metadata_pointer( 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) diff --git a/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py b/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py index ff56327..eee2c7d 100644 --- a/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py +++ b/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py @@ -64,7 +64,7 @@ def has_sufficient_balance(state_machine_data: Tuple[str, dict, Account]) -> boo # get cached balance key = create_cached_data_key( identifier=bytes.fromhex(user.blockchain_address[2:]), - salt='cic.balances_data' + salt=':cic.balances_data' ) cached_balance = get_cached_data(key=key) operational_balance = compute_operational_balance(balances=json.loads(cached_balance)) diff --git a/apps/cic-ussd/cic_ussd/state_machine/logic/user.py b/apps/cic-ussd/cic_ussd/state_machine/logic/user.py index e8b8e44..da8a87d 100644 --- a/apps/cic-ussd/cic_ussd/state_machine/logic/user.py +++ b/apps/cic-ussd/cic_ussd/state_machine/logic/user.py @@ -176,7 +176,7 @@ def edit_user_metadata_attribute(state_machine_data: Tuple[str, dict, Account]): blockchain_address = user.blockchain_address key = generate_metadata_pointer( 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) diff --git a/apps/cic-ussd/cic_ussd/state_machine/logic/validator.py b/apps/cic-ussd/cic_ussd/state_machine/logic/validator.py index 36cce59..2f6203d 100644 --- a/apps/cic-ussd/cic_ussd/state_machine/logic/validator.py +++ b/apps/cic-ussd/cic_ussd/state_machine/logic/validator.py @@ -23,7 +23,7 @@ def has_cached_user_metadata(state_machine_data: Tuple[str, dict, Account]): # check for user metadata in cache key = generate_metadata_pointer( 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) return user_metadata is not None diff --git a/apps/cic-ussd/cic_ussd/tasks/callback_handler.py b/apps/cic-ussd/cic_ussd/tasks/callback_handler.py index 1766565..ab860b9 100644 --- a/apps/cic-ussd/cic_ussd/tasks/callback_handler.py +++ b/apps/cic-ussd/cic_ussd/tasks/callback_handler.py @@ -136,7 +136,7 @@ def process_balances_callback(result: list, param: str, status_code: int): blockchain_address = balances_data.get('address') key = create_cached_data_key( identifier=bytes.fromhex(blockchain_address[2:]), - salt='cic.balances_data' + salt=':cic.balances_data' ) cache_data(key=key, data=json.dumps(balances_data)) else: @@ -226,7 +226,7 @@ def process_statement_callback(result, param: str, status_code: int): # cache account statement 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) # cache statement data diff --git a/apps/cic-ussd/tests/cic_ussd/metadata/test_user_metadata.py b/apps/cic-ussd/tests/cic_ussd/metadata/test_user_metadata.py index 6c932ce..1338f78 100644 --- a/apps/cic-ussd/tests/cic_ussd/metadata/test_user_metadata.py +++ b/apps/cic-ussd/tests/cic_ussd/metadata/test_user_metadata.py @@ -105,7 +105,7 @@ def test_get_user_metadata(caplog, assert 'Get latest data status: 200' in caplog.text key = generate_metadata_pointer( identifier=identifier, - cic_type='cic.person' + cic_type=':cic.person' ) cached_user_metadata = get_cached_data(key=key) assert cached_user_metadata diff --git a/apps/cic-ussd/tests/cic_ussd/state_machine/logic/test_validator_logic.py b/apps/cic-ussd/tests/cic_ussd/state_machine/logic/test_validator_logic.py index 639598f..8e91d37 100644 --- a/apps/cic-ussd/tests/cic_ussd/state_machine/logic/test_validator_logic.py +++ b/apps/cic-ussd/tests/cic_ussd/state_machine/logic/test_validator_logic.py @@ -36,7 +36,7 @@ def test_has_cached_user_metadata(create_in_db_ussd_session, user = create_activated_user key = generate_metadata_pointer( 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)) result = has_cached_user_metadata(state_machine_data=state_machine_data) diff --git a/apps/cic-ussd/tests/fixtures/user.py b/apps/cic-ussd/tests/fixtures/user.py index 20dfbc2..0add085 100644 --- a/apps/cic-ussd/tests/fixtures/user.py +++ b/apps/cic-ussd/tests/fixtures/user.py @@ -115,6 +115,6 @@ def cached_user_metadata(create_activated_user, init_redis_cache, person_metadat user_metadata = json.dumps(person_metadata) key = generate_metadata_pointer( 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)