conftest.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """Test configuration"""
  2. import os
  3. from rival_regions_wrapper import LocalAuthentication, ApiWrapper
  4. from dotenv import load_dotenv
  5. import pytest
  6. import telegram
  7. load_dotenv()
  8. class MissingEnvironmentError(Exception):
  9. """Error for missing environment variable"""
  10. @pytest.fixture(scope="module")
  11. def telegram_channel():
  12. """Set up telegram channel"""
  13. return os.environ.get('TELEGRAM_CHANNEL', None)
  14. @pytest.fixture(scope="module")
  15. def telegram_bot():
  16. """Set up telegram bot before test"""
  17. telegram_key = os.environ.get('TELEGRAM_KEY', None)
  18. if None in (telegram_key, telegram_channel):
  19. raise MissingEnvironmentError(
  20. 'Load the following variables in your user environment: '
  21. 'TELEGRAM_KEY'
  22. )
  23. return telegram.Bot(token=telegram_key)
  24. @pytest.fixture(scope="module")
  25. def api_wrapper():
  26. """Set up wrapper before test"""
  27. rr_username = os.environ.get('RIVAL_REGIONS_USERNAME', None)
  28. rr_password = os.environ.get('RIVAL_REGIONS_PASSWORD', None)
  29. rr_login_method = os.environ.get('RIVAL_REGIONS_LOGIN_METHOD', None)
  30. if None in (rr_username, rr_password, rr_login_method):
  31. raise MissingEnvironmentError(
  32. 'Load the following variables in your user environment: '
  33. 'RIVAL_REGIONS_USERNAME, RIVAL_REGIONS_PASSWORD, RIVAL_REGIONS_LOGIN_METHOD'
  34. )
  35. authentication = LocalAuthentication(rr_username, rr_password, rr_login_method)
  36. return ApiWrapper(authentication)
  37. def pytest_addoption(parser):
  38. """Pytest parser options"""
  39. parser.addoption('--message', action='store_true', dest="message", \
  40. default=False, help="enable messagedecorated tests")
  41. def pytest_configure(config):
  42. """Pytest config"""
  43. if not config.option.message:
  44. setattr(config.option, 'markexpr', 'not message')
  45. config.addinivalue_line(
  46. "markers", "message: send telegram message"
  47. )