Skip to content
Snippets Groups Projects
Commit 5cd5058c authored by Nathan Hertz's avatar Nathan Hertz Committed by Daniel Lyons
Browse files

Delivery web root tests now pass; CAPO-specified web root delivery is working

parent 5b289464
No related branches found
No related tags found
1 merge request!143WS-51: Fix web-root delivery
Pipeline #1026 passed
......@@ -9,8 +9,8 @@ import secrets
from pycapo import CapoConfig
from .deliverer import Destination, DestinationBuilder, DeliveryContextIF
from .finder import ProductFinder, HeuristicProductFinder
from .deliverer import DeliveryContextIF, Destination, DestinationBuilder
from .finder import HeuristicProductFinder, ProductFinder
class DeliveryContext(DeliveryContextIF):
......
......@@ -92,7 +92,9 @@ class TarDecorator(DestinationDecorator):
# I beleive this gives us the request id, but I may be wrong
# I also assume that request id is what we want, may not be true
tar_name = os.path.basename(os.path.normpath(self.context.source))
shutil.make_archive(self.underlying.path + "/" + tar_name, "gztar", self.underlying.path)
shutil.make_archive(
str(self.underlying.path) + "/" + tar_name, "gztar", self.underlying.path
)
# clear out the directory, leaving the tar
for filename in os.listdir(self.underlying.path):
file_path = os.path.join(self.underlying.path, filename)
......
......@@ -3,9 +3,10 @@ import filecmp
import os
import shutil
import tarfile
from unittest.mock import patch
import delivery.delivery
import pytest
from delivery.context import DeliveryContext
from delivery.delivery import Delivery, main
def test_local_rawdata_no_tar(tmpdir_factory):
......@@ -16,7 +17,7 @@ def test_local_rawdata_no_tar(tmpdir_factory):
temp_directory = str(tmpdir_factory.mktemp("test_basic_rawdata_no_tar"))
test_data_path = "../../../../shared/workspaces/test/test_data/spool/724126739/"
eb_name = "17A-109.sb33151331.eb33786546.57892.65940042824"
delivery.delivery.main(["-r", "-l", temp_directory, test_data_path])
main(["-r", "-l", temp_directory, test_data_path])
# compare the source and destination
compare_dirs = filecmp.dircmp(
temp_directory + "/" + eb_name, (test_data_path + eb_name + "/rawdata/" + eb_name)
......@@ -32,7 +33,7 @@ def test_local_rawdata_no_tar(tmpdir_factory):
def test_local_rawdata_with_tar(tmpdir_factory):
temp_directory = str(tmpdir_factory.mktemp("test_basic_rawdata_with_tar"))
test_data_path = "../../../../shared/workspaces/test/test_data/spool/724126739/"
delivery.delivery.main(["-r", "-t", "-l", temp_directory, test_data_path])
main(["-r", "-t", "-l", temp_directory, test_data_path])
eb_name = "17A-109.sb33151331.eb33786546.57892.65940042824"
tar_path = temp_directory + "/724126739.tar.gz"
# does a tar exist where we think
......@@ -57,19 +58,22 @@ def test_local_rawdata_with_tar(tmpdir_factory):
)
@pytest.mark.skip(reason="Test needs more dev time")
# @pytest.mark.skip(reason="Test needs more dev time")
def test_web_rawdata_no_tar(tmpdir_factory):
"""
Test that a directory in the source is copied to a directory in the destination in the manner expected.
:return:
"""
temp_directory = str(tmpdir_factory.mktemp("test_basic_rawdata_no_tar"))
temp_directory = str(tmpdir_factory.mktemp("test_web_rawdata_no_tar"))
test_data_path = "../../../../shared/workspaces/test/test_data/spool/724126739/"
eb_name = "17A-109.sb33151331.eb33786546.57892.65940042824"
delivery.delivery.main(["-r", test_data_path])
test_context = DeliveryContext.parse_commandline(["-r", test_data_path])
with patch("delivery.context.CapoConfig.settings") as mocked_capo_settings:
mocked_capo_settings.return_value.nraoDownloadDirectory = temp_directory
assert temp_directory == mocked_capo_settings().nraoDownloadDirectory
destination_path = Delivery().deliver(test_context)
# compare the source and destination
compare_dirs = filecmp.dircmp(
temp_directory + "/" + eb_name, (test_data_path + eb_name + "/rawdata/" + eb_name)
destination_path / eb_name, f"{test_data_path}{eb_name}/rawdata/{eb_name}"
)
# did the comparison report they are the same
assert (
......@@ -79,13 +83,16 @@ def test_web_rawdata_no_tar(tmpdir_factory):
)
@pytest.mark.skip(reason="Test needs more dev time")
def test_web_rawdata_with_tar(tmpdir_factory):
temp_directory = str(tmpdir_factory.mktemp("test_basic_rawdata_with_tar"))
temp_directory = str(tmpdir_factory.mktemp("test_web_rawdata_with_tar"))
test_data_path = "../../../../shared/workspaces/test/test_data/spool/724126739/"
delivery.delivery.main(["-r", "-t", test_data_path])
test_context = DeliveryContext.parse_commandline(["-r", "-t", test_data_path])
with patch("delivery.context.CapoConfig.settings") as mocked_capo_settings:
mocked_capo_settings.return_value.nraoDownloadDirectory = temp_directory
assert temp_directory == mocked_capo_settings().nraoDownloadDirectory
destination_path = Delivery().deliver(test_context)
eb_name = "17A-109.sb33151331.eb33786546.57892.65940042824"
tar_path = temp_directory + "/724126739.tar.gz"
tar_path = destination_path / "724126739.tar.gz"
# does a tar exist where we think
assert os.path.exists(tar_path)
# is it the only thing there (did cleanup work)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment