__init__.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_block_store_service import CloudBlockStoreServiceTestCase
  27. from test.test_cloud_helpers import CloudHelpersTestCase
  28. from test.test_compute_service import CloudComputeServiceTestCase
  29. from test.test_image_service import CloudImageServiceTestCase
  30. from test.test_instance_types_service import CloudInstanceTypesServiceTestCase
  31. from test.test_interface import CloudInterfaceTestCase
  32. from test.test_network_service import CloudNetworkServiceTestCase
  33. from test.test_object_life_cycle import CloudObjectLifeCycleTestCase
  34. from test.test_object_store_service import CloudObjectStoreServiceTestCase
  35. from test.test_region_service import CloudRegionServiceTestCase
  36. from test.test_security_service import CloudSecurityServiceTestCase
  37. PROVIDER_TESTS = [
  38. CloudHelpersTestCase,
  39. CloudInterfaceTestCase,
  40. CloudObjectLifeCycleTestCase,
  41. CloudSecurityServiceTestCase,
  42. CloudNetworkServiceTestCase,
  43. CloudInstanceTypesServiceTestCase,
  44. CloudBlockStoreServiceTestCase,
  45. CloudObjectStoreServiceTestCase,
  46. CloudComputeServiceTestCase,
  47. CloudRegionServiceTestCase,
  48. CloudImageServiceTestCase
  49. ]
  50. def load_tests(loader=None, tests=None, pattern=None):
  51. """
  52. This function is required to aid the load_tests protocol
  53. (https://docs.python.org/2/library/unittest.html#load-tests-protocol)
  54. """
  55. cloudbridge.init_logging()
  56. return ProviderTestCaseGenerator(PROVIDER_TESTS).generate_tests()