Skip to content
Snippets Groups Projects
Commit 5588ceb5 authored by ml bonhomme's avatar ml bonhomme :bee: Committed by Erwan Rouchet
Browse files

Do not publish downloaded files as artifacts

parent 0c6c91bd
No related branches found
No related tags found
1 merge request!362Do not publish downloaded files as artifacts
Pipeline #137552 passed
......@@ -79,10 +79,11 @@ class ProcessTask(object):
return ProcessMode(self.process["mode"])
def download_files(self):
temp_path = tempfile.mkdtemp()
files = []
for datafile_id in self.process["files"]:
df = default_client.request("RetrieveDataFile", id=datafile_id)
path = get_working_dir() / datafile_id
path = Path(temp_path) / datafile_id
logger.info("Downloading file {} ({})".format(df["name"], df["id"]))
try:
......
# -*- coding: utf-8 -*-
import json
import shutil
import tempfile
from argparse import Namespace
from io import BufferedReader
from pathlib import Path
......@@ -24,6 +26,12 @@ SAMPLES = Path(__file__).absolute().parent / "samples"
)
@requests_mock.Mocker()
class TestProcess(TestCase):
def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(Path(self.tmp_dir))
def test_not_found(self, args_mock, parser_mock, req_mock):
process_id = uuid4()
req_mock.get(
......@@ -125,7 +133,8 @@ class TestProcess(TestCase):
main()
self.assertEqual(default_client.sleep_duration, 0.01)
def test_run(self, args_mock, parser_mock, req_mock):
@patch("arkindex_tasks.base.tempfile")
def test_run(self, req_mock, temp_mock, args_mock, parser_mock):
process_id = uuid4()
req_mock.get(
"/api/v1/process/{}/".format(process_id),
......@@ -165,6 +174,7 @@ class TestProcess(TestCase):
req_mock.delete("/api/v1/process/file/file1/", status_code=204)
req_mock.delete("/api/v1/process/file/file2/", status_code=204)
temp_mock.mkdtemp.return_value = self.tmp_dir
args_mock().parse_args.return_value = Namespace(
process_id=process_id,
sleep=0,
......@@ -183,7 +193,7 @@ class TestProcess(TestCase):
args, kwargs = call1
self.assertEqual(len(args), 1)
self.assertIsInstance(args[0], BufferedReader)
self.assertEqual(args[0].name, str(get_working_dir() / "file1"))
self.assertEqual(args[0].name, str(Path(self.tmp_dir) / "file1"))
self.assertDictEqual(
kwargs,
{
......@@ -195,7 +205,7 @@ class TestProcess(TestCase):
args, kwargs = call2
self.assertEqual(len(args), 1)
self.assertIsInstance(args[0], BufferedReader)
self.assertEqual(args[0].name, str(get_working_dir() / "file2"))
self.assertEqual(args[0].name, str(Path(self.tmp_dir) / "file2"))
self.assertDictEqual(
kwargs,
{
......
# -*- coding: utf-8 -*-
import shutil
import tempfile
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
......@@ -12,6 +14,12 @@ SAMPLES = Path(__file__).absolute().parent / "samples"
@patch("arkindex_tasks.utils.download_file.retry.wait.wait_fixed", new=0)
class TestBase(TestCase):
def setUp(self):
self.tmp_dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(Path(self.tmp_dir))
def test_default_working_dir(self):
arkindex_tasks.base._working_dir = None
try:
......@@ -44,13 +52,16 @@ class TestBase(TestCase):
self.assertDictEqual(task.process, {"id": "processid"})
@requests_mock.Mocker()
def test_download_files(self, mock):
@patch("arkindex_tasks.base.tempfile")
def test_download_files(self, mock, temp_mock):
mock.get(
"/api/v1/process/file/file1/",
json={"id": "file1", "name": "img1.jpg", "s3_url": "http://s3/img1.jpg"},
)
mock.get("http://s3/img1.jpg", body=open(SAMPLES / "img1.jpg", "rb"))
temp_mock.mkdtemp.return_value = self.tmp_dir
task = arkindex_tasks.base.ProcessTask("processid")
task.process = {"id": "processid", "files": ["file1"]}
......@@ -62,12 +73,12 @@ class TestBase(TestCase):
"id": "file1",
"name": "img1.jpg",
"s3_url": "http://s3/img1.jpg",
"local_path": arkindex_tasks.base.get_working_dir() / "file1",
"local_path": Path(self.tmp_dir) / "file1",
}
],
)
self.assertTrue((arkindex_tasks.base.get_working_dir() / "file1").is_file())
self.assertTrue((Path(self.tmp_dir) / "file1").is_file())
self.assertEqual(mock.call_count, 2)
@requests_mock.Mocker()
......
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