Skip to content
Snippets Groups Projects

WS-796: tests for delivery of initial_weblog with final standard calibration

Merged Janet Goldstein requested to merge WS-796-verify-download-weblogs into main
1 unresolved thread
1 file
+ 119
0
Compare changes
  • Side-by-side
  • Inline
#
# Copyright (C) 2021 Associated Universities, Inc. Washington DC, USA.
#
# This file is part of NRAO Workspaces.
#
# Workspaces is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Workspaces is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
"""Tests for delivery standard calibration products"""
import pathlib
from unittest.mock import patch
# pylint: disable=C0103, R0903, W0511
Please register or sign in to reply
from _pytest.tmpdir import TempdirFactory
from delivery.context import DeliveryContext
from delivery.delivery import Delivery
WEBLOG_FILENAME = "weblog.tgz"
INIT_WEBLOG_FILENAME = "initial_weblog.tgz"
SDM_NAME = "17A-109.sb33151331.eb33786546.57892.65940042824"
# TODO Some Fine Day: consolidate duplicate code
def test_no_init_weblog_in_first_cal(resource_path_root, tmpdir_factory: TempdirFactory, capsys):
"""
If there is just one version of a standard calibration,
weblog.tgz should be delivered, but not initial_weblog.tgz.
:return:
"""
temp_directory = pathlib.Path(tmpdir_factory.mktemp("test_no_init_weblog_in_first_cal"))
assert temp_directory.is_dir()
test_data_path = resource_path_root / "724126739_with_tmp"
assert test_data_path.is_dir()
top_dir = test_data_path / SDM_NAME
assert top_dir.is_dir()
working_dir = top_dir / "working"
assert working_dir.is_dir()
weblog = working_dir / WEBLOG_FILENAME
try:
weblog.touch()
test_context = DeliveryContext.parse_commandline(["-r", str(test_data_path)])
with patch("delivery.destinations.sharedweb.CapoConfig") as mocked_capo_config:
mocked_capo_config.return_value.settings.return_value.downloadDirectory = str(temp_directory)
mocked_capo_config.return_value.settings.return_value.downloadUrl = "http://testing"
assert str(temp_directory) == mocked_capo_config().settings().downloadDirectory
results = Delivery().deliver(test_context)
actual_delivery_dir = pathlib.Path(results["delivered_to"])
top_dir = actual_delivery_dir / SDM_NAME
working_dir = top_dir / "working"
wl = working_dir / WEBLOG_FILENAME
assert wl.exists()
il = working_dir / INIT_WEBLOG_FILENAME
assert not il.exists()
finally:
weblog.unlink()
capsys.readouterr()
def test_both_weblogs_in_final_cal(resource_path_root, tmpdir_factory: TempdirFactory, capsys):
"""
If there is just one version of a standard calibration,
weblog.tgz -and- initial_weblog.tgz should be delivered.
:return:
"""
temp_directory = pathlib.Path(tmpdir_factory.mktemp("test_init_weblog_in_final_cal"))
assert temp_directory.is_dir()
test_data_path = resource_path_root / "724126739_with_tmp"
assert test_data_path.is_dir()
top_dir = test_data_path / SDM_NAME
assert top_dir.is_dir()
working_dir = top_dir / "working"
assert working_dir.is_dir()
weblog = working_dir / WEBLOG_FILENAME
init_weblog = working_dir / INIT_WEBLOG_FILENAME
try:
weblog.touch()
init_weblog.touch()
test_context = DeliveryContext.parse_commandline(["-r", str(test_data_path)])
with patch("delivery.destinations.sharedweb.CapoConfig") as mocked_capo_config:
mocked_capo_config.return_value.settings.return_value.downloadDirectory = str(temp_directory)
mocked_capo_config.return_value.settings.return_value.downloadUrl = "http://testing"
assert str(temp_directory) == mocked_capo_config().settings().downloadDirectory
results = Delivery().deliver(test_context)
actual_delivery_dir = pathlib.Path(results["delivered_to"])
top_dir = actual_delivery_dir / SDM_NAME
working_dir = top_dir / "working"
wl = working_dir / WEBLOG_FILENAME
assert wl.exists()
il = working_dir / INIT_WEBLOG_FILENAME
assert il.exists()
finally:
weblog.unlink()
init_weblog.unlink()
capsys.readouterr()
Loading