conftest.py 939 B

12345678910111213141516171819202122232425262728
  1. """Test configuration"""
  2. import os
  3. from rival_regions_wrapper import LocalAuthentication, ApiWrapper
  4. from dotenv import load_dotenv
  5. import pytest
  6. load_dotenv()
  7. class MissingAuthenticationError(Exception):
  8. """Error for missing authentication"""
  9. @pytest.fixture(scope="module")
  10. def api_wrapper():
  11. """Set up wrapper before test"""
  12. rr_username = os.environ.get('RIVAL_REGIONS_USERNAME', None)
  13. rr_password = os.environ.get('RIVAL_REGIONS_PASSWORD', None)
  14. rr_login_method = os.environ.get('RIVAL_REGIONS_LOGIN_METHOD', None)
  15. if None in (rr_username, rr_password, rr_login_method):
  16. raise MissingAuthenticationError(
  17. 'Load the following variables in your user environment: '
  18. 'RIVAL_REGIONS_USERNAME, RIVAL_REGIONS_PASSWORD, RIVAL_REGIONS_LOGIN_METHOD'
  19. )
  20. authentication = LocalAuthentication(rr_username, rr_password, rr_login_method)
  21. return ApiWrapper(authentication)