cic-stack/apps/cic-ussd/tests/fixtures/config.py

87 lines
2.6 KiB
Python
Raw Normal View History

2021-02-06 16:13:47 +01:00
# standard imports
import logging
import os
# third party imports
2021-08-06 18:29:01 +02:00
import i18n
2021-02-06 16:13:47 +01:00
import pytest
from chainlib.chain import ChainSpec
2021-02-06 16:13:47 +01:00
from confini import Config
# local imports
2021-08-06 18:29:01 +02:00
from cic_ussd.account.chain import Chain
from cic_ussd.encoder import PasswordEncoder
2021-02-06 16:13:47 +01:00
from cic_ussd.files.local_files import create_local_file_data_stores, json_file_parser
from cic_ussd.menu.ussd_menu import UssdMenu
2021-08-06 18:29:01 +02:00
from cic_ussd.phone_number import E164Format, Support
2021-02-06 16:13:47 +01:00
from cic_ussd.state_machine import UssdStateMachine
2021-08-06 18:29:01 +02:00
from cic_ussd.validator import validate_presence
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
logg = logging.getLogger(__name__)
2021-02-06 16:13:47 +01:00
fixtures_dir = os.path.dirname(__file__)
root_directory = os.path.dirname(os.path.dirname(fixtures_dir))
@pytest.fixture(scope='session')
def alembic_config():
migrations_directory = os.path.join(root_directory, 'cic_ussd', 'db', 'migrations', 'default')
file = os.path.join(migrations_directory, 'alembic.ini')
return {
'file': file,
'script_location': migrations_directory
}
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def init_state_machine(load_config):
UssdStateMachine.states = json_file_parser(filepath=load_config.get('MACHINE_STATES'))
UssdStateMachine.transitions = json_file_parser(filepath=load_config.get('MACHINE_TRANSITIONS'))
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
@pytest.fixture(scope='function')
def load_chain_spec(load_config):
chain_spec = ChainSpec(
common_name=load_config.get('CIC_COMMON_NAME'),
engine=load_config.get('CIC_ENGINE'),
network_id=load_config.get('CIC_NETWORK_ID')
)
Chain.spec = chain_spec
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
@pytest.fixture(scope='session')
def load_config():
config_directory = os.path.join(root_directory, 'config/test')
config = Config(default_dir=config_directory)
config.process()
logg.debug('config loaded\n{}'.format(config))
return config
2021-02-06 16:13:47 +01:00
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def load_e164_region(load_config):
E164Format.region = load_config.get('E164_REGION')
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
@pytest.fixture(scope='session')
def load_support_phone(load_config):
Support.phone_number = load_config.get('OFFICE_SUPPORT_PHONE')
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
@pytest.fixture
def load_ussd_menu(load_config):
ussd_menu_db = create_local_file_data_stores(file_location=load_config.get('USSD_MENU_FILE'), table_name="ussd_menu")
UssdMenu.ussd_menu_db = ussd_menu_db
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def set_fernet_key(load_config):
PasswordEncoder.set_key(load_config.get('APP_PASSWORD_PEPPER'))
2021-08-06 18:29:01 +02:00
@pytest.fixture
def set_locale_files(load_config):
validate_presence(load_config.get('LOCALE_PATH'))
i18n.load_path.append(load_config.get('LOCALE_PATH'))
i18n.set('fallback', load_config.get('LOCALE_FALLBACK'))