[tests] Do not mock open for koji wrapper tests
Instead create a temporary file and write into it, then check its contents. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
a3044f4381
commit
3ff1d3e21f
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
import unittest
|
import unittest
|
||||||
|
import tempfile
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -14,6 +15,7 @@ from pungi.wrappers.kojiwrapper import KojiWrapper
|
|||||||
|
|
||||||
class KojiWrapperBaseTestCase(unittest.TestCase):
|
class KojiWrapperBaseTestCase(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
_, self.tmpfile = tempfile.mkstemp()
|
||||||
self.koji_profile = mock.Mock()
|
self.koji_profile = mock.Mock()
|
||||||
with mock.patch('pungi.wrappers.kojiwrapper.koji') as koji:
|
with mock.patch('pungi.wrappers.kojiwrapper.koji') as koji:
|
||||||
koji.get_profile_module = mock.Mock(
|
koji.get_profile_module = mock.Mock(
|
||||||
@ -28,10 +30,12 @@ class KojiWrapperBaseTestCase(unittest.TestCase):
|
|||||||
self.koji_profile = koji.get_profile_module.return_value
|
self.koji_profile = koji.get_profile_module.return_value
|
||||||
self.koji = KojiWrapper('koji')
|
self.koji = KojiWrapper('koji')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.remove(self.tmpfile)
|
||||||
|
|
||||||
|
|
||||||
class KojiWrapperTest(KojiWrapperBaseTestCase):
|
class KojiWrapperTest(KojiWrapperBaseTestCase):
|
||||||
@mock.patch('pungi.wrappers.kojiwrapper.open')
|
def test_get_image_build_cmd_without_required_data(self):
|
||||||
def test_get_image_build_cmd_without_required_data(self, mock_open):
|
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
self.koji.get_image_build_cmd(
|
self.koji.get_image_build_cmd(
|
||||||
{
|
{
|
||||||
@ -39,11 +43,10 @@ class KojiWrapperTest(KojiWrapperBaseTestCase):
|
|||||||
'name': 'test-name',
|
'name': 'test-name',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'/tmp/file'
|
self.tmpfile
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('pungi.wrappers.kojiwrapper.open')
|
def test_get_image_build_cmd_correct(self):
|
||||||
def test_get_image_build_cmd_correct(self, mock_open):
|
|
||||||
cmd = self.koji.get_image_build_cmd(
|
cmd = self.koji.get_image_build_cmd(
|
||||||
{
|
{
|
||||||
'image-build': {
|
'image-build': {
|
||||||
@ -59,28 +62,28 @@ class KojiWrapperTest(KojiWrapperBaseTestCase):
|
|||||||
'release': '20160222.0',
|
'release': '20160222.0',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'/tmp/file'
|
self.tmpfile
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(cmd[0], 'koji')
|
self.assertEqual(cmd[0], 'koji')
|
||||||
self.assertEqual(cmd[1], 'image-build')
|
self.assertEqual(cmd[1], 'image-build')
|
||||||
self.assertItemsEqual(cmd[2:],
|
self.assertItemsEqual(cmd[2:],
|
||||||
['--config=/tmp/file', '--wait'])
|
['--config=' + self.tmpfile, '--wait'])
|
||||||
|
|
||||||
output = mock_open.return_value
|
with open(self.tmpfile, 'r') as f:
|
||||||
self.assertEqual(mock.call('[image-build]\n'), output.write.mock_calls[0])
|
lines = f.read().strip().split('\n')
|
||||||
self.assertItemsEqual(output.write.mock_calls[1:],
|
self.assertEqual(lines[0], '[image-build]')
|
||||||
[mock.call('name = test-name\n'),
|
self.assertItemsEqual(lines[1:],
|
||||||
mock.call('version = 1\n'),
|
['name = test-name',
|
||||||
mock.call('target = test-target\n'),
|
'version = 1',
|
||||||
mock.call('install_tree = /tmp/test/install_tree\n'),
|
'target = test-target',
|
||||||
mock.call('arches = x86_64\n'),
|
'install_tree = /tmp/test/install_tree',
|
||||||
mock.call('format = docker,qcow2\n'),
|
'arches = x86_64',
|
||||||
mock.call('kickstart = test-kickstart\n'),
|
'format = docker,qcow2',
|
||||||
mock.call('ksurl = git://example.com/ks.git\n'),
|
'kickstart = test-kickstart',
|
||||||
mock.call('distro = test-distro\n'),
|
'ksurl = git://example.com/ks.git',
|
||||||
mock.call('release = 20160222.0\n'),
|
'distro = test-distro',
|
||||||
mock.call('\n')])
|
'release = 20160222.0'])
|
||||||
|
|
||||||
def test_get_image_paths(self):
|
def test_get_image_paths(self):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user