1
0

test_linode.py 3.2 KB

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