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
|
2021-03-04 17:47:13 +01:00
|
|
|
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
|
2021-03-04 17:47:13 +01:00
|
|
|
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):
|
2021-10-20 17:02:36 +02:00
|
|
|
chain_spec = ChainSpec.from_chain_str(load_config.get('CHAIN_SPEC'))
|
2021-08-06 18:29:01 +02:00
|
|
|
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-03-04 17:47:13 +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
|
2021-03-04 17:47:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
@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-03-04 17:47:13 +01:00
|
|
|
|
|
|
|
|
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'))
|