cic-internal-integration/apps/cic-ussd/tests/cic_ussd/metadata/test_base.py

44 lines
1.9 KiB
Python
Raw Permalink Normal View History

2021-08-06 18:29:01 +02:00
# standard imports
import json
import os
# external imports
import requests_mock
from chainlib.hash import strip_0x
2021-10-15 13:21:41 +02:00
from cic_types.condiments import MetadataPointer
2021-08-06 18:29:01 +02:00
from cic_types.processor import generate_metadata_pointer
# local imports
2021-10-15 13:21:41 +02:00
from cic_ussd.metadata.base import UssdMetadataHandler
2021-08-06 18:29:01 +02:00
# external imports
2021-10-15 13:21:41 +02:00
def test_ussd_metadata_handler(activated_account,
init_cache,
load_config,
person_metadata,
setup_metadata_request_handler,
setup_metadata_signer):
2021-08-06 18:29:01 +02:00
identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address))
2021-10-15 13:21:41 +02:00
cic_type = MetadataPointer.PERSON
metadata_client = UssdMetadataHandler(cic_type, identifier)
2021-08-06 18:29:01 +02:00
assert metadata_client.cic_type == cic_type
assert metadata_client.engine == 'pgp'
assert metadata_client.identifier == identifier
assert metadata_client.metadata_pointer == generate_metadata_pointer(identifier, cic_type)
assert metadata_client.url == os.path.join(load_config.get('CIC_META_URL'), metadata_client.metadata_pointer)
with requests_mock.Mocker(real_http=False) as request_mocker:
request_mocker.register_uri('POST', metadata_client.url, status_code=200, reason='OK', json=person_metadata)
person_metadata['digest'] = os.urandom(20).hex()
request_mocker.register_uri('PUT', metadata_client.url, status_code=200, reason='OK', json=person_metadata)
result = metadata_client.create(person_metadata)
assert result.json() == person_metadata
assert result.status_code == 200
person_metadata.pop('digest')
request_mocker.register_uri('GET', metadata_client.url, status_code=200, reason='OK', json=person_metadata)
2021-10-15 13:21:41 +02:00
result = metadata_client.query().json()
2021-08-06 18:29:01 +02:00
assert result == person_metadata