Rehabilitate test coverage in ussd and cic-notify
This commit is contained in:
162
apps/cic-ussd/tests/fixtures/account.py
vendored
162
apps/cic-ussd/tests/fixtures/account.py
vendored
@@ -8,6 +8,7 @@ from cic_types.condiments import MetadataPointer
|
||||
|
||||
# local imports
|
||||
from cic_ussd.account.chain import Chain
|
||||
from cic_ussd.account.tokens import set_active_token
|
||||
from cic_ussd.cache import cache_data, cache_data_key
|
||||
from cic_ussd.db.enum import AccountStatus
|
||||
from cic_ussd.db.models.account import Account
|
||||
@@ -36,6 +37,16 @@ def activated_account(init_database, set_fernet_key):
|
||||
return account
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def guardian_account(init_database, set_fernet_key):
|
||||
account = Account(blockchain_address(), phone_number())
|
||||
account.create_password('0000')
|
||||
account.activate_account()
|
||||
init_database.add(account)
|
||||
init_database.commit()
|
||||
return account
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def balances():
|
||||
return [{
|
||||
@@ -53,13 +64,22 @@ def cache_account_creation_data(init_cache, account_creation_data):
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_balances(activated_account, balances, init_cache):
|
||||
identifier = bytes.fromhex(activated_account.blockchain_address)
|
||||
def cache_balances(activated_account, balances, init_cache, token_symbol):
|
||||
identifier = [bytes.fromhex(activated_account.blockchain_address), token_symbol.encode('utf-8')]
|
||||
balances = json.dumps(balances[0])
|
||||
key = cache_data_key(identifier, MetadataPointer.BALANCES)
|
||||
cache_data(key, balances)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_adjusted_balances(activated_account, balances, init_cache, token_symbol):
|
||||
identifier = bytes.fromhex(activated_account.blockchain_address)
|
||||
balances_identifier = [identifier, token_symbol.encode('utf-8')]
|
||||
key = cache_data_key(balances_identifier, MetadataPointer.BALANCES_ADJUSTED)
|
||||
adjusted_balance = 45931650.64654012
|
||||
cache_data(key, adjusted_balance)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_default_token_data(default_token_data, init_cache, load_chain_spec):
|
||||
chain_str = Chain.spec.__str__()
|
||||
@@ -68,6 +88,113 @@ def cache_default_token_data(default_token_data, init_cache, load_chain_spec):
|
||||
cache_data(key, data)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def set_active_token(activated_account, init_cache, token_symbol):
|
||||
identifier = bytes.fromhex(activated_account.blockchain_address)
|
||||
key = cache_data_key(identifier, MetadataPointer.TOKEN_ACTIVE)
|
||||
cache_data(key=key, data=token_symbol)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_token_data(activated_account, init_cache, token_data):
|
||||
identifier = [bytes.fromhex(activated_account.blockchain_address), token_data.get('symbol').encode('utf-8')]
|
||||
key = cache_data_key(identifier, MetadataPointer.TOKEN_DATA)
|
||||
cache_data(key=key, data=json.dumps(token_data))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_token_symbol_list(activated_account, init_cache, token_symbol):
|
||||
identifier = bytes.fromhex(activated_account.blockchain_address)
|
||||
key = cache_data_key(identifier=identifier, salt=MetadataPointer.TOKEN_SYMBOLS_LIST)
|
||||
token_symbols_list = [token_symbol]
|
||||
cache_data(key, json.dumps(token_symbols_list))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_token_data_list(activated_account, init_cache, token_data):
|
||||
identifier = bytes.fromhex(activated_account.blockchain_address)
|
||||
key = cache_data_key(identifier, MetadataPointer.TOKEN_DATA_LIST)
|
||||
token_data_list = [token_data]
|
||||
cache_data(key, json.dumps(token_data_list))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def token_meta_symbol():
|
||||
return {
|
||||
"contact": {
|
||||
"phone": "+254700000000",
|
||||
"email": "info@grassrootseconomics.org"
|
||||
},
|
||||
"country_code": "KE",
|
||||
"location": "Kilifi",
|
||||
"name": "GRASSROOTS ECONOMICS"
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def token_proof_symbol():
|
||||
return {
|
||||
"description": "Community support",
|
||||
"issuer": "Grassroots Economics",
|
||||
"namespace": "ge",
|
||||
"proofs": [
|
||||
"0x4746540000000000000000000000000000000000000000000000000000000000",
|
||||
"1f0f0e3e9db80eeaba22a9d4598e454be885855d6048545546fd488bb709dc2f"
|
||||
],
|
||||
"version": 0
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def token_list_entries():
|
||||
return [
|
||||
{
|
||||
'name': 'Fee',
|
||||
'symbol': 'FII',
|
||||
'issuer': 'Foo',
|
||||
'contact': {'phone': '+254712345678'},
|
||||
'location': 'Fum',
|
||||
'balance': 50.0
|
||||
},
|
||||
{
|
||||
'name': 'Giftable Token',
|
||||
'symbol': 'GFT',
|
||||
'issuer': 'Grassroots Economics',
|
||||
'contact': {
|
||||
'phone': '+254700000000',
|
||||
'email': 'info@grassrootseconomics.org'
|
||||
},
|
||||
'location': 'Fum',
|
||||
'balance': 60.0
|
||||
},
|
||||
{
|
||||
'name': 'Demurrage Token',
|
||||
'symbol': 'DET',
|
||||
'issuer': 'Grassroots Economics',
|
||||
'contact': {
|
||||
'phone': '+254700000000',
|
||||
'email': 'info@grassrootseconomics.org'
|
||||
},
|
||||
'location': 'Fum',
|
||||
'balance': 49.99
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_token_meta_symbol(token_meta_symbol, token_symbol):
|
||||
identifier = token_symbol.encode('utf-8')
|
||||
key = cache_data_key(identifier, MetadataPointer.TOKEN_META_SYMBOL)
|
||||
cache_data(key, json.dumps(token_meta_symbol))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_token_proof_symbol(token_proof_symbol, token_symbol):
|
||||
identifier = token_symbol.encode('utf-8')
|
||||
key = cache_data_key(identifier, MetadataPointer.TOKEN_PROOF_SYMBOL)
|
||||
cache_data(key, json.dumps(token_proof_symbol))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def cache_person_metadata(activated_account, init_cache, person_metadata):
|
||||
identifier = bytes.fromhex(activated_account.blockchain_address)
|
||||
@@ -100,10 +227,33 @@ def custom_metadata():
|
||||
@pytest.fixture(scope='function')
|
||||
def default_token_data(token_symbol):
|
||||
return {
|
||||
'symbol': token_symbol,
|
||||
'address': blockchain_address(),
|
||||
'name': 'Giftable',
|
||||
'decimals': 6
|
||||
'symbol': token_symbol,
|
||||
'address': '32e860c2a0645d1b7b005273696905f5d6dc5d05',
|
||||
'name': 'Giftable Token',
|
||||
'decimals': 6,
|
||||
"converters": []
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def token_data():
|
||||
return {
|
||||
"description": "Community support",
|
||||
"issuer": "Grassroots Economics",
|
||||
"location": "Kilifi",
|
||||
"contact": {
|
||||
"phone": "+254700000000",
|
||||
"email": "info@grassrootseconomics.org"
|
||||
},
|
||||
"decimals": 6,
|
||||
"name": "Giftable Token",
|
||||
"symbol": "GFT",
|
||||
"address": "32e860c2a0645d1b7b005273696905f5d6dc5d05",
|
||||
"proofs": [
|
||||
"0x4746540000000000000000000000000000000000000000000000000000000000",
|
||||
"1f0f0e3e9db80eeaba22a9d4598e454be885855d6048545546fd488bb709dc2f"
|
||||
],
|
||||
"converters": []
|
||||
}
|
||||
|
||||
|
||||
|
||||
12
apps/cic-ussd/tests/fixtures/cache.py
vendored
12
apps/cic-ussd/tests/fixtures/cache.py
vendored
@@ -2,14 +2,18 @@
|
||||
|
||||
# external imports
|
||||
import pytest
|
||||
from pytest_redis import factories
|
||||
|
||||
# local imports
|
||||
from cic_ussd.cache import Cache
|
||||
from cic_ussd.session.ussd_session import UssdSession
|
||||
|
||||
redis_test_proc = factories.redis_proc()
|
||||
redis_db = factories.redisdb('redis_test_proc', decode=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def init_cache(redisdb):
|
||||
Cache.store = redisdb
|
||||
UssdSession.store = redisdb
|
||||
return redisdb
|
||||
def init_cache(redis_db):
|
||||
Cache.store = redis_db
|
||||
UssdSession.store = redis_db
|
||||
return redis_db
|
||||
|
||||
33
apps/cic-ussd/tests/fixtures/config.py
vendored
33
apps/cic-ussd/tests/fixtures/config.py
vendored
@@ -10,11 +10,13 @@ from confini import Config
|
||||
|
||||
# local imports
|
||||
from cic_ussd.account.chain import Chain
|
||||
from cic_ussd.account.guardianship import Guardianship
|
||||
from cic_ussd.encoder import PasswordEncoder
|
||||
from cic_ussd.files.local_files import create_local_file_data_stores, json_file_parser
|
||||
from cic_ussd.menu.ussd_menu import UssdMenu
|
||||
from cic_ussd.phone_number import E164Format, Support
|
||||
from cic_ussd.state_machine import UssdStateMachine
|
||||
from cic_ussd.translation import generate_locale_files, Languages
|
||||
from cic_ussd.validator import validate_presence
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
@@ -39,6 +41,14 @@ def init_state_machine(load_config):
|
||||
UssdStateMachine.transitions = json_file_parser(filepath=load_config.get('MACHINE_TRANSITIONS'))
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def load_languages(init_cache, load_config):
|
||||
validate_presence(load_config.get('LANGUAGES_FILE'))
|
||||
Languages.load_languages_dict(load_config.get('LANGUAGES_FILE'))
|
||||
languages = Languages()
|
||||
languages.cache_system_languages()
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def load_chain_spec(load_config):
|
||||
chain_spec = ChainSpec.from_chain_str(load_config.get('CHAIN_SPEC'))
|
||||
@@ -75,8 +85,23 @@ def set_fernet_key(load_config):
|
||||
PasswordEncoder.set_key(load_config.get('APP_PASSWORD_PEPPER'))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def set_locale_files(load_config):
|
||||
validate_presence(load_config.get('LOCALE_PATH'))
|
||||
i18n.load_path.append(load_config.get('LOCALE_PATH'))
|
||||
@pytest.fixture(scope='function')
|
||||
def setup_guardianship(load_config):
|
||||
guardians_file = os.path.join(root_directory, load_config.get('SYSTEM_GUARDIANS_FILE'))
|
||||
validate_presence(guardians_file)
|
||||
Guardianship.load_system_guardians(guardians_file)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def set_locale_files(load_config, tmpdir_factory):
|
||||
tmpdir = tmpdir_factory.mktemp("var")
|
||||
tmpdir_path = str(tmpdir)
|
||||
validate_presence(tmpdir_path)
|
||||
import cic_translations
|
||||
package_path = cic_translations.__path__
|
||||
schema_files = os.path.join(package_path[0], load_config.get("SCHEMA_FILE_PATH"))
|
||||
generate_locale_files(locale_dir=tmpdir_path,
|
||||
schema_file_path=schema_files,
|
||||
translation_builder_path=load_config.get('LOCALE_FILE_BUILDERS'))
|
||||
i18n.load_path.append(tmpdir_path)
|
||||
i18n.set('fallback', load_config.get('LOCALE_FALLBACK'))
|
||||
|
||||
3
apps/cic-ussd/tests/fixtures/transaction.py
vendored
3
apps/cic-ussd/tests/fixtures/transaction.py
vendored
@@ -40,6 +40,7 @@ def statement(activated_account):
|
||||
'blockchain_address': activated_account.blockchain_address,
|
||||
'token_symbol': 'GFT',
|
||||
'token_value': 25000000,
|
||||
'token_decimals': 6,
|
||||
'role': 'sender',
|
||||
'action_tag': 'Sent',
|
||||
'direction_tag': 'To',
|
||||
@@ -63,7 +64,7 @@ def transaction_result(activated_account, load_config, valid_recipient):
|
||||
'destination_token_symbol': load_config.get('TEST_TOKEN_SYMBOL'),
|
||||
'source_token_decimals': 6,
|
||||
'destination_token_decimals': 6,
|
||||
'chain': 'evm:bloxberg:8996'
|
||||
'chain': load_config.get('CHAIN_SPEC')
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user