mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_swift to pytest
This commit is contained in:
parent
f829deaf63
commit
8da111674a
2 changed files with 55 additions and 66 deletions
55
tests/pytests/unit/modules/test_swift.py
Normal file
55
tests/pytests/unit/modules/test_swift.py
Normal 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")
|
|
@ -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"))
|
Loading…
Add table
Reference in a new issue