conftest.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """Test configuration"""
  2. import os
  3. import pytest
  4. import _pytest.skipping
  5. from dotenv import load_dotenv
  6. from python_anticaptcha import AnticaptchaClient
  7. from rival_regions_wrapper.middleware import LocalAuthentication
  8. load_dotenv()
  9. class MissingAuthenticationError(Exception):
  10. """Error for missing authentication"""
  11. def pytest_addoption(parser):
  12. """Add option to parser to prevent skips"""
  13. parser.addoption(
  14. "--no-skips",
  15. action="store_true",
  16. default=False, help="disable skip marks")
  17. @pytest.hookimpl(tryfirst=True)
  18. def pytest_cmdline_preparse(config, args):
  19. """Add check for skips"""
  20. if "--no-skips" not in args:
  21. return
  22. def no_skip(*args, **kwargs):
  23. return
  24. _pytest.skipping.skip = no_skip
  25. @pytest.fixture(scope='module')
  26. def vcr(vcr):
  27. """Set parameters vor VCR"""
  28. vcr.ignore_localhost = True
  29. return vcr
  30. @pytest.fixture(scope="module")
  31. def conference_id():
  32. """Get conference id from environ variable"""
  33. return os.environ.get('CONFERENCE_ID', None)
  34. @pytest.fixture(scope="module")
  35. def message():
  36. """Get message from environ variable"""
  37. return os.environ.get('MESSAGE', None)
  38. @pytest.fixture(scope="module")
  39. def conference_title():
  40. """Get conference title from environ variable"""
  41. return os.environ.get('CONFERENCE_TITLE', None)
  42. @pytest.fixture(scope="module")
  43. def language_chat():
  44. """Get language chat from environ varriable"""
  45. return os.environ.get('LANGUAGE_CHAT', None)
  46. @pytest.fixture(scope="module")
  47. def perk():
  48. """Get perk from environ varriable"""
  49. return os.environ.get('PERK', None)
  50. @pytest.fixture(scope="module")
  51. def perk_upgrade_type():
  52. """Get perk upgrade type from environ varriable"""
  53. return os.environ.get('PERK_UPGRADE_TYPE', None)
  54. def perk_upgrade_type():
  55. """Get perk upgrade type from environ varriable"""
  56. return os.environ.get('PERK_UPGRADE_TYPE', None)
  57. @pytest.fixture(scope="module")
  58. def craft_item():
  59. """Get craft item from environ varriable"""
  60. return os.environ.get('CRAFT_ITEM', None)
  61. @pytest.fixture(scope="module")
  62. def craft_amount():
  63. """Get craft amount from environ varriable"""
  64. return os.environ.get('CRAFT_AMOUNT', None)
  65. @pytest.fixture(scope="module")
  66. def profile_id():
  67. """Get profile id from environ varriable"""
  68. return os.environ.get('PROFILE_ID', None)
  69. @pytest.fixture(scope="module")
  70. def middleware():
  71. """Set up wrapper before test"""
  72. username = os.environ.get('USERNAME', None)
  73. password = os.environ.get('PASSWORD', None)
  74. login_method = os.environ.get('LOGIN_METHOD', None)
  75. captcha_key = os.environ.get('CAPTCHA_KEY', None)
  76. if None in (username, password, login_method):
  77. raise MissingAuthenticationError(
  78. 'Load the following variables in your user environment: '
  79. 'username, password, login_method'
  80. )
  81. _middleware = LocalAuthentication(
  82. False, AnticaptchaClient(captcha_key)
  83. )
  84. return _middleware.set_credentials(
  85. username, password, login_method
  86. )