__init__.py 2.4 KB

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