mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Move Nexus state tests to pytest
This commit is contained in:
parent
824582f9ba
commit
920ca4846e
2 changed files with 43 additions and 55 deletions
43
tests/pytests/unit/states/test_nexus.py
Normal file
43
tests/pytests/unit/states/test_nexus.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
"""
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import salt.states.nexus as nexus
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
return {nexus: {}}
|
||||
|
||||
|
||||
def test_downloaded():
|
||||
"""
|
||||
Test to ensures that the artifact from nexus exists at
|
||||
given location.
|
||||
"""
|
||||
name = "jboss"
|
||||
arti_url = "http://nexus.example.com/repository"
|
||||
artifact = {
|
||||
"nexus_url": arti_url,
|
||||
"artifact_id": "module",
|
||||
"repository": "libs-releases",
|
||||
"packaging": "jar",
|
||||
"group_id": "com.company.module",
|
||||
"classifier": "sources",
|
||||
"version": "1.0",
|
||||
}
|
||||
|
||||
ret = {"name": name, "result": False, "changes": {}, "comment": ""}
|
||||
|
||||
mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
|
||||
with patch.dict(nexus.__salt__, {"nexus.get_release": mck}):
|
||||
assert nexus.downloaded(name, artifact) == ret
|
||||
|
||||
with patch.object(
|
||||
nexus, "__fetch_from_nexus", MagicMock(side_effect=Exception("error"))
|
||||
):
|
||||
ret = nexus.downloaded(name, artifact)
|
||||
assert ret["result"] is False
|
||||
assert ret["comment"] == "error"
|
|
@ -1,55 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
"""
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.states.nexus as nexus
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.mixins import LoaderModuleMockMixin
|
||||
from tests.support.mock import MagicMock, patch
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
|
||||
class nexusTestCase(TestCase, LoaderModuleMockMixin):
|
||||
"""
|
||||
Test cases for salt.states.nexus
|
||||
"""
|
||||
|
||||
def setup_loader_modules(self):
|
||||
return {nexus: {}}
|
||||
|
||||
# 'downloaded' function tests: 1
|
||||
|
||||
def test_downloaded(self):
|
||||
"""
|
||||
Test to ensures that the artifact from nexus exists at
|
||||
given location.
|
||||
"""
|
||||
name = "jboss"
|
||||
arti_url = "http://nexus.example.com/repository"
|
||||
artifact = {
|
||||
"nexus_url": arti_url,
|
||||
"artifact_id": "module",
|
||||
"repository": "libs-releases",
|
||||
"packaging": "jar",
|
||||
"group_id": "com.company.module",
|
||||
"classifier": "sources",
|
||||
"version": "1.0",
|
||||
}
|
||||
|
||||
ret = {"name": name, "result": False, "changes": {}, "comment": ""}
|
||||
|
||||
mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
|
||||
with patch.dict(nexus.__salt__, {"nexus.get_release": mck}):
|
||||
self.assertDictEqual(nexus.downloaded(name, artifact), ret)
|
||||
|
||||
with patch.object(
|
||||
nexus, "__fetch_from_nexus", MagicMock(side_effect=Exception("error"))
|
||||
):
|
||||
ret = nexus.downloaded(name, artifact)
|
||||
self.assertEqual(ret["result"], False)
|
||||
self.assertEqual(ret["comment"], "error")
|
Loading…
Add table
Reference in a new issue