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

70 lines
2.1 KiB
Python
Raw Normal View History

2021-02-06 16:13:47 +01:00
# standard imports
2021-08-06 18:29:01 +02:00
import os
import random
2021-02-06 16:13:47 +01:00
2021-08-06 18:29:01 +02:00
# external imports
2021-02-06 16:13:47 +01:00
import pytest
# local imports
from cic_ussd.db.models.ussd_session import UssdSession
2021-08-06 18:29:01 +02:00
from cic_ussd.session.ussd_session import create_ussd_session
# test imports
from tests.helpers.accounts import phone_number
2021-02-06 16:13:47 +01:00
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def activated_account_ussd_session(load_config, activated_account):
valid_service_codes = load_config.get('USSD_SERVICE_CODE').split(",")
2021-02-06 16:13:47 +01:00
return {
2021-08-06 18:29:01 +02:00
'data': {},
'external_session_id': os.urandom(20).hex(),
'msisdn': activated_account.phone_number,
'service_code': valid_service_codes[0],
'state': 'initial_language_selection',
2021-02-06 16:13:47 +01:00
'user_input': '1',
2021-08-06 18:29:01 +02:00
}
@pytest.fixture(scope='function')
def generic_ussd_session(load_config, activated_account):
valid_service_codes = load_config.get('USSD_SERVICE_CODE').split(",")
return {
'data': {},
'service_code': valid_service_codes[0],
2021-02-06 16:13:47 +01:00
'state': 'initial_language_selection',
2021-08-06 18:29:01 +02:00
'user_input': '1',
2021-02-06 16:13:47 +01:00
'version': 2
}
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def ussd_session_traffic(generic_ussd_session, init_database, persisted_ussd_session):
for _ in range((random.randint(5, 15))):
generic_ussd_session['external_session_id'] = os.urandom(20).hex()
generic_ussd_session['msisdn'] = phone_number()
ussd = UssdSession(**{key: value for key, value in generic_ussd_session.items()})
init_database.add(ussd)
init_database.commit()
@pytest.fixture(scope='function')
def ussd_session_data(load_config):
return {
'recipient': phone_number()
}
2021-02-06 16:13:47 +01:00
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def cached_ussd_session(init_cache, activated_account_ussd_session):
return create_ussd_session(**{key: value for key, value in activated_account_ussd_session.items()})
2021-02-06 16:13:47 +01:00
@pytest.fixture(scope='function')
2021-08-06 18:29:01 +02:00
def persisted_ussd_session(init_cache, init_database, activated_account_ussd_session):
activated_account_ussd_session['version'] = 2
ussd = UssdSession(**{key: value for key, value in activated_account_ussd_session.items()})
init_database.add(ussd)
2021-02-06 16:13:47 +01:00
init_database.commit()
2021-08-06 18:29:01 +02:00
return ussd