conftest.py 851 B

1234567891011121314151617181920212223242526272829
  1. """Test configuration"""
  2. import os
  3. import pytest
  4. from dotenv import load_dotenv
  5. from rival_regions_wrapper import RemoteAuthentication, LocalAuthentication, ApiWrapper
  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. username = os.environ.get('USERNAME', None)
  13. password = os.environ.get('PASSWORD', None)
  14. login_method = os.environ.get('LOGIN_METHOD', None)
  15. if None in (username, password, login_method):
  16. raise MissingAuthenticationError(
  17. 'Load the following variables in your user environment: '
  18. 'username, password, login_method'
  19. )
  20. authentication = LocalAuthentication(username, password, login_method)
  21. return ApiWrapper(authentication)