__init__.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. Tests the functionality of each provider implementation against registered test cases.
  3. These tests require that provider credentials are set as environment variables,
  4. as required for each provider (see `tox.ini` for a list of env variables).
  5. Since the tests exercise the ``cloudbridge`` interfaces, and there are multiple
  6. implementations of these interfaces, for m interfaces and n implementation,
  7. exercising all interfaces means that m*n test case classes are needed. Otherwise,
  8. the standard test runners such as unittest and nose2 do not correctly pick up
  9. the tests.
  10. To avoid an explosion of repetitive test cases, the ``ProviderTestCaseGenerator``
  11. class will automatically generate a new Python class for each combination of
  12. test and provider. The ``load_tests`` protocol
  13. (https://docs.python.org/2/library/unittest.html#load-tests-protocol)
  14. is used to aid test discovery.
  15. Use ``python setup.py test`` to run these unit tests (alternatively, use
  16. ``python -m unittest test``).
  17. All test cases need to be registered below, and available providers will be
  18. discovered through the ``ProviderFactory``. Test Cases must not inherit from
  19. ``unittest.TestCase``, to avoid confusing unittest and nose2's automatic discovery.
  20. (The test generator will automatically add ``unittest.TestCase`` as a base class
  21. to each combination).
  22. """
  23. from test.helpers import ProviderTestCaseGenerator
  24. from test.test_compute_service import ProviderComputeServiceTestCase
  25. from test.test_provider_image_service import ProviderImageServiceTestCase
  26. from test.test_provider_interface import ProviderInterfaceTestCase
  27. from test.test_provider_security_service import ProviderSecurityServiceTestCase
  28. PROVIDER_TESTS = [
  29. ProviderInterfaceTestCase,
  30. ProviderSecurityServiceTestCase,
  31. ProviderComputeServiceTestCase,
  32. ProviderImageServiceTestCase
  33. ]
  34. def load_tests(loader=None, tests=None, pattern=None):
  35. """
  36. This function is required to aid the load_tests protocol
  37. (https://docs.python.org/2/library/unittest.html#load-tests-protocol)
  38. """
  39. return ProviderTestCaseGenerator(PROVIDER_TESTS).generate_tests()