test_azure_helpers.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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}',
  6. '/subscriptionId/123-1345')
  7. self.assertTrue(len(params) == 1, 'Parameter count should be 1')
  8. def test_parse_url_invalid(self):
  9. with self.assertRaises(Exception):
  10. azure_helpers.parse_url('/subscriptionId/{subscriptionId}',
  11. '/123-1345')
  12. def test_filter_matched(self):
  13. ex1 = Expando()
  14. ex1.tags = {'Name': 'test'}
  15. ex2 = Expando()
  16. ex2.tags = {'Name': 'abc'}
  17. result = azure_helpers.filter([ex1, ex2], {'Name': 'test'})
  18. self.assertTrue(len(result) == 1, 'Result count should be one')
  19. def test_filter_not_matched(self):
  20. ex1 = Expando()
  21. ex1.tags = {'Name': 'pqr'}
  22. ex2 = Expando()
  23. ex2.tags = {'Name': 'abc'}
  24. result = azure_helpers.filter([ex1, ex2], {'Name': 'test123'})
  25. self.assertTrue(len(result) == 0, 'Result count should be zero')
  26. def test_filter_None(self):
  27. ex1 = Expando()
  28. ex1.tags = {'Name': 'test'}
  29. ex2 = Expando()
  30. ex2.tags = {'Name': 'abc'}
  31. result = azure_helpers.filter([ex1, ex2], None)
  32. self.assertTrue(len(result) == 2, 'Result count should be two')
  33. class Expando(object):
  34. pass