migrate test_swift to pytest

This commit is contained in:
Frode Gundersen 2023-01-13 16:28:39 +00:00 committed by Pedro Algarvio
parent f829deaf63
commit 8da111674a
2 changed files with 55 additions and 66 deletions

View file

@ -0,0 +1,55 @@
"""
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
Test cases for salt.modules.swift
"""
import pytest
import salt.modules.swift as swift
from tests.support.mock import MagicMock, patch
@pytest.fixture
def configure_loader_modules():
return {swift: {}}
def test_delete():
"""
Test for delete a container, or delete an object from a container.
"""
with patch.object(swift, "_auth", MagicMock()):
assert swift.delete("mycontainer")
assert swift.delete("mycontainer", path="myfile.png")
def test_get():
"""
Test for list the contents of a container,
or return an object from a container.
"""
with patch.object(swift, "_auth", MagicMock()):
assert swift.get()
assert swift.get("mycontainer")
assert swift.get("mycontainer", path="myfile.png", return_bin=True)
assert swift.get("mycontainer", path="myfile.png", local_file="/tmp/myfile.png")
assert not swift.get("mycontainer", path="myfile.png")
def test_put():
"""
Test for create a new container, or upload an object to a container.
"""
with patch.object(swift, "_auth", MagicMock()):
assert swift.put("mycontainer")
assert swift.put("mycontainer", path="myfile.png", local_file="/tmp/myfile.png")
assert not swift.put("mycontainer", path="myfile.png")

View file

@ -1,66 +0,0 @@
"""
:codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
"""
import salt.modules.swift as swift
from tests.support.mock import MagicMock, patch
from tests.support.unit import TestCase
class SwiftTestCase(TestCase):
"""
Test cases for salt.modules.swift
"""
# 'delete' function tests: 1
def test_delete(self):
"""
Test for delete a container, or delete an object from a container.
"""
with patch.object(swift, "_auth", MagicMock()):
self.assertTrue(swift.delete("mycontainer"))
self.assertTrue(swift.delete("mycontainer", path="myfile.png"))
# 'get' function tests: 1
def test_get(self):
"""
Test for list the contents of a container,
or return an object from a container.
"""
with patch.object(swift, "_auth", MagicMock()):
self.assertTrue(swift.get())
self.assertTrue(swift.get("mycontainer"))
self.assertTrue(
swift.get("mycontainer", path="myfile.png", return_bin=True)
)
self.assertTrue(
swift.get(
"mycontainer", path="myfile.png", local_file="/tmp/myfile.png"
)
)
self.assertFalse(swift.get("mycontainer", path="myfile.png"))
# 'put' function tests: 1
def test_put(self):
"""
Test for create a new container, or upload an object to a container.
"""
with patch.object(swift, "_auth", MagicMock()):
self.assertTrue(swift.put("mycontainer"))
self.assertTrue(
swift.put(
"mycontainer", path="myfile.png", local_file="/tmp/myfile.png"
)
)
self.assertFalse(swift.put("mycontainer", path="myfile.png"))