diff --git a/src/caosdb/__init__.py b/src/caosdb/__init__.py index 7e06885fe495c1e8c4ccc99b7d0c0f8ff8c34b5b..58c4aebb753eb86c1f51ff26a36109ae032940cf 100644 --- a/src/caosdb/__init__.py +++ b/src/caosdb/__init__.py @@ -41,7 +41,7 @@ from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER, from caosdb.common.state import State, Transition # Import of the basic API classes: from caosdb.common.models import (ACL, ALL, FIX, NONE, OBLIGATORY, RECOMMENDED, - SUGGESTED, Container, DropOffBox, Entity, + SUGGESTED, Container, Entity, File, Info, Message, Permissions, Property, Query, QueryTemplate, Record, RecordType, delete, execute_query, get_global_acl, diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 7000ede917995c6c01b78a822c2d39ac626fcc23..493150314efa9f3cc5d46250708e038b137c3338 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -289,14 +289,16 @@ class Entity(object): @property def thumbnail(self): - if self.__thumbnail is not None or self._wrapped_entity is None: - return self.__thumbnail - - return self._wrapped_entity.thumbnail + warn(DeprecationWarning( + "The thumbnail feature has been removed from the CaosDB server " + "API")) + return None @thumbnail.setter def thumbnail(self, new_thumbnail): - self.__thumbnail = new_thumbnail + warn(DeprecationWarning( + "The thumbnail feature has been removed from the CaosDB server " + "API")) @property def file(self): @@ -311,14 +313,16 @@ class Entity(object): @property def pickup(self): - if self.__pickup is not None or self._wrapped_entity is None: - return self.__pickup - - return self._wrapped_entity.pickup + warn(DeprecationWarning( + "The drop-off/pickup feature has been removed from the CaosDB " + "server API")) + return None @pickup.setter def pickup(self, new_pickup): - self.__pickup = new_pickup + warn(DeprecationWarning( + "The drop-off/pickup feature has been removed from the CaosDB " + "server API")) def grant(self, realm=None, username=None, role=None, permission=None, priority=False, revoke_denial=True): @@ -1805,9 +1809,9 @@ class File(Record): """This class represents CaosDB's file entities. - For inserting a new file to the server, `path` gives the new location, and - (exactly?) one of `file` and `pickup` should (must?) be given to specify the - source of the file. + For inserting a new file to the server or updating an existent one. + `path` gives the new location. `file` specifies the (local) file which is + to be uploaded. It is mandatory for insertions, but optionally for updates. Symlinking from the "extroot" file system is not supported by this API yet, it can be done manually using the `InsertFilesInDir` flag. For sample code, @@ -1822,18 +1826,16 @@ class File(Record): server's "caosroot" file system. @param file: A local path or python file object. The file designated by this argument will be uploaded to the server via HTTP. - @param pickup: A file/folder in the DropOffBox (the server will move that - file into its "caosroot" file system). - @param thumbnail: (Local) filename to a thumbnail for this file. + @param pickup: deprecated + @param thumbnail: deprecated. @param properties: A list of properties for this file record. @todo is this implemented? - @param from_location: Deprecated, use `pickup` instead. """ - def __init__(self, name=None, id=None, description=None, # @ReservedAssignment - path=None, file=None, pickup=None, # @ReservedAssignment - thumbnail=None, from_location=None): + def __init__(self, name=None, id=None, description=None, + path=None, file=None, pickup=None, + thumbnail=None): Record.__init__(self, id=id, name=name, description=description) self.role = "File" self.datatype = None @@ -1843,16 +1845,15 @@ class File(Record): # local file path or pointer to local file self.file = file - self.thumbnail = thumbnail - - self.pickup = pickup - - if from_location is not None: + if thumbnail is not None: warn(DeprecationWarning( - "Param `from_location` is deprecated, use `pickup instead`.")) + "The thumbnail feature has been removed from the CaosDB " + "server API")) - if self.pickup is None: - self.pickup = from_location + if pickup is not None: + warn(DeprecationWarning( + "The drop-off/pickup feature has been removed from the CaosDB " + "server API")) def to_xml(self, xml=None, add_properties=ALL, local_serialization=False): """Convert this file to an xml element. @@ -3402,8 +3403,6 @@ class Container(list): if hasattr(entity, '_upload') and entity._upload is not None: entity_xml.set("upload", entity._upload) - elif hasattr(entity, 'pickup') and entity.pickup is not None: - entity_xml.set("pickup", entity.pickup) insert_xml.append(entity_xml) @@ -3474,11 +3473,6 @@ class Container(list): part.filename = entity._upload http_parts.append(part) - if entity.thumbnail is not None: - part = MultipartParam.from_file(paramname=hex( - randint(0, sys.maxsize)), filename=entity.thumbnail) - part.filename = entity._upload + ".thumbnail" - http_parts.append(part) else: entity._checksum = None @@ -3552,8 +3546,6 @@ class Container(list): if hasattr(entity, '_upload') and entity._upload is not None: entity_xml.set("upload", entity._upload) - elif hasattr(entity, 'pickup') and entity.pickup is not None: - entity_xml.set("pickup", entity.pickup) insert_xml.append(entity_xml) if len(self) > 0 and len(insert_xml) < 1: @@ -4265,39 +4257,6 @@ def execute_query(q, unique=False, raise_exception_on_error=True, cache=True, fl cache=cache) -class DropOffBox(list): - - path = None - - def sync(self): - c = get_connection() - _log_request("GET: Info") - http_response = c.retrieve(["Info"]) - body = http_response.read() - _log_response(body) - - xml = etree.fromstring(body) - - for child in xml: - if child.tag.lower() == "stats": - infoelem = child - - break - - for child in infoelem: - if child.tag.lower() == "dropoffbox": - dropoffboxelem = child - - break - del self[:] - self.path = dropoffboxelem.get('path') - - for f in dropoffboxelem: - self.append(f.get('path')) - - return self - - class UserInfo(): def __init__(self, xml): diff --git a/unittests/test_file.py b/unittests/test_file.py index 3c80af7f362a7cdabe0a9ebc89cd2986d04fe242..9abe3dcc41663b38083a284fd0e1a84be00b3c6a 100644 --- a/unittests/test_file.py +++ b/unittests/test_file.py @@ -24,14 +24,10 @@ """Tests for the File class.""" from caosdb import File, Record, configure_connection from caosdb.connection.mockup import MockUpServerConnection -# pylint: disable=missing-docstring -from nose.tools import assert_equal as eq -from nose.tools import assert_is_not_none as there -from nose.tools import assert_true as tru def setup_module(): - there(File) + assert File is not None configure_connection(url="unittests", username="testuser", password_method="plain", password="testpassword", timeout=200, @@ -39,12 +35,12 @@ def setup_module(): def hat(obj, attr): - tru(hasattr(obj, attr)) + assert hasattr(obj, attr) def test_is_record(): file_ = File() - tru(isinstance(file_, Record)) + assert isinstance(file_, Record) def test_instance_variable(): @@ -57,4 +53,39 @@ def test_instance_variable(): def test_role(): file_ = File() - eq(file_.role, "File") + assert file_.role == "File" + + +def test_ticket_237(): + """This is an ancient test which has been moved here from the integration + test suite. It checks the basic functionality of the _wrap(function)""" + + f1 = File( + name="name1", + path="path1", + file="file1") + assert f1.name == "name1" + assert f1.path == "path1" + assert f1.file == "file1" + + f2 = File(name="name2") + assert f2.name == "name2" + assert f2.path is None + assert f2.file is None + + f2._wrap(f1) + + assert f2.name == "name2" + assert f2.path == "path1" + assert f2.file == "file1" + + f2.path = "path2" + f2.file = "file2" + + assert f2.name == "name2" + assert f2.path == "path2" + assert f2.file == "file2" + + assert f1.name == "name1" + assert f1.path == "path1" + assert f1.file == "file1"