test_nexus.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: :email:`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.states.nexus as nexus
  9. # Import Salt Testing Libs
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.mock import MagicMock, patch
  12. from tests.support.unit import TestCase
  13. class nexusTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases for salt.states.nexus
  16. """
  17. def setup_loader_modules(self):
  18. return {nexus: {}}
  19. # 'downloaded' function tests: 1
  20. def test_downloaded(self):
  21. """
  22. Test to ensures that the artifact from nexus exists at
  23. given location.
  24. """
  25. name = "jboss"
  26. arti_url = "http://nexus.example.com/repository"
  27. artifact = {
  28. "nexus_url": arti_url,
  29. "artifact_id": "module",
  30. "repository": "libs-releases",
  31. "packaging": "jar",
  32. "group_id": "com.company.module",
  33. "classifier": "sources",
  34. "version": "1.0",
  35. }
  36. ret = {"name": name, "result": False, "changes": {}, "comment": ""}
  37. mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
  38. with patch.dict(nexus.__salt__, {"nexus.get_release": mck}):
  39. self.assertDictEqual(nexus.downloaded(name, artifact), ret)
  40. with patch.object(
  41. nexus, "__fetch_from_nexus", MagicMock(side_effect=Exception("error"))
  42. ):
  43. ret = nexus.downloaded(name, artifact)
  44. self.assertEqual(ret["result"], False)
  45. self.assertEqual(ret["comment"], "error")