Пример #1
0
def task_files_download(task_id, user):
    namespace = user.current_account.namespace
    slave_ip, sandbox_directory = get_task_data(f"{namespace}_{task_id}")
    if not slave_ip:
        return Response(response=json.dumps({}), status=404)

    offset = request.args.get("offset", 0)
    length = request.args.get("length", 1024)
    path = request.args.get("path", "")
    file_final_url = (
        f"http://{slave_ip}:5051/files/download?path={sandbox_directory}{path}"
    )
    download_id = uuid4().hex
    cache.set(
        f"downloads/{download_id}",
        {"file_url": file_final_url, "task_id": task_id, "file_path": path},
        timeout=30,
    )
    download_id_url = url_for(
        "hollowman.api.tasks.download_by_id", download_id=download_id
    )
    return Response(
        response=json.dumps({"download_url": download_id_url.strip("/")}),
        status=HTTPStatus.OK,
    )
Пример #2
0
 def test_set_calls_backend_set_method(self):
     with mock.patch.object(cache, "__cache_backend") as cache_backend_mock:
         cache_backend_mock.set.return_value = True
         self.assertTrue(cache.set("my-key", "my-value", timeout=30))
         cache_backend_mock.set.assert_called_with("my-key",
                                                   "my-value",
                                                   timeout=30)
Пример #3
0
 def test_set_with_offline_cache_check_logger(self):
     self.assertFalse(cache.set("my-key", 10))
     self.assertEqual(self.logger_mock.error.call_count, 1)
     self.logger_mock.error.assert_called_with({
         "action":
         "cache-set",
         "state":
         "error",
         "key":
         "my-key",
         "cache-backend":
         "redis://127.0.0.1:6379/0",
     })
Пример #4
0
 def test_set_with_offline_cache_returns_False(self):
     self.assertFalse(cache.set("my-key", "my-value"))