[tests] Use real paths module in testing
This avoids problems of mock paths having different API that the real ones. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
8661d294ab
commit
90954ddf0e
9 changed files with 203 additions and 211 deletions
|
|
@ -13,13 +13,13 @@ import shutil
|
|||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.phases.image_checksum import ImageChecksumPhase, dump_checksums
|
||||
from tests.helpers import _DummyCompose
|
||||
from tests.helpers import _DummyCompose, PungiTestCase
|
||||
|
||||
|
||||
class TestImageChecksumPhase(unittest.TestCase):
|
||||
class TestImageChecksumPhase(PungiTestCase):
|
||||
|
||||
def test_config_skip_individual_with_multiple_algorithms(self):
|
||||
compose = _DummyCompose({
|
||||
compose = _DummyCompose(self.topdir, {
|
||||
'media_checksums': ['md5', 'sha1'],
|
||||
'media_checksum_one_file': True
|
||||
})
|
||||
|
|
@ -32,7 +32,7 @@ class TestImageChecksumPhase(unittest.TestCase):
|
|||
@mock.patch('kobo.shortcuts.compute_file_checksums')
|
||||
@mock.patch('pungi.phases.image_checksum.dump_checksums')
|
||||
def test_checksum_one_file(self, dump, cc, exists):
|
||||
compose = _DummyCompose({
|
||||
compose = _DummyCompose(self.topdir, {
|
||||
'media_checksums': ['sha256'],
|
||||
'media_checksum_one_file': True,
|
||||
})
|
||||
|
|
@ -44,15 +44,15 @@ class TestImageChecksumPhase(unittest.TestCase):
|
|||
|
||||
phase.run()
|
||||
|
||||
dump.assert_called_once_with('/a/b/Client/i386/iso', 'sha256', {'image.iso': 'cafebabe'}, 'CHECKSUM')
|
||||
cc.assert_called_once_with('/a/b/Client/i386/iso/image.iso', ['sha256'])
|
||||
dump.assert_called_once_with(self.topdir + '/compose/Client/i386/iso', 'sha256', {'image.iso': 'cafebabe'}, 'CHECKSUM')
|
||||
cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['sha256'])
|
||||
compose.image.add_checksum.assert_called_once_with(None, 'sha256', 'cafebabe')
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('kobo.shortcuts.compute_file_checksums')
|
||||
@mock.patch('pungi.phases.image_checksum.dump_checksums')
|
||||
def test_checksum_save_individuals(self, dump, cc, exists):
|
||||
compose = _DummyCompose({
|
||||
compose = _DummyCompose(self.topdir, {
|
||||
'media_checksums': ['md5', 'sha256'],
|
||||
})
|
||||
|
||||
|
|
@ -64,13 +64,17 @@ class TestImageChecksumPhase(unittest.TestCase):
|
|||
phase.run()
|
||||
|
||||
dump.assert_has_calls(
|
||||
[mock.call('/a/b/Client/i386/iso', 'md5', {'image.iso': 'cafebabe'}, 'image.iso.MD5SUM'),
|
||||
mock.call('/a/b/Client/i386/iso', 'sha256', {'image.iso': 'deadbeef'}, 'image.iso.SHA256SUM'),
|
||||
mock.call('/a/b/Client/i386/iso', 'md5', {'image.iso': 'cafebabe'}, 'MD5SUM'),
|
||||
mock.call('/a/b/Client/i386/iso', 'sha256', {'image.iso': 'deadbeef'}, 'SHA256SUM')],
|
||||
[mock.call(self.topdir + '/compose/Client/i386/iso', 'md5',
|
||||
{'image.iso': 'cafebabe'}, 'image.iso.MD5SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'sha256',
|
||||
{'image.iso': 'deadbeef'}, 'image.iso.SHA256SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'md5',
|
||||
{'image.iso': 'cafebabe'}, 'MD5SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'sha256',
|
||||
{'image.iso': 'deadbeef'}, 'SHA256SUM')],
|
||||
any_order=True
|
||||
)
|
||||
cc.assert_called_once_with('/a/b/Client/i386/iso/image.iso', ['md5', 'sha256'])
|
||||
cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['md5', 'sha256'])
|
||||
compose.image.add_checksum.assert_has_calls([mock.call(None, 'sha256', 'deadbeef'),
|
||||
mock.call(None, 'md5', 'cafebabe')],
|
||||
any_order=True)
|
||||
|
|
@ -79,7 +83,7 @@ class TestImageChecksumPhase(unittest.TestCase):
|
|||
@mock.patch('kobo.shortcuts.compute_file_checksums')
|
||||
@mock.patch('pungi.phases.image_checksum.dump_checksums')
|
||||
def test_checksum_one_file_custom_name(self, dump, cc, exists):
|
||||
compose = _DummyCompose({
|
||||
compose = _DummyCompose(self.topdir, {
|
||||
'media_checksums': ['sha256'],
|
||||
'media_checksum_one_file': True,
|
||||
'media_checksum_base_filename': '%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s'
|
||||
|
|
@ -92,17 +96,17 @@ class TestImageChecksumPhase(unittest.TestCase):
|
|||
|
||||
phase.run()
|
||||
|
||||
dump.assert_called_once_with('/a/b/Client/i386/iso', 'sha256',
|
||||
dump.assert_called_once_with(self.topdir + '/compose/Client/i386/iso', 'sha256',
|
||||
{'image.iso': 'cafebabe'},
|
||||
'test-Client-1.0-20151203.t.0-CHECKSUM')
|
||||
cc.assert_called_once_with('/a/b/Client/i386/iso/image.iso', ['sha256'])
|
||||
cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['sha256'])
|
||||
compose.image.add_checksum.assert_called_once_with(None, 'sha256', 'cafebabe')
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('kobo.shortcuts.compute_file_checksums')
|
||||
@mock.patch('pungi.phases.image_checksum.dump_checksums')
|
||||
def test_checksum_save_individuals_custom_name(self, dump, cc, exists):
|
||||
compose = _DummyCompose({
|
||||
compose = _DummyCompose(self.topdir, {
|
||||
'media_checksums': ['md5', 'sha256'],
|
||||
'media_checksum_base_filename': '%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s'
|
||||
})
|
||||
|
|
@ -115,15 +119,17 @@ class TestImageChecksumPhase(unittest.TestCase):
|
|||
phase.run()
|
||||
|
||||
dump.assert_has_calls(
|
||||
[mock.call('/a/b/Client/i386/iso', 'md5', {'image.iso': 'cafebabe'}, 'image.iso.MD5SUM'),
|
||||
mock.call('/a/b/Client/i386/iso', 'sha256', {'image.iso': 'deadbeef'}, 'image.iso.SHA256SUM'),
|
||||
mock.call('/a/b/Client/i386/iso', 'md5', {'image.iso': 'cafebabe'},
|
||||
[mock.call(self.topdir + '/compose/Client/i386/iso', 'md5',
|
||||
{'image.iso': 'cafebabe'}, 'image.iso.MD5SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'sha256',
|
||||
{'image.iso': 'deadbeef'}, 'image.iso.SHA256SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'md5', {'image.iso': 'cafebabe'},
|
||||
'test-Client-1.0-20151203.t.0-MD5SUM'),
|
||||
mock.call('/a/b/Client/i386/iso', 'sha256', {'image.iso': 'deadbeef'},
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'sha256', {'image.iso': 'deadbeef'},
|
||||
'test-Client-1.0-20151203.t.0-SHA256SUM')],
|
||||
any_order=True
|
||||
)
|
||||
cc.assert_called_once_with('/a/b/Client/i386/iso/image.iso', ['md5', 'sha256'])
|
||||
cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['md5', 'sha256'])
|
||||
compose.image.add_checksum.assert_has_calls([mock.call(None, 'sha256', 'deadbeef'),
|
||||
mock.call(None, 'md5', 'cafebabe')],
|
||||
any_order=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue