def test_Region_sync_custom_image_not_synced_uses_progress_bar(tmpdir, monkeypatch):
"""Test Region.sync_custom performs create and handles when its already
synced."""
region = make_Region(quiet=False)
mock_progress_bar = MagicMock()
mock_progress_bar.signal_set = True
mock_progress_bar_class = MagicMock()
mock_progress_bar_class.return_value = mock_progress_bar
mock_progress_bar.term_width = 80
monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
monkeypatch.setattr(region_module, "ProgressBar", mock_progress_bar_class)
mock_signal = Mock()
monkeypatch.setattr(signal, "signal", mock_signal)
image_path = tmpdir.join("image.tar.gz")
image_path.write(b"data")
def fake_create( # pylint: disable=too-many-arguments,unused-argument
name, arch, stream, title=None, filetype=None,
progress_callback=None):
"""Fakes the create method.
Calls progress_callback twice with 0% then 100%.
"""
progress_callback(0)
progress_callback(1)
# Call fake_create instead of the mock.
region.origin.BootResources.create.side_effect = fake_create
region.sync_custom("image", {
"path": str(image_path),
"architecture": "amd64/generic",
"title": "My Title",
})
assert mock_progress_bar.start.called is True
assert [call(0), call(1)] == mock_progress_bar.update.call_args_list
assert call(signal.SIGWINCH, signal.SIG_DFL) == mock_signal.call_args
assert (
call(
"custom/image uploaded", level=MessageLevel.SUCCESS,
replace=True, fill=80) ==
region.print_msg.call_args)
评论列表
文章目录