65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Unit tests for CrossFitBooker initialization
|
|
"""
|
|
|
|
import pytest
|
|
import os
|
|
import sys
|
|
from unittest.mock import patch
|
|
|
|
# Add the parent directory to the path
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from crossfit_booker import CrossFitBooker
|
|
|
|
|
|
class TestCrossFitBookerInit:
|
|
"""Test cases for CrossFitBooker initialization"""
|
|
|
|
def test_init_success(self):
|
|
"""Test successful initialization with all required env vars"""
|
|
with patch.dict(os.environ, {
|
|
'CROSSFIT_USERNAME': 'test_user',
|
|
'CROSSFIT_PASSWORD': 'test_pass',
|
|
'EMAIL_FROM': 'from@test.com',
|
|
'EMAIL_TO': 'to@test.com',
|
|
'EMAIL_PASSWORD': 'email_pass',
|
|
'TELEGRAM_TOKEN': 'telegram_token',
|
|
'TELEGRAM_CHAT_ID': '12345'
|
|
}):
|
|
booker = CrossFitBooker()
|
|
assert booker.auth_token is None
|
|
assert booker.user_id is None
|
|
assert booker.session is not None
|
|
assert booker.notifier is not None
|
|
|
|
def test_init_missing_credentials(self):
|
|
"""Test initialization fails with missing credentials"""
|
|
with patch.dict(os.environ, {}, clear=True):
|
|
with pytest.raises(ValueError, match="Missing environment variables"):
|
|
CrossFitBooker()
|
|
|
|
def test_init_partial_credentials(self):
|
|
"""Test initialization fails with partial credentials"""
|
|
with patch.dict(os.environ, {
|
|
'CROSSFIT_USERNAME': 'test_user'
|
|
# Missing PASSWORD
|
|
}):
|
|
with pytest.raises(ValueError, match="Missing environment variables"):
|
|
CrossFitBooker()
|
|
|
|
def test_init_with_optional_env_vars(self):
|
|
"""Test initialization with optional environment variables"""
|
|
with patch.dict(os.environ, {
|
|
'CROSSFIT_USERNAME': 'test_user',
|
|
'CROSSFIT_PASSWORD': 'test_pass',
|
|
'ENABLE_EMAIL_NOTIFICATIONS': 'false',
|
|
'ENABLE_TELEGRAM_NOTIFICATIONS': 'false'
|
|
}):
|
|
booker = CrossFitBooker()
|
|
assert booker.notifier is not None
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__, "-v"]) |