test_swift.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. """
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.modules.swift as swift
  9. from tests.support.mock import MagicMock, patch
  10. # Import Salt Testing Libs
  11. from tests.support.unit import TestCase
  12. class SwiftTestCase(TestCase):
  13. """
  14. Test cases for salt.modules.swift
  15. """
  16. # 'delete' function tests: 1
  17. def test_delete(self):
  18. """
  19. Test for delete a container, or delete an object from a container.
  20. """
  21. with patch.object(swift, "_auth", MagicMock()):
  22. self.assertTrue(swift.delete("mycontainer"))
  23. self.assertTrue(swift.delete("mycontainer", path="myfile.png"))
  24. # 'get' function tests: 1
  25. def test_get(self):
  26. """
  27. Test for list the contents of a container,
  28. or return an object from a container.
  29. """
  30. with patch.object(swift, "_auth", MagicMock()):
  31. self.assertTrue(swift.get())
  32. self.assertTrue(swift.get("mycontainer"))
  33. self.assertTrue(
  34. swift.get("mycontainer", path="myfile.png", return_bin=True)
  35. )
  36. self.assertTrue(
  37. swift.get(
  38. "mycontainer", path="myfile.png", local_file="/tmp/myfile.png"
  39. )
  40. )
  41. self.assertFalse(swift.get("mycontainer", path="myfile.png"))
  42. # 'put' function tests: 1
  43. def test_put(self):
  44. """
  45. Test for create a new container, or upload an object to a container.
  46. """
  47. with patch.object(swift, "_auth", MagicMock()):
  48. self.assertTrue(swift.put("mycontainer"))
  49. self.assertTrue(
  50. swift.put(
  51. "mycontainer", path="myfile.png", local_file="/tmp/myfile.png"
  52. )
  53. )
  54. self.assertFalse(swift.put("mycontainer", path="myfile.png"))