From 35f048a5c2f4ebc0e167684a0c8ce2dcdf4c58e1 Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Wed, 9 Apr 2025 08:34:04 +0200
Subject: [PATCH] TEST: Removed tests which use the dropoffbox

---
 tests/test_file.py        | 209 +-------------------------------------
 tests/test_tickets.py     |  62 +++++------
 tests/test_tickets_200.py |  18 ++--
 3 files changed, 40 insertions(+), 249 deletions(-)

diff --git a/tests/test_file.py b/tests/test_file.py
index 77f01ea..36c9d99 100644
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -5,8 +5,8 @@
 #
 # Copyright (C) 2018 Research Group Biomedical Physics,
 # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
-# Copyright (C) 2019-2023 IndiScale GmbH (info@indiscale.com)
-# Copyright (C) 2019-2023 Daniel Hornung (d.hornung@indiscale.com)
+# Copyright (C) 2019,2023,2025 IndiScale GmbH (info@indiscale.com)
+# Copyright (C) 2019,2023,2025 Daniel Hornung (d.hornung@indiscale.com)
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -103,91 +103,6 @@ def test_file_with_space():
     qfile.download("test2.dat")
 
 
-# FIXME Can this test be removed? It seems to use the DropOffBox.
-@mark.local_server
-def test_pickup_file():
-    d = models.DropOffBox()
-    d.sync()
-    try:
-        pickup_file = open(os.path.join(d.path, "testpickup.dat"), "w")
-    except BaseException:
-        print("drop off box not on this system.")
-    else:
-        pickup_file.write("hello world\n")
-        pickup_file.close()
-        file_ = models.File(name="PickupTestfile",
-                            description="Pickup test file desc",
-                            path="testfiles/pickuptestfile.dat" +
-                            hex(randint(0, maxint)),
-                            pickup="testpickup.dat")
-        file_.insert()
-        assert_is_not_none(file_.id)
-
-
-# FIXME Can this test be removed? It seems to use the DropOffBox.
-@mark.local_server
-def test_pickup_folder():
-    # pickup_folder
-    d = models.DropOffBox()
-    d.sync()
-    try:
-        os.mkdir(d.path + "/testfolder")
-    except BaseException:
-        print("drop off box not on this system.")
-    else:
-        os.mkdir(d.path + "/testfolder/subfolder")
-        pickup_file = open(d.path + "/testfolder/testpickup1.dat", "w")
-        pickup_file.write("hello world\n")
-        pickup_file.close()
-        pickup_file = open(
-            d.path + "/testfolder/subfolder/testpickup2.dat", "w")
-        pickup_file.write("hello world\n")
-        pickup_file.close()
-
-        file_ = models.File(name="PickupTestfolder",
-                            description="Pickup test folder desc",
-                            path="testfiles/pickuptestfolder" +
-                            hex(randint(0, maxint)) + "/",
-                            pickup="testfolder/")
-        file_.insert()
-
-
-# FIXME Can this test be removed? It seems to use the DropOffBox.
-@mark.local_server
-def test_file4():
-    try:
-        d = models.DropOffBox()
-        d.sync()
-        try:
-            pickup_file = open(d.path + "/testpickup1.dat", "w")
-        except BaseException:
-            print("drop off box not on this system.")
-        else:
-            pickup_file.write("hello world\n")
-            pickup_file.close()
-            pickup_file = open(d.path + "/testpickup2.dat", "w")
-            pickup_file.write("hello world\n")
-            pickup_file.close()
-            file1_ = models.File(
-                name="Testfile1", description="Testfile Desc",
-                path="testfiles/testfile1.dat" + hex(randint(0, maxint)),
-                pickup="testpickup1.dat")
-            file2_ = models.File(
-                name="Testfile2", description="Testfile Desc",
-                path="testfiles/testfile1.dat" + hex(randint(0, maxint)),
-                pickup="testpickup2.dat")
-            c = models.Container()
-            c.extend([file1_, file2_])
-            c.insert()
-            assert_is_not_none(file1_.id)
-            assert_is_not_none(file2_.id)
-    finally:
-        try:
-            c.delete()
-        except BaseException:
-            pass
-
-
 def test_upload_complete_folder():
     file1_ = models.File(name="Testfile1",
                          description="Testfile Desc",
@@ -218,126 +133,6 @@ def test_upload_complete_folder():
     c.delete()
 
 
-# FIXME Can this test be removed? It seems to use the DropOffBox.
-def test_file6():
-    try:
-        # upload file to testfiles2/testfile...
-        upload_file = open("test.dat", "w")
-        upload_file.write("hello world\n")
-        upload_file.close()
-        file_ = models.File(name="Testfidb.dble",
-                            description="Testfile Desc",
-                            path="testfiles2/testfile" +
-                            hex(randint(0, maxint)) + ".dat",
-                            file="test.dat")
-        file_.insert()
-
-        assert file_.id is not None
-        assert file_.is_valid()
-
-        # pickup_folder
-        # and try to store it to testfiles2/
-        d = models.DropOffBox()
-        d.sync()
-        path = d.path + "/testfolder"
-
-        if not os.path.isdir(d.path):
-            print("drop off box not on this system.")
-        else:
-            os.mkdir(path)
-            pickup_file = open(path + "/testpickup1.dat", "w")
-            pickup_file.write("hello world\n")
-            pickup_file.close()
-            os.mkdir(path + "/subfolder")
-            pickup_file = open(path + "/subfolder/testpickup2.dat", "w")
-            pickup_file.write("hello world\n")
-            pickup_file.close()
-
-            folder_ = models.File(
-                name="PickupTestfolder",
-                description="Pickup test folder desc",
-                path="testfiles2/",
-                pickup="testfolder/")
-
-            with raises(TransactionError) as te:
-                folder_.insert()
-            cm = te.value.errors[0]
-            errors = cm.entity.get_errors()
-            assert errors[0].description == 'This target path does already exist.'
-    finally:
-        try:
-            folder_.delete()
-        except BaseException:
-            pass
-        try:
-            file_.delete()
-        except BaseException:
-            pass
-        try:
-            shutil.rmtree(path)
-        except BaseException:
-            pass
-
-
-# FIXME Can this test be removed? It seems to use the DropOffBox.
-def test_file7():
-    try:
-        # upload file to testfiles2/testsub/testfile...
-        upload_file = open("test.dat", "w")
-        upload_file.write("hello world\n")
-        upload_file.close()
-        file_ = models.File(name="Testfidb.dble",
-                            description="Testfile Desc",
-                            path="testfiles2/testsub/testfile" +
-                            hex(randint(0, maxint)) + ".dat",
-                            file="test.dat")
-        file_.insert()
-
-        assert_is_not_none(file_.id)
-        assert_true(file_.is_valid())
-
-        # pickup_folder
-        # and try to store it to testfiles2/
-        d = models.DropOffBox()
-        d.sync()
-        path = d.path + "/testfolder"
-
-        if not os.path.isdir(d.path):
-            print("drop off box not on this system.")
-        else:
-            os.mkdir(path)
-            pickup_file = open(path + "/testpickup1.dat", "w")
-            pickup_file.write("hello world\n")
-            pickup_file.close()
-            os.mkdir(path + "/subfolder")
-            pickup_file = open(path + "/subfolder/testpickup2.dat", "w")
-            pickup_file.write("hello world\n")
-            pickup_file.close()
-
-            folder_ = models.File(
-                name="PickupTestfolder",
-                description="Pickup test folder desc",
-                path="testfiles2/",
-                pickup="path")
-
-            with raises(TransactionError) as te:
-                folder_.insert()
-            assert te.value.has_error(EntityError)
-    finally:
-        try:
-            folder_.delete()
-        except BaseException:
-            pass
-        try:
-            file_.delete()
-        except BaseException:
-            pass
-        try:
-            shutil.rmtree(path)
-        except BaseException:
-            pass
-
-
 def test_consistency_file_was_modified():
     try:
 
diff --git a/tests/test_tickets.py b/tests/test_tickets.py
index fa3c6a8..c535ed7 100644
--- a/tests/test_tickets.py
+++ b/tests/test_tickets.py
@@ -5,6 +5,8 @@
 #
 # Copyright (C) 2018 Research Group Biomedical Physics,
 # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
+# Copyright (C) 2025 Indiscale GmbH <info@indiscale.com>
+# Copyright (C) 2025 Daniel Hornung <d.hornung@indiscale.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -25,9 +27,11 @@
 
 @author: tf
 """
-import caosdb as db
-from caosdb.exceptions import (CaosDBException,
-                               TransactionError, UniqueNamesError)
+
+import tempfile
+import linkahead as db
+from linkahead.exceptions import (LinkAheadException,
+                                  TransactionError, UniqueNamesError)
 import pytest
 from tests import test_misc
 
@@ -466,44 +470,34 @@ def test_ticket_137():
         rt1.insert()
 
 
-# FIXME Can this test be removed? It seems to use the DropOffBox.
-@pytest.mark.skip
-def test_ticket_39():
+# Test remodeled after removal of dropoffbox.
+def test_ticket_39(tmp_path):
+    """Testing file upload of unreadable files."""
     import os
 
-    scratch = os.path.realpath(db.get_config().get(
-        "EndToEndTests", "test_tickets.test_ticket_39.scratch"))
-    assert os.path.isdir(scratch)
-    testfile = os.path.join(scratch, "test.dat")
-    try:
-        # insert RecordType
+    # scratch = os.path.realpath(db.get_config().get(
+    #     "EndToEndTests", "test_tickets.test_ticket_39.scratch"))
+    # assert os.path.isdir(scratch)
 
-        upload_file = open(testfile, "w")
+    testfile_ok = tmp_path / "test.dat"
+    with open(testfile_ok, encoding="utf-8", mode="w") as upload_file:
         upload_file.write("hello world\n")
-        upload_file.close()
-        # check if the server can connect to this filesystem
 
-        f = db.File(path="testfiles/file1", pickup=testfile).insert()
-        assert f.is_valid()
-        f.delete()
+    # check if the server can connect to this filesystem
+    f = db.File(path="testfiles/file1", file=str(testfile_ok)).insert()
+    assert f.is_valid()
+    f.delete()
 
-        # make unreadable
-        os.chmod(testfile, 0o000)
-        with pytest.raises(TransactionError) as te:
-            f = db.File(
-                path="testfiles/file1", pickup=testfile).insert()
-        e = te.value.errors[0]
-        assert e.msg == "Insufficient read permission for this file. Please make it readable."
+    # make unreadable file
+    testfile_no_access = tmp_path / "test2.dat"
+    with open(testfile_no_access, encoding="utf-8", mode="w") as upload_file:
+        upload_file.write("hello world\n")
+    os.chmod(testfile_no_access, 0o000)
 
-    finally:
-        os.chmod(testfile, 0o600)
+    with pytest.raises(PermissionError) as pytest_pe:
+        db.File(path="testfiles/file2", file=str(testfile_no_access)).insert()
 
-        if len(db.execute_query("FIND ENTITY RT1")) > 0:
-            rt1.delete()
-        try:
-            os.remove(testfile)
-        except Exception as e:
-            print(e)
+    assert pytest_pe.value.filename.endswith("test2.dat")
 
 
 def test_ticket_128():
@@ -1216,7 +1210,7 @@ def test_ticket_104():
         _basepath = _fullurl.path
 
         wrongbasepath = _fullurl.scheme + "://" + _netloc + "/wrongcontextroot/"
-        with pytest.raises(CaosDBException):
+        with pytest.raises(LinkAheadException):
             db.configure_connection(url=wrongbasepath)._login()
     finally:
         db.configure_connection()
diff --git a/tests/test_tickets_200.py b/tests/test_tickets_200.py
index 3dfcef0..ac9dc25 100644
--- a/tests/test_tickets_200.py
+++ b/tests/test_tickets_200.py
@@ -5,6 +5,8 @@
 #
 # Copyright (C) 2018 Research Group Biomedical Physics,
 # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
+# Copyright (C) 2025 Indiscale GmbH <info@indiscale.com>
+# Copyright (C) 2025 Daniel Hornung <d.hornung@indiscale.com>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as
@@ -174,25 +176,25 @@ def test_ticket_221():
     assert repr(RT2) == '<RecordType name="TestRT2">\n  <Property name="test_property_with_RT1" datatype="TestRT1" importance="RECOMMENDED" flag="inheritance:FIX"/>\n</RecordType>\n'
 
 
-# FIXME Can this test be removed? It seems to use the DropOffBox. Otherwise replace 'pickup'.
+# Test remodeled after removal of dropoffbox (and `pickup` parameter)
 def test_ticket_237():
 
     f1 = h.File(
         name="name1",
         path="path1",
-        pickup="pickup1",
+        # pickup="pickup1",
         file="file1",
         thumbnail="thumbnail1")
     assert f1.name == "name1"
     assert f1.path == "path1"
-    assert f1.pickup == "pickup1"
+    # assert f1.pickup == "pickup1"
     assert f1.file == "file1"
     assert f1.thumbnail == "thumbnail1"
 
     f2 = h.File(name="name2")
     assert f2.name == "name2"
     assert f2.path is None
-    assert f2.pickup is None
+    # assert f2.pickup is None
     assert f2.file is None
     assert f2.thumbnail is None
 
@@ -200,24 +202,24 @@ def test_ticket_237():
 
     assert f2.name == "name2"
     assert f2.path == "path1"
-    assert f2.pickup == "pickup1"
+    # assert f2.pickup == "pickup1"
     assert f2.file == "file1"
     assert f2.thumbnail == "thumbnail1"
 
     f2.path = "path2"
-    f2.pickup = "pickup2"
+    # f2.pickup = "pickup2"
     f2.file = "file2"
     f2.thumbnail = "thumbnail2"
 
     assert f2.name == "name2"
     assert f2.path == "path2"
-    assert f2.pickup == "pickup2"
+    # assert f2.pickup == "pickup2"
     assert f2.file == "file2"
     assert f2.thumbnail == "thumbnail2"
 
     assert f1.name == "name1"
     assert f1.path == "path1"
-    assert f1.pickup == "pickup1"
+    # assert f1.pickup == "pickup1"
     assert f1.file == "file1"
     assert f1.thumbnail == "thumbnail1"
 
-- 
GitLab