1
0

test_linode.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Nicole Thomas <nicole@saltstack.com>
  4. '''
  5. # Import Salt Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase, skipIf
  10. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  11. # Import Salt Libs
  12. from salt.cloud.clouds import linode
  13. @skipIf(NO_MOCK, NO_MOCK_REASON)
  14. class LinodeTestCase(TestCase, LoaderModuleMockMixin):
  15. '''
  16. Unit TestCase for the salt.cloud.clouds.linode module.
  17. '''
  18. def setup_loader_modules(self):
  19. return {linode: {}}
  20. # _validate_name tests
  21. def test_validate_name_first_character_invalid(self):
  22. '''
  23. Tests when name starts with an invalid character.
  24. '''
  25. # Test when name begins with a hyphen
  26. self.assertFalse(linode._validate_name('-foo'))
  27. # Test when name begins with an underscore
  28. self.assertFalse(linode._validate_name('_foo'))
  29. def test_validate_name_last_character_invalid(self):
  30. '''
  31. Tests when name ends with an invalid character.
  32. '''
  33. # Test when name ends with a hyphen
  34. self.assertFalse(linode._validate_name('foo-'))
  35. # Test when name ends with an underscore
  36. self.assertFalse(linode._validate_name('foo_'))
  37. def test_validate_name_too_short(self):
  38. '''
  39. Tests when name has less than three letters.
  40. '''
  41. # Test when name is an empty string
  42. self.assertFalse(linode._validate_name(''))
  43. # Test when name is two letters long
  44. self.assertFalse(linode._validate_name('ab'))
  45. # Test when name is three letters long (valid)
  46. self.assertTrue(linode._validate_name('abc'))
  47. def test_validate_name_too_long(self):
  48. '''
  49. Tests when name has more than 48 letters.
  50. '''
  51. long_name = '1111-2222-3333-4444-5555-6666-7777-8888-9999-111'
  52. # Test when name is 48 letters long (valid)
  53. self.assertEqual(len(long_name), 48)
  54. self.assertTrue(linode._validate_name(long_name))
  55. # Test when name is more than 48 letters long
  56. long_name += '1'
  57. self.assertEqual(len(long_name), 49)
  58. self.assertFalse(linode._validate_name(long_name))
  59. def test_validate_name_invalid_characters(self):
  60. '''
  61. Tests when name contains invalid characters.
  62. '''
  63. # Test when name contains an invalid character
  64. self.assertFalse(linode._validate_name('foo;bar'))
  65. # Test when name contains non-ascii letters
  66. self.assertFalse(linode._validate_name('fooàààààbar'))
  67. # Test when name contains spaces
  68. self.assertFalse(linode._validate_name('foo bar'))
  69. def test_validate_name_valid_characters(self):
  70. '''
  71. Tests when name contains valid characters.
  72. '''
  73. # Test when name contains letters and numbers
  74. self.assertTrue(linode._validate_name('foo123bar'))
  75. # Test when name contains hyphens
  76. self.assertTrue(linode._validate_name('foo-bar'))
  77. # Test when name contains underscores
  78. self.assertTrue(linode._validate_name('foo_bar'))
  79. # Test when name start and end with numbers
  80. self.assertTrue(linode._validate_name('1foo'))
  81. self.assertTrue(linode._validate_name('foo0'))