1
0

test_mac_xattr.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # -*- coding: utf-8 -*-
  2. """
  3. integration tests for mac_xattr
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. from tests.support.case import ModuleCase
  8. from tests.support.helpers import runs_on, skip_if_binaries_missing, slowTest
  9. from tests.support.runtests import RUNTIME_VARS
  10. @runs_on(kernel="Darwin")
  11. @skip_if_binaries_missing("xattr")
  12. class MacXattrModuleTest(ModuleCase):
  13. """
  14. Validate the mac_xattr module
  15. """
  16. @classmethod
  17. def setUpClass(cls):
  18. cls.test_file = os.path.join(RUNTIME_VARS.TMP, "xattr_test_file.txt")
  19. cls.no_file = os.path.join(RUNTIME_VARS.TMP, "xattr_no_file.txt")
  20. def setUp(self):
  21. """
  22. Create test file for testing extended attributes
  23. """
  24. self.run_function("file.touch", [self.test_file])
  25. def tearDown(self):
  26. """
  27. Clean up test file
  28. """
  29. if os.path.exists(self.test_file):
  30. os.remove(self.test_file)
  31. @slowTest
  32. def test_list_no_xattr(self):
  33. """
  34. Make sure there are no attributes
  35. """
  36. # Clear existing attributes
  37. self.assertTrue(self.run_function("xattr.clear", [self.test_file]))
  38. # Test no attributes
  39. self.assertEqual(self.run_function("xattr.list", [self.test_file]), {})
  40. # Test file not found
  41. self.assertEqual(
  42. self.run_function("xattr.list", [self.no_file]),
  43. "ERROR: File not found: {0}".format(self.no_file),
  44. )
  45. @slowTest
  46. def test_write(self):
  47. """
  48. Write an attribute
  49. """
  50. # Clear existing attributes
  51. self.assertTrue(self.run_function("xattr.clear", [self.test_file]))
  52. # Write some attributes
  53. self.assertTrue(
  54. self.run_function(
  55. "xattr.write", [self.test_file, "spongebob", "squarepants"]
  56. )
  57. )
  58. self.assertTrue(
  59. self.run_function("xattr.write", [self.test_file, "squidward", "plankton"])
  60. )
  61. self.assertTrue(
  62. self.run_function("xattr.write", [self.test_file, "crabby", "patty"])
  63. )
  64. # Test that they were actually added
  65. self.assertEqual(
  66. self.run_function("xattr.list", [self.test_file]),
  67. {"spongebob": "squarepants", "squidward": "plankton", "crabby": "patty"},
  68. )
  69. # Test file not found
  70. self.assertEqual(
  71. self.run_function("xattr.write", [self.no_file, "patrick", "jellyfish"]),
  72. "ERROR: File not found: {0}".format(self.no_file),
  73. )
  74. @slowTest
  75. def test_read(self):
  76. """
  77. Test xattr.read
  78. """
  79. # Clear existing attributes
  80. self.assertTrue(self.run_function("xattr.clear", [self.test_file]))
  81. # Write an attribute
  82. self.assertTrue(
  83. self.run_function(
  84. "xattr.write", [self.test_file, "spongebob", "squarepants"]
  85. )
  86. )
  87. # Read the attribute
  88. self.assertEqual(
  89. self.run_function("xattr.read", [self.test_file, "spongebob"]),
  90. "squarepants",
  91. )
  92. # Test file not found
  93. self.assertEqual(
  94. self.run_function("xattr.read", [self.no_file, "spongebob"]),
  95. "ERROR: File not found: {0}".format(self.no_file),
  96. )
  97. # Test attribute not found
  98. self.assertEqual(
  99. self.run_function("xattr.read", [self.test_file, "patrick"]),
  100. "ERROR: Attribute not found: patrick",
  101. )
  102. @slowTest
  103. def test_delete(self):
  104. """
  105. Test xattr.delete
  106. """
  107. # Clear existing attributes
  108. self.assertTrue(self.run_function("xattr.clear", [self.test_file]))
  109. # Write some attributes
  110. self.assertTrue(
  111. self.run_function(
  112. "xattr.write", [self.test_file, "spongebob", "squarepants"]
  113. )
  114. )
  115. self.assertTrue(
  116. self.run_function("xattr.write", [self.test_file, "squidward", "plankton"])
  117. )
  118. self.assertTrue(
  119. self.run_function("xattr.write", [self.test_file, "crabby", "patty"])
  120. )
  121. # Delete an attribute
  122. self.assertTrue(
  123. self.run_function("xattr.delete", [self.test_file, "squidward"])
  124. )
  125. # Make sure it was actually deleted
  126. self.assertEqual(
  127. self.run_function("xattr.list", [self.test_file]),
  128. {"spongebob": "squarepants", "crabby": "patty"},
  129. )
  130. # Test file not found
  131. self.assertEqual(
  132. self.run_function("xattr.delete", [self.no_file, "spongebob"]),
  133. "ERROR: File not found: {0}".format(self.no_file),
  134. )
  135. # Test attribute not found
  136. self.assertEqual(
  137. self.run_function("xattr.delete", [self.test_file, "patrick"]),
  138. "ERROR: Attribute not found: patrick",
  139. )
  140. @slowTest
  141. def test_clear(self):
  142. """
  143. Test xattr.clear
  144. """
  145. # Clear existing attributes
  146. self.assertTrue(self.run_function("xattr.clear", [self.test_file]))
  147. # Write some attributes
  148. self.assertTrue(
  149. self.run_function(
  150. "xattr.write", [self.test_file, "spongebob", "squarepants"]
  151. )
  152. )
  153. self.assertTrue(
  154. self.run_function("xattr.write", [self.test_file, "squidward", "plankton"])
  155. )
  156. self.assertTrue(
  157. self.run_function("xattr.write", [self.test_file, "crabby", "patty"])
  158. )
  159. # Test Clear
  160. self.assertTrue(self.run_function("xattr.clear", [self.test_file]))
  161. # Test file not found
  162. self.assertEqual(
  163. self.run_function("xattr.clear", [self.no_file]),
  164. "ERROR: File not found: {0}".format(self.no_file),
  165. )