test_interface.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import unittest
  2. import cloudbridge
  3. from cloudbridge.cloud import interfaces
  4. from cloudbridge.cloud.factory import CloudProviderFactory
  5. from cloudbridge.cloud.interfaces import TestMockHelperMixin
  6. from cloudbridge.cloud.interfaces.exceptions import ProviderConnectionException
  7. from test.helpers import ProviderTestBase
  8. class CloudInterfaceTestCase(ProviderTestBase):
  9. _multiprocess_can_split_ = True
  10. def test_name_property(self):
  11. """
  12. Name should always return a value and should not raise an exception
  13. """
  14. assert self.provider.name
  15. def test_has_service_valid_service_type(self):
  16. """
  17. has_service with a valid service type should return
  18. a boolean and raise no exceptions
  19. """
  20. for key, value in interfaces.CloudServiceType.__dict__.items():
  21. if not key.startswith("__"):
  22. self.provider.has_service(value)
  23. def test_has_service_invalid_service_type(self):
  24. """
  25. has_service with an invalid service type should return False
  26. """
  27. self.assertFalse(
  28. self.provider.has_service("NON_EXISTENT_SERVICE"),
  29. "has_service should not return True for a non-existent service")
  30. def test_library_version(self):
  31. """
  32. Check that the library version can be retrieved.
  33. """
  34. self.assertIsNotNone(cloudbridge.get_version(),
  35. "Did not get library version.")
  36. def test_authenticate_success(self):
  37. self.assertTrue(self.provider.authenticate())
  38. def test_authenticate_failure(self):
  39. if isinstance(self.provider, TestMockHelperMixin):
  40. raise unittest.SkipTest(
  41. "Mock providers are not expected to"
  42. " authenticate correctly")
  43. # Mock up test by clearing credentials on a per provider basis
  44. cloned_config = self.provider.config.copy()
  45. if self.provider.PROVIDER_ID == 'aws':
  46. cloned_config['aws_access_key'] = "dummy_a_key"
  47. cloned_config['aws_secret_key'] = "dummy_s_key"
  48. elif self.provider.PROVIDER_ID == 'openstack':
  49. cloned_config['os_username'] = "cb_dummy"
  50. cloned_config['os_password'] = "cb_dummy"
  51. elif self.provider.PROVIDER_ID == 'azure':
  52. cloned_config['azure_subscription_id'] = "cb_dummy"
  53. with self.assertRaises(ProviderConnectionException):
  54. cloned_provider = CloudProviderFactory().create_provider(
  55. self.provider.PROVIDER_ID, cloned_config)
  56. cloned_provider.authenticate()