conftest.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. value = os.environ.get('CONFERENCE_ID', None)
  34. if not value:
  35. raise Exception(
  36. 'Load the following variable in your user environment: CONFERENCE_ID'
  37. )
  38. return value
  39. @pytest.fixture(scope="module")
  40. def message():
  41. """Get message from environ variable"""
  42. value = os.environ.get('MESSAGE', None)
  43. if not value:
  44. raise Exception(
  45. 'Load the following variable in your user environment: MESSAGE'
  46. )
  47. return value
  48. @pytest.fixture(scope="module")
  49. def conference_title():
  50. """Get conference title from environ variable"""
  51. value = os.environ.get('CONFERENCE_TITLE', None)
  52. if not value:
  53. raise Exception(
  54. 'Load the following variable in your user environment: CONFERENCE_TITLE'
  55. )
  56. return value
  57. @pytest.fixture(scope="module")
  58. def language_chat():
  59. """Get language chat from environ varriable"""
  60. value = os.environ.get('LANGUAGE_CHAT', None)
  61. if not value:
  62. raise Exception(
  63. 'Load the following variable in your user environment: LANGUAGE_CHAT'
  64. )
  65. return value
  66. @pytest.fixture(scope="module")
  67. def perk():
  68. """Get perk from environ varriable"""
  69. value = os.environ.get('PERK', None)
  70. if not value:
  71. raise Exception(
  72. 'Load the following variable in your user environment: PERK'
  73. )
  74. return value
  75. @pytest.fixture(scope="module")
  76. def perk_upgrade_type():
  77. """Get perk upgrade type from environ varriable"""
  78. value = os.environ.get('PERK_UPGRADE_TYPE', None)
  79. if not value:
  80. raise Exception(
  81. 'Load the following variable in your user environment: PERK_UPGRADE_TYPE'
  82. )
  83. return value
  84. @pytest.fixture(scope="module")
  85. def craft_item():
  86. """Get craft item from environ varriable"""
  87. value = os.environ.get('CRAFT_ITEM', None)
  88. if not value:
  89. raise Exception(
  90. 'Load the following variable in your user environment: CRAFT_ITEM'
  91. )
  92. return value
  93. @pytest.fixture(scope="module")
  94. def craft_amount():
  95. """Get craft amount from environ varriable"""
  96. value = os.environ.get('CRAFT_AMOUNT', None)
  97. if not value:
  98. raise Exception(
  99. 'Load the following variable in your user environment: CRAFT_AMOUNT'
  100. )
  101. return value
  102. @pytest.fixture(scope="module")
  103. def profile_id():
  104. """Get profile id from environ varriable"""
  105. value = os.environ.get('PROFILE_ID', None)
  106. if not value:
  107. raise Exception(
  108. 'Load the following variable in your user environment: PROFILE_ID'
  109. )
  110. return value
  111. @pytest.fixture(scope="module")
  112. def middleware():
  113. """Set up wrapper before test"""
  114. username = os.environ.get('USERNAME', None)
  115. password = os.environ.get('PASSWORD', None)
  116. login_method = os.environ.get('LOGIN_METHOD', None)
  117. debug = os.environ.get('DEBUG', None)
  118. captcha_key = os.environ.get('CAPTCHA_KEY', None)
  119. if None in (username, password, login_method):
  120. raise MissingAuthenticationError(
  121. 'Load the following variables in your user environment: '
  122. 'USERNAME, PASSWORD, LOGIN_METHOD'
  123. )
  124. _middleware = LocalAuthentication(
  125. False, AnticaptchaClient(captcha_key), debug
  126. )
  127. return _middleware.set_credentials(
  128. username, password, login_method
  129. )