diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 975eae8f22ff68e358edff4e36edc9046b3b3d36..9c03b2d97a56b0c6927e1f1f52f571beea52e54b 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -24,6 +24,7 @@ RUN rm -r /git/.git # Install pylinkahead.ini for the tests RUN mv /git/.docker/tester_pylinkahead.ini /git/pylinkahead.ini +RUN useradd user WORKDIR /git # wait for server, @@ -34,5 +35,9 @@ CMD /wait-for-it.sh caosdb-server:10443 -t 500 -- \ # ... put out general version information python3 --version && \ python3 -c "import linkahead; print(linkahead.version.version)" && \ + chown -R user /authtoken && \ + mkdir -p /extroot && \ + chown -R user /extroot && \ + chown -R user /git && \ # ... and run tests - pytest --cov=linkahead -vv tests + su user -c "pytest --cov=linkahead -vv tests" diff --git a/CHANGELOG.md b/CHANGELOG.md index e75607c919fdc7fdb7ce91c8c321b391e1637d06..fa682b9e5f9a7f01ca96a837dceed60e399d06fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Some redundant tests from `test_tickets.py` that checked functionality that was already tested in `test_error_stuff.py`. - `test_server_side_scripting.bin_dir.local` option in pylinkahead.ini +- Dropoffbox tests. ### Fixed (for any bug fixes) diff --git a/tests/test_file.py b/tests/test_file.py index af0349fe1af6ffc6134f71b45c82c2813fa65551..36c9d99f04eac272c4647cc3488bb0579a1613cb 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,88 +103,6 @@ def test_file_with_space(): qfile.download("test2.dat") -@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) - - -@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() - - -@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", @@ -215,124 +133,6 @@ def test_upload_complete_folder(): c.delete() -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 - - -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_tenpoints.py b/tests/test_tenpoints.py index e23aabed074c407ece6bfa34d9b74186f8aedf15..781f2933791fb1a3eeba1baaeadab77bbb4fbf61 100644 --- a/tests/test_tenpoints.py +++ b/tests/test_tenpoints.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- # # ** header v3.0 -# This file is a part of the CaosDB Project. +# This file is a part of the LinkAhead Project. # # Copyright (C) 2018 Research Group Biomedical Physics, # Max-Planck-Institute for Dynamics and Self-Organization Göttingen +# Copyright (C) 2024 IndiScale GmbH +# Copyright (C) 2024 Daniel Hornung # # 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,9 @@ @author: fitschen """ -import caosdb as h +import linkahead as db import os -from caosdb.exceptions import CaosDBException +from linkahead.exceptions import LinkAheadException '''1) Struktur: @@ -44,7 +46,7 @@ RecordTypes / Properties 2) Daten: 2.1 Einfügen von Datensätzen unter Benutzung der oben angelegten RecordTypes -2.2 Hochladen von Dateien über HTTP und DropOffBox und Verknüpfung mit den +2.2 Hochladen von Dateien über HTTP und Verknüpfung mit den Datensätzen 2.3 Verwendung von Einheiten 2.4 Nachtägliches Annotieren von Datensätzen, z.B. hinzufügen einer @@ -53,7 +55,7 @@ Description oder einer Zahl''' def setup_function(function): try: - h.execute_query("FIND ENTITY *").delete() + db.execute_query("FIND ENTITY *").delete() except Exception as e: print(e) @@ -68,30 +70,30 @@ def test_tenpoints1_1(): enthalten (Gewicht, Beschreibung, Identifkationsnummern, etc.) ''' - c = h.Container() + c = db.Container() c.append( - h.Property( + db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text')) c.append( - h.Property( + db.Property( name="SimpleDoubleProperty", description="simple double property (from test_tenpoints.py)", datatype='double')) c.append( - h.Property( + db.Property( name="SimpleIntegerProperty", description="simple integer property (from test_tenpoints.py)", datatype='integer')) c.append( - h.Property( + db.Property( name="SimpleDatetimeProperty", description="simple datetime property (from test_tenpoints.py)", datatype='datetime')) c.append( - h.RecordType( + db.RecordType( name="SimpleRecordType", description="simple recordType (from test_tenpoints.py)") .add_property( name='SimpleTextProperty') .add_property( @@ -106,35 +108,35 @@ def test_tenpoints1_2(): ''' 1.2 Einfügen von RecordTypes, die zusätzlich Dateien referenzieren ''' - c = h.Container() + c = db.Container() c.append( - h.Property( + db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text')) c.append( - h.Property( + db.Property( name="SimpleDoubleProperty", description="simple double property (from test_tenpoints.py)", datatype='double')) c.append( - h.Property( + db.Property( name="SimpleIntegerProperty", description="simple integer property (from test_tenpoints.py)", datatype='integer')) c.append( - h.Property( + db.Property( name="SimpleDatetimeProperty", description="simple datetime property (from test_tenpoints.py)", datatype='datetime')) c.append( - h.Property( + db.Property( name="SimpleFileProperty", description="simple file property (from test_tenpoints.py)", datatype='file')) c.append( - h.RecordType( + db.RecordType( name="SimpleRecordType", description="simple recordType (from test_tenpoints.py)") .add_property( name='SimpleTextProperty') .add_property( @@ -152,35 +154,35 @@ def test_tenpoints1_3(): andere RecordTypes enthalten ''' - c = h.Container() + c = db.Container() c.append( - h.Property( + db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text')) c.append( - h.Property( + db.Property( name="SimpleDoubleProperty", description="simple double property (from test_tenpoints.py)", datatype='double')) c.append( - h.Property( + db.Property( name="SimpleIntegerProperty", description="simple integer property (from test_tenpoints.py)", datatype='integer')) c.append( - h.Property( + db.Property( name="SimpleDatetimeProperty", description="simple datetime property (from test_tenpoints.py)", datatype='datetime')) c.append( - h.Property( + db.Property( name="SimpleFileProperty", description="simple file property (from test_tenpoints.py)", datatype='file')) c.append( - h.RecordType( + db.RecordType( name="SimpleRecordType", description="simple recordType (from test_tenpoints.py)") .add_property( name='SimpleTextProperty') .add_property( @@ -190,11 +192,12 @@ def test_tenpoints1_3(): name='SimpleFileProperty')) c.append( - h.Property( + db.Property( name="ReferenceProperty", description='reference property (from test_tenpoints.py)', datatype="SimpleRecordType")) - c.append(h.RecordType(name="ComlexRecordType", description="complex recordType with references (from test_tenpoints.py)") + c.append(db.RecordType(name="ComlexRecordType", + description="complex recordType with references (from test_tenpoints)") .add_property(name='ReferenceProperty') # first method # second method, doesn't need the ReferenceProperty .add_property(name='SimpleRecordType') @@ -218,37 +221,37 @@ def test_tenpoints1_5(): RecordTypes / Properties ''' - c = h.Container() + c = db.Container() c.append( - h.Property( + db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text')) c.append( - h.Property( + db.Property( name="SimpleDoubleProperty", description="simple double property (from test_tenpoints.py)", datatype='double')) c.append( - h.Property( + db.Property( name="SimpleIntegerProperty", description="simple integer property (from test_tenpoints.py)", datatype='integer')) c.append( - h.Property( + db.Property( name="SimpleDatetimeProperty", description="simple datetime property (from test_tenpoints.py)", datatype='datetime')) c.append( - h.Property( + db.Property( name="SimpleFileProperty", description="simple file property (from test_tenpoints.py)", datatype='file')) c.insert() - d = h.Container() + d = db.Container() d.append( - h.RecordType( + db.RecordType( name="SimpleRecordType", description="simple recordType (from test_tenpoints.py)") .add_property( name='SimpleTextProperty') .add_property( @@ -258,11 +261,11 @@ def test_tenpoints1_5(): name='SimpleFileProperty')) d.append( - h.Property( + db.Property( name="ReferenceProperty", description='reference property (from test_tenpoints.py)', datatype="SimpleRecordType")) - d.append(h.RecordType(name="ComplexRecordType", description="complex recordType with references (from test_tenpoints.py)") + d.append(db.RecordType(name="ComplexRecordType", description="complex recordType with references (from test_tenpoints.py)") .add_property(name='ReferenceProperty') # first method # second method, doesn't need the ReferenceProperty .add_property(name='SimpleRecordType') @@ -270,7 +273,7 @@ def test_tenpoints1_5(): d.insert() - sr = (h.Record().add_parent(name="SimpleRecordType") + sr = (db.Record().add_parent(name="SimpleRecordType") .add_property(name="SimpleTextProperty", value="Some Text") .add_property(name="SimpleDoubleProperty", value=3.14) .add_property(name="SimpleIntegerProperty", value=1337) @@ -278,12 +281,12 @@ def test_tenpoints1_5(): sr.insert() - cr1 = (h.Record().add_parent(name="ComplexRecordType") + cr1 = (db.Record().add_parent(name="ComplexRecordType") .add_property(name="ReferenceProperty", value=sr)) cr1.insert() - cr2 = (h.Record().add_parent(name="ComplexRecordType") + cr2 = (db.Record().add_parent(name="ComplexRecordType") .add_property(name="SimpleRecordType", value=sr)) cr2.insert() @@ -292,41 +295,41 @@ def test_tenpoints1_5(): def test_tenpoints2_1AND2_2(): ''' 2.1 Einfügen von Datensätzen unter Benutzung der oben angelegten RecordTypes - & 2.2 Hochladen von Dateien über HTTP und DropOffBox und Verknüpfung mit den + & 2.2 Hochladen von Dateien über HTTP und Verknüpfung mit den Datensätzen ''' """data model.""" - c = h.Container() + c = db.Container() c.append( - h.Property( + db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text')) c.append( - h.Property( + db.Property( name="SimpleDoubleProperty", description="simple double property (from test_tenpoints.py)", datatype='double', unit="m")) c.append( - h.Property( + db.Property( name="SimpleIntegerProperty", description="simple integer property (from test_tenpoints.py)", datatype='integer')) c.append( - h.Property( + db.Property( name="SimpleDatetimeProperty", description="simple datetime property (from test_tenpoints.py)", datatype='datetime')) c.append( - h.Property( + db.Property( name="SimpleFileProperty", description="simple file property (from test_tenpoints.py)", datatype='file')) c.append( - h.RecordType( + db.RecordType( name="SimpleRecordType", description="simple recordType (from test_tenpoints.py)") .add_property( name='SimpleTextProperty', @@ -341,11 +344,12 @@ def test_tenpoints2_1AND2_2(): importance='obligatory')) c.append( - h.Property( + db.Property( name="ReferenceProperty", description='reference property (from test_tenpoints.py)', datatype="SimpleRecordType")) - c.append(h.RecordType(name="ComplexRecordType", description="complex recordType with references (from test_tenpoints.py)") + c.append(db.RecordType(name="ComplexRecordType", + description="complex recordType with references (from test_tenpoints)") .add_property(name='ReferenceProperty') # first method # second method, doesn't need the ReferenceProperty .add_property(name='SimpleRecordType') @@ -355,7 +359,7 @@ def test_tenpoints2_1AND2_2(): print(c) ''' data''' - d = h.Container() + d = db.Container() ''' create testfile ''' f = open("test.dat", "w") @@ -364,7 +368,7 @@ def test_tenpoints2_1AND2_2(): ''' prepare file record ''' d.append( - h.File( + db.File( id=-1, path='testfiles/testfile', file="test.dat", @@ -372,7 +376,7 @@ def test_tenpoints2_1AND2_2(): ''' prepare simple record with file property''' d.append( - h.Record( + db.Record( id=-2, name="SimpleRecord") .add_parent( name='SimpleRecordType') .add_property( @@ -387,7 +391,7 @@ def test_tenpoints2_1AND2_2(): name='SimpleFileProperty', value=-1)) - d.append(h.Record() + d.append(db.Record() .add_parent(name="ComplexRecordType") .add_property(name="ReferenceProperty", value=-2) ) @@ -409,38 +413,28 @@ def test_tenpoints2_1AND2_2(): assert int(fp.value) == fr.id print(d) - """insert file via dropOffBox.""" - dob = h.DropOffBox().sync() - if os.path.isdir(dob.path): - f = open("test.dat", "w") - f.write("hello world\n") - f.close() - import shutil - shutil.move("test.dat", dob.path) - fo = h.File(path='testfiles/testfile2', pickup="test.dat").insert() - def test_tenpoints2_3(): '''2.3 Verwendung von Einheiten''' """insert simple property with unit.""" - p1 = h.Property(name='unittestproperty', datatype='double', unit='m') + p1 = db.Property(name='unittestproperty', datatype='double', unit='m') p1.insert() '''subtyping with unit inheritance''' - p2 = h.Property(name='SubTypeOfUnitTestProperty').add_parent(id=p1.id) + p2 = db.Property(name='SubTypeOfUnitTestProperty').add_parent(id=p1.id) p2.insert() assert 'm' == p2.unit '''implement property''' - rt = h.RecordType( + rt = db.RecordType( name='SimpleRecordType', description='simple recordType (from test_tenpoints.py)').add_property( id=p2.id) rt.insert() print(rt) rtid = rt.id - rt = h.RecordType(id=rtid).retrieve() + rt = db.RecordType(id=rtid).retrieve() print(rt) assert p2.id == rt.get_properties()[0].id @@ -451,43 +445,43 @@ def test_tenpoints2_4(): '''2.4 Nachtägliches Annotieren von Datensätzen, z.B. hinzufügen einer Description oder einer Zahl''' - c = h.Container() + c = db.Container() c.append( - h.Property( + db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text')) c.append( - h.Property( + db.Property( name="SimpleDoubleProperty", description="simple double property (from test_tenpoints.py)", datatype='double')) c.append( - h.Property( + db.Property( name="SimpleIntegerProperty", description="simple integer property (from test_tenpoints.py)", datatype='integer')) c.append( - h.Property( + db.Property( name="SimpleDatetimeProperty", description="simple datetime property (from test_tenpoints.py)", datatype='datetime')) c.append( - h.Property( + db.Property( name="SimpleFileProperty", description="simple file property (from test_tenpoints.py)", datatype='file')) c.append( - h.Property( + db.Property( name="CommentProperty", description="comment property", datatype='text')) c.insert() - d = h.Container() + d = db.Container() d.append( - h.RecordType( + db.RecordType( name="SimpleRecordType", description="simple recordType (from test_tenpoints.py)") .add_property( name='SimpleTextProperty', @@ -500,11 +494,12 @@ def test_tenpoints2_4(): name='SimpleFileProperty')) d.append( - h.Property( + db.Property( name="ReferenceProperty", description='reference property (from test_tenpoints.py)', datatype="SimpleRecordType")) - d.append(h.RecordType(name="ComplexRecordType", description="complex recordType with references (from test_tenpoints.py)") + d.append(db.RecordType(name="ComplexRecordType", + description="complex recordType with references (from test_tenpoints)") .add_property(name='ReferenceProperty') # first method # second method, doesn't need the ReferenceProperty .add_property(name='SimpleRecordType') @@ -518,10 +513,10 @@ def test_tenpoints2_4(): f.close() ''' prepare file record ''' - e = h.Container() - e.append(h.File(id=-1, path='testfiles/testfile', file="test.dat")) + e = db.Container() + e.append(db.File(id=-1, path='testfiles/testfile', file="test.dat")) - sr = (h.Record().add_parent(name="SimpleRecordType") + sr = (db.Record().add_parent(name="SimpleRecordType") .add_property(name="SimpleTextProperty", value="Some Text") .add_property(name="SimpleDoubleProperty", value=3.14) .add_property(name="SimpleIntegerProperty", value=1337) @@ -531,7 +526,7 @@ def test_tenpoints2_4(): e.append(sr).insert() cr1 = ( - h.Record( + db.Record( name="My special unique record name").add_parent( name="ComplexRecordType") .add_property( name="ReferenceProperty", @@ -539,28 +534,29 @@ def test_tenpoints2_4(): cr1.insert() - cr2 = (h.Record().add_parent(name="ComplexRecordType") + cr2 = (db.Record().add_parent(name="ComplexRecordType") .add_property(name="SimpleRecordType", value=sr)) recid = cr2.insert().id '''annotate file''' - h.File( + db.File( path='testfiles/testfile').retrieve().add_property( c.get_entity_by_name("CommentProperty"), value="This is a really nice file.").update() '''annotate records''' - h.Record( + db.Record( name="My special unique record name").retrieve().add_property( c.get_entity_by_name("CommentProperty"), value="This is a really nice record.").update() - h.Record( + db.Record( id=recid).retrieve().add_property( c.get_entity_by_name("CommentProperty"), value="I don't like this record.").update() - h.execute_query( - "FIND RECORD SimpleRecordType WITH SimpleIntegerProperty=1337 AND SimpleTextProperty='Some Text'", + db.execute_query( + "FIND RECORD SimpleRecordType WITH SimpleIntegerProperty=1337" + " AND SimpleTextProperty='Some Text'", unique=True).add_property( c.get_entity_by_name("CommentProperty"), value="I looove this record!!!!!11.").update() @@ -569,18 +565,18 @@ def test_tenpoints2_4(): def test_existence(): try: - h.Property(name="SimpleTextProperty").retrieve(unique=True) + db.Property(name="SimpleTextProperty").retrieve(unique=True) - except CaosDBException: + except LinkAheadException: print("SimpleTextProperty does not exist!") - p = h.Property( + p = db.Property( name="SimpleTextProperty", description="simple text property (from test_tenpoints.py)", datatype='text').insert() if int( - h.Property( + db.Property( name="SimpleTextProperty").retrieve( unique=True).id) >= 0: print("SimpleTextProperty does exist!") diff --git a/tests/test_tickets.py b/tests/test_tickets.py index 106d2f63aeb3c93840a67b86ebd6e51672c3b137..c535ed7bfa3e8c04553fc80eb1ee46b7bfe06162 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,43 +470,34 @@ def test_ticket_137(): rt1.insert() -@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(): @@ -1215,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 b6af11aef5d37903fb53de2a96c48a3e44ac98df..ac9dc253b439a0a4716b7eb184363256fe3efaf9 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,24 +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' +# 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 @@ -199,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"