123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- """Test configuration"""
- import os
- import pytest
- import _pytest.skipping
- from dotenv import load_dotenv
- from python_anticaptcha import AnticaptchaClient
- from rival_regions_wrapper.middleware import LocalAuthentication
- load_dotenv()
- class MissingAuthenticationError(Exception):
- """Error for missing authentication"""
- def pytest_addoption(parser):
- """Add option to parser to prevent skips"""
- parser.addoption(
- "--no-skips",
- action="store_true",
- default=False, help="disable skip marks")
- @pytest.hookimpl(tryfirst=True)
- def pytest_cmdline_preparse(config, args):
- """Add check for skips"""
- if "--no-skips" not in args:
- return
- def no_skip(*args, **kwargs):
- return
- _pytest.skipping.skip = no_skip
- @pytest.fixture(scope='module')
- def vcr(vcr):
- """Set parameters vor VCR"""
- vcr.ignore_localhost = True
- return vcr
- @pytest.fixture(scope="module")
- def conference_id():
- """Get conference id from environ variable"""
- value = os.environ.get('CONFERENCE_ID', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: CONFERENCE_ID'
- )
- return value
- @pytest.fixture(scope="module")
- def message():
- """Get message from environ variable"""
- value = os.environ.get('MESSAGE', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: MESSAGE'
- )
- return value
- @pytest.fixture(scope="module")
- def conference_title():
- """Get conference title from environ variable"""
- value = os.environ.get('CONFERENCE_TITLE', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: CONFERENCE_TITLE'
- )
- return value
- @pytest.fixture(scope="module")
- def language_chat():
- """Get language chat from environ varriable"""
- value = os.environ.get('LANGUAGE_CHAT', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: LANGUAGE_CHAT'
- )
- return value
- @pytest.fixture(scope="module")
- def perk():
- """Get perk from environ varriable"""
- value = os.environ.get('PERK', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: PERK'
- )
- return value
- @pytest.fixture(scope="module")
- def perk_upgrade_type():
- """Get perk upgrade type from environ varriable"""
- value = os.environ.get('PERK_UPGRADE_TYPE', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: PERK_UPGRADE_TYPE'
- )
- return value
- @pytest.fixture(scope="module")
- def craft_item():
- """Get craft item from environ varriable"""
- value = os.environ.get('CRAFT_ITEM', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: CRAFT_ITEM'
- )
- return value
- @pytest.fixture(scope="module")
- def craft_amount():
- """Get craft amount from environ varriable"""
- value = os.environ.get('CRAFT_AMOUNT', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: CRAFT_AMOUNT'
- )
- return value
- @pytest.fixture(scope="module")
- def profile_id():
- """Get profile id from environ varriable"""
- value = os.environ.get('PROFILE_ID', None)
- if not value:
- raise Exception(
- 'Load the following variable in your user environment: PROFILE_ID'
- )
- return value
- @pytest.fixture(scope="module")
- def middleware():
- """Set up wrapper before test"""
- username = os.environ.get('USERNAME', None)
- password = os.environ.get('PASSWORD', None)
- login_method = os.environ.get('LOGIN_METHOD', None)
- debug = os.environ.get('DEBUG', None)
- captcha_key = os.environ.get('CAPTCHA_KEY', None)
- if None in (username, password, login_method):
- raise MissingAuthenticationError(
- 'Load the following variables in your user environment: '
- 'USERNAME, PASSWORD, LOGIN_METHOD'
- )
- _middleware = LocalAuthentication(
- False, AnticaptchaClient(captcha_key), debug
- )
- return _middleware.set_credentials(
- username, password, login_method
- )
|