base_test.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # coding=utf-8
  2. """
  3. Base test utilities and common imports for all provider tests
  4. @author: Github Copilot
  5. """
  6. import unittest
  7. import sys
  8. import os
  9. # Add the parent directory to the path so we can import the ddns module
  10. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  11. try:
  12. from unittest.mock import patch, MagicMock
  13. except ImportError:
  14. # Python 2.7 compatibility
  15. from mock import patch, MagicMock # type: ignore
  16. class BaseProviderTestCase(unittest.TestCase):
  17. """Base test case class with common setup for all provider tests"""
  18. def setUp(self):
  19. """Set up common test fixtures"""
  20. self.auth_id = "test_id"
  21. self.auth_token = "test_token"
  22. def assertProviderInitialized(self, provider, expected_auth_id=None, expected_auth_token=None):
  23. """Helper method to assert provider is correctly initialized"""
  24. self.assertEqual(provider.auth_id, expected_auth_id or self.auth_id)
  25. self.assertEqual(provider.auth_token, expected_auth_token or self.auth_token)
  26. def mock_logger(self, provider):
  27. """Helper method to mock provider logger"""
  28. provider.logger = MagicMock()
  29. return provider.logger
  30. # Export commonly used imports for convenience
  31. __all__ = ["BaseProviderTestCase", "unittest", "patch", "MagicMock"]