From 7085f19f899634a0a9b29e35899197c24a411e02 Mon Sep 17 00:00:00 2001 From: Janet Goldstein <jgoldste@nrao.edu> Date: Tue, 23 Nov 2021 12:00:29 -0500 Subject: [PATCH] WS-796: tests for delivery of initial_weblog with final standard calibration --- .../pexable/deliver/test/test_final_cal.py | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 apps/cli/executables/pexable/deliver/test/test_final_cal.py diff --git a/apps/cli/executables/pexable/deliver/test/test_final_cal.py b/apps/cli/executables/pexable/deliver/test/test_final_cal.py new file mode 100644 index 000000000..2baa115f6 --- /dev/null +++ b/apps/cli/executables/pexable/deliver/test/test_final_cal.py @@ -0,0 +1,119 @@ +# +# 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""" + +# pylint: disable=C0103, R0903, W0511 + +import pathlib +from unittest.mock import patch + +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() -- GitLab