[tests] Move dummy testing compose into separate module
This greatly reduces duplication, as a single copy is now shared among all test cases. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
75b57ac25a
commit
8661d294ab
74
tests/helpers.py
Normal file
74
tests/helpers.py
Normal file
@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import mock
|
||||
import os
|
||||
|
||||
from pungi.util import get_arch_variant_data
|
||||
|
||||
|
||||
class _DummyCompose(object):
|
||||
def __init__(self, config):
|
||||
self.compose_date = '20151203'
|
||||
self.compose_type_suffix = '.t'
|
||||
self.compose_respin = 0
|
||||
self.compose_id = 'Test-20151203.0.t'
|
||||
self.ci_base = mock.Mock(
|
||||
release_id='Test-1.0',
|
||||
release=mock.Mock(
|
||||
short='test',
|
||||
version='1.0',
|
||||
),
|
||||
)
|
||||
self.conf = config
|
||||
self.paths = mock.Mock(
|
||||
compose=mock.Mock(
|
||||
topdir=mock.Mock(return_value='/a/b'),
|
||||
os_tree=mock.Mock(
|
||||
side_effect=lambda arch, variant, create_dir=False: os.path.join('/ostree', arch, variant.uid)
|
||||
),
|
||||
repository=mock.Mock(
|
||||
side_effect=lambda arch, variant, create_dir=False: os.path.join('/repo', arch, variant.uid)
|
||||
),
|
||||
image_dir=mock.Mock(
|
||||
side_effect=lambda variant, relative=False, symlink_to=None: os.path.join(
|
||||
'' if relative else '/', 'image_dir', variant.uid, '%(arch)s'
|
||||
)
|
||||
),
|
||||
iso_dir=mock.Mock(
|
||||
side_effect=lambda arch, variant, symlink_to=None, relative=False: os.path.join(
|
||||
'' if relative else '/', 'iso_dir', arch, variant.uid
|
||||
)
|
||||
),
|
||||
iso_path=mock.Mock(
|
||||
side_effect=lambda arch, variant, filename, symlink_to: os.path.join(
|
||||
'/iso_dir', arch, variant.uid, filename
|
||||
)
|
||||
)
|
||||
),
|
||||
work=mock.Mock(
|
||||
image_build_conf=mock.Mock(
|
||||
side_effect=lambda variant, image_name, image_type:
|
||||
'-'.join([variant.uid, image_name, image_type])
|
||||
)
|
||||
),
|
||||
log=mock.Mock(
|
||||
log_file=mock.Mock(return_value='/a/b/log/log_file')
|
||||
)
|
||||
)
|
||||
self._logger = mock.Mock()
|
||||
self.variants = {
|
||||
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
'Client': mock.Mock(uid='Client', arches=['amd64'], is_empty=False),
|
||||
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
}
|
||||
self.log_error = mock.Mock()
|
||||
self.get_image_name = mock.Mock(return_value='image-name')
|
||||
self.image = mock.Mock(path='Client/i386/iso/image.iso')
|
||||
self.im = mock.Mock(images={'Client': {'i386': [self.image]}})
|
||||
|
||||
def get_variants(self, arch=None, types=None):
|
||||
return [v for v in self.variants.values() if not arch or arch in v.arches]
|
||||
|
||||
def can_fail(self, variant, arch, deliverable):
|
||||
failable = get_arch_variant_data(self.conf, 'failable_deliverables', arch, variant)
|
||||
return deliverable in failable
|
@ -11,62 +11,7 @@ import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.phases.image_build import ImageBuildPhase, CreateImageBuildThread
|
||||
from pungi.util import get_arch_variant_data
|
||||
|
||||
|
||||
class _DummyCompose(object):
|
||||
def __init__(self, config):
|
||||
self.compose_date = '20151203'
|
||||
self.compose_type_suffix = '.t'
|
||||
self.compose_respin = 0
|
||||
self.ci_base = mock.Mock(
|
||||
release_id='Test-1.0',
|
||||
release=mock.Mock(
|
||||
short='test',
|
||||
version='1.0',
|
||||
),
|
||||
)
|
||||
self.conf = config
|
||||
self.paths = mock.Mock(
|
||||
compose=mock.Mock(
|
||||
topdir=mock.Mock(return_value='/a/b'),
|
||||
os_tree=mock.Mock(
|
||||
side_effect=lambda arch, variant, create_dir=False: os.path.join('/ostree', arch, variant.uid)
|
||||
),
|
||||
image_dir=mock.Mock(
|
||||
side_effect=lambda variant, relative=False: os.path.join(
|
||||
'' if relative else '/', 'image_dir', variant.uid, '%(arch)s'
|
||||
)
|
||||
)
|
||||
),
|
||||
work=mock.Mock(
|
||||
image_build_conf=mock.Mock(
|
||||
side_effect=lambda variant, image_name, image_type:
|
||||
'-'.join([variant.uid, image_name, image_type])
|
||||
)
|
||||
),
|
||||
log=mock.Mock(
|
||||
log_file=mock.Mock(return_value='/a/b/log/log_file')
|
||||
)
|
||||
)
|
||||
self._logger = mock.Mock()
|
||||
self.variants = {
|
||||
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
'Client': mock.Mock(uid='Client', arches=['amd64'], is_empty=False),
|
||||
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
}
|
||||
self.im = mock.Mock()
|
||||
self.log_error = mock.Mock()
|
||||
|
||||
def get_arches(self):
|
||||
return ['x86_64', 'amd64']
|
||||
|
||||
def get_variants(self, arch=None, types=None):
|
||||
return [v for v in self.variants.values() if not arch or arch in v.arches]
|
||||
|
||||
def can_fail(self, variant, arch, deliverable):
|
||||
failable = get_arch_variant_data(self.conf, 'failable_deliverables', arch, variant)
|
||||
return deliverable in failable
|
||||
from tests.helpers import _DummyCompose
|
||||
|
||||
|
||||
class TestImageBuildPhase(unittest.TestCase):
|
||||
|
@ -12,32 +12,8 @@ import shutil
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.phases.image_checksum import (ImageChecksumPhase,
|
||||
dump_checksums)
|
||||
|
||||
|
||||
class _DummyCompose(object):
|
||||
def __init__(self, config):
|
||||
self.compose_date = '20151203'
|
||||
self.compose_type_suffix = '.t'
|
||||
self.compose_respin = 0
|
||||
self.ci_base = mock.Mock(
|
||||
release_id='Test-1.0',
|
||||
release=mock.Mock(
|
||||
short='test',
|
||||
version='1.0',
|
||||
),
|
||||
)
|
||||
self.conf = config
|
||||
self.paths = mock.Mock(
|
||||
compose=mock.Mock(
|
||||
topdir=mock.Mock(return_value='/a/b')
|
||||
)
|
||||
)
|
||||
self.image = mock.Mock(
|
||||
path='Client/i386/iso/image.iso',
|
||||
)
|
||||
self.im = mock.Mock(images={'Client': {'i386': [self.image]}})
|
||||
from pungi.phases.image_checksum import ImageChecksumPhase, dump_checksums
|
||||
from tests.helpers import _DummyCompose
|
||||
|
||||
|
||||
class TestImageChecksumPhase(unittest.TestCase):
|
||||
|
@ -11,55 +11,7 @@ import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.phases.live_images import LiveImagesPhase, CreateLiveImageThread
|
||||
from pungi.util import get_arch_variant_data
|
||||
|
||||
|
||||
class _DummyCompose(object):
|
||||
def __init__(self, config):
|
||||
self.compose_id = 'Test-20151203.0.t'
|
||||
self.compose_date = '20151203'
|
||||
self.compose_respin = '0'
|
||||
self.conf = config
|
||||
self.paths = mock.Mock(
|
||||
compose=mock.Mock(
|
||||
topdir=mock.Mock(return_value='/top'),
|
||||
repository=mock.Mock(
|
||||
side_effect=lambda arch, variant, create_dir=False: os.path.join('/repo', arch, variant.uid)
|
||||
),
|
||||
iso_dir=mock.Mock(
|
||||
side_effect=lambda arch, variant, symlink_to: os.path.join(
|
||||
'/top/iso_dir', arch, variant.uid
|
||||
)
|
||||
),
|
||||
image_dir=mock.Mock(
|
||||
side_effect=lambda variant, symlink_to: os.path.join(
|
||||
'/top/image_dir/%(arch)s', variant.uid
|
||||
)
|
||||
),
|
||||
),
|
||||
log=mock.Mock(
|
||||
log_file=mock.Mock(return_value='/a/b/log/log_file')
|
||||
)
|
||||
)
|
||||
self._logger = mock.Mock()
|
||||
self.variants = {
|
||||
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
'Client': mock.Mock(uid='Client', arches=['amd64'], is_empty=False),
|
||||
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
}
|
||||
self.log_error = mock.Mock()
|
||||
self.get_image_name = mock.Mock(return_value='image-name')
|
||||
self.im = mock.Mock()
|
||||
|
||||
def get_arches(self):
|
||||
return ['x86_64', 'amd64']
|
||||
|
||||
def get_variants(self, arch=None, types=None):
|
||||
return [v for v in self.variants.values() if not arch or arch in v.arches]
|
||||
|
||||
def can_fail(self, variant, arch, deliverable):
|
||||
failable = get_arch_variant_data(self.conf, 'failable_deliverables', arch, variant)
|
||||
return deliverable in failable
|
||||
from tests.helpers import _DummyCompose
|
||||
|
||||
|
||||
class TestLiveImagesPhase(unittest.TestCase):
|
||||
@ -90,7 +42,7 @@ class TestLiveImagesPhase(unittest.TestCase):
|
||||
[mock.call((compose,
|
||||
{'ks_file': 'test.ks',
|
||||
'build_arch': 'amd64',
|
||||
'dest_dir': '/top/iso_dir/amd64/Client',
|
||||
'dest_dir': '/iso_dir/amd64/Client',
|
||||
'scratch': False,
|
||||
'repos': ['/repo/amd64/Client',
|
||||
'http://example.com/repo/',
|
||||
@ -134,7 +86,7 @@ class TestLiveImagesPhase(unittest.TestCase):
|
||||
[mock.call((compose,
|
||||
{'ks_file': 'test.ks',
|
||||
'build_arch': 'amd64',
|
||||
'dest_dir': '/top/iso_dir/amd64/Client',
|
||||
'dest_dir': '/iso_dir/amd64/Client',
|
||||
'scratch': False,
|
||||
'repos': ['/repo/amd64/Client',
|
||||
'http://example.com/repo/',
|
||||
@ -180,7 +132,7 @@ class TestLiveImagesPhase(unittest.TestCase):
|
||||
[mock.call((compose,
|
||||
{'ks_file': 'test.ks',
|
||||
'build_arch': 'amd64',
|
||||
'dest_dir': '/top/iso_dir/amd64/Client',
|
||||
'dest_dir': '/iso_dir/amd64/Client',
|
||||
'scratch': False,
|
||||
'repos': ['/repo/amd64/Client',
|
||||
'http://example.com/repo/',
|
||||
@ -199,7 +151,7 @@ class TestLiveImagesPhase(unittest.TestCase):
|
||||
mock.call((compose,
|
||||
{'ks_file': 'another.ks',
|
||||
'build_arch': 'amd64',
|
||||
'dest_dir': '/top/iso_dir/amd64/Client',
|
||||
'dest_dir': '/iso_dir/amd64/Client',
|
||||
'scratch': False,
|
||||
'repos': ['/repo/amd64/Client',
|
||||
'http://example.com/repo/',
|
||||
@ -246,7 +198,7 @@ class TestLiveImagesPhase(unittest.TestCase):
|
||||
[mock.call((compose,
|
||||
{'ks_file': 'test.ks',
|
||||
'build_arch': 'amd64',
|
||||
'dest_dir': '/top/image_dir/amd64/Client',
|
||||
'dest_dir': '/image_dir/Client/amd64',
|
||||
'scratch': False,
|
||||
'repos': ['/repo/amd64/Client',
|
||||
'http://example.com/repo/',
|
||||
@ -335,7 +287,7 @@ class TestCreateLiveImageThread(unittest.TestCase):
|
||||
ksurl='https://git.example.com/kickstarts.git?#CAFEBABE')])
|
||||
self.assertEqual(Image.return_value.type, 'live')
|
||||
self.assertEqual(Image.return_value.format, 'iso')
|
||||
self.assertEqual(Image.return_value.path, 'iso_dir/amd64/Client/image-name')
|
||||
self.assertEqual(Image.return_value.path, '../../top/iso_dir/amd64/Client/image-name')
|
||||
self.assertEqual(Image.return_value.size, 1024)
|
||||
self.assertEqual(Image.return_value.mtime, 13579)
|
||||
self.assertEqual(Image.return_value.arch, 'amd64')
|
||||
@ -417,7 +369,7 @@ class TestCreateLiveImageThread(unittest.TestCase):
|
||||
|
||||
self.assertEqual(Image.return_value.type, 'live')
|
||||
self.assertEqual(Image.return_value.format, 'iso')
|
||||
self.assertEqual(Image.return_value.path, 'iso_dir/amd64/Client/image.iso')
|
||||
self.assertEqual(Image.return_value.path, '../../top/iso_dir/amd64/Client/image.iso')
|
||||
self.assertEqual(Image.return_value.size, 1024)
|
||||
self.assertEqual(Image.return_value.mtime, 13579)
|
||||
self.assertEqual(Image.return_value.arch, 'amd64')
|
||||
@ -495,7 +447,7 @@ class TestCreateLiveImageThread(unittest.TestCase):
|
||||
|
||||
self.assertEqual(Image.return_value.type, 'appliance')
|
||||
self.assertEqual(Image.return_value.format, 'raw.xz')
|
||||
self.assertEqual(Image.return_value.path, 'iso_dir/amd64/Client/image-name')
|
||||
self.assertEqual(Image.return_value.path, '../../top/iso_dir/amd64/Client/image-name')
|
||||
self.assertEqual(Image.return_value.size, 1024)
|
||||
self.assertEqual(Image.return_value.mtime, 13579)
|
||||
self.assertEqual(Image.return_value.arch, 'amd64')
|
||||
|
@ -10,56 +10,7 @@ import os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
from pungi.phases.livemedia_phase import LiveMediaPhase, LiveMediaThread
|
||||
from pungi.util import get_arch_variant_data
|
||||
|
||||
|
||||
class _DummyCompose(object):
|
||||
def __init__(self, config):
|
||||
self.compose_date = '20151203'
|
||||
self.compose_type_suffix = '.t'
|
||||
self.compose_respin = 0
|
||||
self.ci_base = mock.Mock(
|
||||
release_id='Test-1.0',
|
||||
release=mock.Mock(
|
||||
short='test',
|
||||
version='1.0',
|
||||
),
|
||||
)
|
||||
self.conf = config
|
||||
self.paths = mock.Mock(
|
||||
compose=mock.Mock(
|
||||
topdir=mock.Mock(return_value='/a/b'),
|
||||
os_tree=mock.Mock(
|
||||
side_effect=lambda arch, variant, create_dir=False: os.path.join('/ostree', arch, variant.uid)
|
||||
),
|
||||
repository=mock.Mock(
|
||||
side_effect=lambda arch, variant, create_dir=False: os.path.join('/repo', arch, variant.uid)
|
||||
),
|
||||
iso_dir=mock.Mock(
|
||||
side_effect=lambda arch, variant, relative=False: os.path.join(
|
||||
'' if relative else '/', 'iso_dir', variant.uid, arch
|
||||
)
|
||||
)
|
||||
),
|
||||
log=mock.Mock(
|
||||
log_file=mock.Mock(return_value='/a/b/log/log_file')
|
||||
)
|
||||
)
|
||||
self._logger = mock.Mock()
|
||||
self.variants = {
|
||||
'Server': mock.Mock(uid='Server', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
'Client': mock.Mock(uid='Client', arches=['amd64'], is_empty=False),
|
||||
'Everything': mock.Mock(uid='Everything', arches=['x86_64', 'amd64'], is_empty=False),
|
||||
}
|
||||
self.im = mock.Mock()
|
||||
self.log_error = mock.Mock()
|
||||
|
||||
def get_variants(self, arch=None, types=None):
|
||||
return [v for v in self.variants.values() if not arch or arch in v.arches]
|
||||
|
||||
def can_fail(self, variant, arch, deliverable):
|
||||
failable = get_arch_variant_data(self.conf, 'failable_deliverables', arch, variant)
|
||||
return deliverable in failable
|
||||
from tests.helpers import _DummyCompose
|
||||
|
||||
|
||||
class TestLiveMediaPhase(unittest.TestCase):
|
||||
@ -278,20 +229,20 @@ class TestCreateImageBuildThread(unittest.TestCase):
|
||||
self.assertEqual(get_image_paths.mock_calls,
|
||||
[mock.call(1234)])
|
||||
self.assertItemsEqual(makedirs.mock_calls,
|
||||
[mock.call('/iso_dir/Server/x86_64'),
|
||||
mock.call('/iso_dir/Server/amd64')])
|
||||
[mock.call('/iso_dir/x86_64/Server'),
|
||||
mock.call('/iso_dir/amd64/Server')])
|
||||
link = Linker.return_value.link
|
||||
self.assertItemsEqual(link.mock_calls,
|
||||
[mock.call('/koji/task/1235/Live-20160103.amd64.iso',
|
||||
'/iso_dir/Server/amd64/Live-20160103.amd64.iso',
|
||||
'/iso_dir/amd64/Server/Live-20160103.amd64.iso',
|
||||
link_type='hardlink-or-copy'),
|
||||
mock.call('/koji/task/1235/Live-20160103.x86_64.iso',
|
||||
'/iso_dir/Server/x86_64/Live-20160103.x86_64.iso',
|
||||
'/iso_dir/x86_64/Server/Live-20160103.x86_64.iso',
|
||||
link_type='hardlink-or-copy')])
|
||||
|
||||
image_relative_paths = [
|
||||
'iso_dir/Server/amd64/Live-20160103.amd64.iso',
|
||||
'iso_dir/Server/x86_64/Live-20160103.x86_64.iso'
|
||||
'iso_dir/amd64/Server/Live-20160103.amd64.iso',
|
||||
'iso_dir/x86_64/Server/Live-20160103.x86_64.iso'
|
||||
]
|
||||
|
||||
self.assertEqual(len(compose.im.add.call_args_list), 2)
|
||||
|
Loading…
Reference in New Issue
Block a user