test_azure_helpers.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from azure_test.helpers import ProviderTestBase
  2. from cloudbridge.cloud.providers.azure import helpers as azure_helpers
  3. class AzureHelpersTestCase(ProviderTestBase):
  4. def test_parse_url_valid(self):
  5. params = azure_helpers.parse_url('/subscriptionId/{subscriptionId}', '/subscriptionId/123-1345')
  6. self.assertTrue(len(params) == 1, 'Parameter count should be 1')
  7. def test_parse_url_invalid(self):
  8. with self.assertRaises(Exception):
  9. params = azure_helpers.parse_url('/subscriptionId/{subscriptionId}', '/123-1345')
  10. def test_filter_matched(self):
  11. ex1 = Expando()
  12. ex1.name = 'test'
  13. ex2 = Expando()
  14. ex2.name = 'abc'
  15. result = azure_helpers.filter([ex1, ex2], {'name': 'test'})
  16. self.assertTrue(len(result) == 1, 'Result count should be one')
  17. def test_filter_not_matched(self):
  18. ex1 = Expando()
  19. ex1.name = 'pqr'
  20. ex2 = Expando()
  21. ex2.name = 'abc'
  22. result = azure_helpers.filter([ex1, ex2], {'name': 'test123'})
  23. self.assertTrue(len(result) == 0, 'Result count should be zero')
  24. def test_filter_None(self):
  25. ex1 = Expando()
  26. ex1.name = 'pqr'
  27. ex2 = Expando()
  28. ex2.name = 'abc'
  29. result = azure_helpers.filter([ex1, ex2], None)
  30. self.assertTrue(len(result) == 2, 'Result count should be two')
  31. class Expando(object):
  32. pass