Skip to content
Snippets Groups Projects
Commit 0a6e522a authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'release-v0.3.0' into 'master'

Release v0.3.0

See merge request caosdb/caosdb-pylib!21
parents b6563976 ad187e7d
No related branches found
No related tags found
No related merge requests found
# Changelog # Changelog #
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ##
### Added ###
### Changed ###
### Deprecated ###
### Removed ###
### Fixed ###
### Security ###
## [0.3.0] - 2020-04-24##
## [0.2.4] ### Added ###
* `apiutils.apply_to_ids` -- a helper which applies a function to all ids which
are used by an entity (own entity, parents, properties, references etc.).
### Changed ###
### Deprecated ###
### Fixed ###
* import bugs in apiutils
## [0.2.4] -- 2020-04-23
### Added ### Added
...@@ -49,7 +78,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -49,7 +78,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Many other fixes - Many other fixes
## [0.1.0] - 2018-10-09 ## [0.1.0] - 2018-10-09 ##
Tag `v0.1` - Commit 6fc0dcaa Tag `v0.1` - Commit 6fc0dcaa
......
# Release Guidelines for the CaosDB MySQL Backend # Release Guidelines for the CaosDB Python Client Library
This document specifies release guidelines in addition to the generel release This document specifies release guidelines in addition to the generel release
guidelines of the CaosDB Project guidelines of the CaosDB Project
...@@ -28,7 +28,9 @@ guidelines of the CaosDB Project ...@@ -28,7 +28,9 @@ guidelines of the CaosDB Project
6. Delete the release branch. 6. Delete the release branch.
7. Publish the release by executing `./release.sh` with uploads the caosdb 7. Remove possibly existing `./dist` directory with old release.
8. Publish the release by executing `./release.sh` with uploads the caosdb
module to the Python Package Index [pypi.org](https://pypi.org). module to the Python Package Index [pypi.org](https://pypi.org).
8. Merge the master branch back into the dev branch. 9. Merge the master branch back into the dev branch.
release.sh 100644 → 100755
File mode changed from 100644 to 100755
...@@ -46,10 +46,11 @@ from setuptools import find_packages, setup ...@@ -46,10 +46,11 @@ from setuptools import find_packages, setup
######################################################################## ########################################################################
MAJOR = 0 MAJOR = 0
MINOR = 2 MINOR = 3
MICRO = 4 MICRO = 0
PRE = "" # e.g. rc0, alpha.1, 0.beta-23 PRE = ""
ISRELEASED = True ISRELEASED = True
if PRE: if PRE:
VERSION = "{}.{}.{}-{}".format(MAJOR, MINOR, MICRO, PRE) VERSION = "{}.{}.{}-{}".format(MAJOR, MINOR, MICRO, PRE)
else: else:
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -34,7 +36,8 @@ from subprocess import call ...@@ -34,7 +36,8 @@ from subprocess import call
from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER, from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
REFERENCE, TEXT) REFERENCE, TEXT)
from caosdb.common.models import (Container, Entity, File, Property, Query, from caosdb.common.models import (Container, Entity, File, Property, Query,
Record, RecordType, get_config) Record, RecordType, get_config,
execute_query, is_reference)
def new_record(record_type, name=None, description=None, def new_record(record_type, name=None, description=None,
...@@ -85,11 +88,11 @@ def new_record(record_type, name=None, description=None, ...@@ -85,11 +88,11 @@ def new_record(record_type, name=None, description=None,
def id_query(ids): def id_query(ids):
q = "FIND Entity with " + " OR ".join(["id={}".format(id) for id in ids]) q = "FIND Entity with " + " OR ".join(["id={}".format(id) for id in ids])
return db.execute_query(q) return execute_query(q)
def retrieve_entities_with_ids(entities): def retrieve_entities_with_ids(entities):
collection = db.Container() collection = Container()
step = 20 step = 20
for i in range(len(entities)//step+1): for i in range(len(entities)//step+1):
...@@ -669,3 +672,36 @@ def describe_diff(olddiff, newdiff, name=None, as_update=True): ...@@ -669,3 +672,36 @@ def describe_diff(olddiff, newdiff, name=None, as_update=True):
"version of {}\n\n".format(name))+description "version of {}\n\n".format(name))+description
return description return description
def apply_to_ids(entities, func):
""" Apply a function to all ids.
All ids means the ids of the entities themselves but also to all parents,
properties and referenced entities.
Parameters
----------
entities : list of Entity
func : function with one parameter.
"""
for entity in entities:
_apply_to_ids_of_entity(entity, func)
def _apply_to_ids_of_entity(entity, func):
entity.id = func(entity.id)
for par in entity.parents:
par.id = func(par.id)
for prop in entity.properties:
prop.id = func(prop.id)
isref = is_reference(prop.datatype)
if isref:
if isinstance(prop.value, list):
prop.value = [func(el) for el in prop.value]
else:
if prop.value is not None:
prop.value = func(prop.value)
...@@ -110,7 +110,7 @@ def get_id_of_datatype(datatype): ...@@ -110,7 +110,7 @@ def get_id_of_datatype(datatype):
raise AmbiguityException( raise AmbiguityException(
"Name {} did not lead to unique result; Missing " "Name {} did not lead to unique result; Missing "
"implementation".format(datatype)) "implementation".format(datatype))
elif len(res) == 1: elif len(res) != 1:
raise EntityDoesNotExistError( raise EntityDoesNotExistError(
"No RecordType named {}".format(datatype)) "No RecordType named {}".format(datatype))
......
...@@ -38,8 +38,8 @@ from sys import hexversion ...@@ -38,8 +38,8 @@ from sys import hexversion
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from warnings import warn from warnings import warn
from lxml import etree from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
LIST, REFERENCE, TEXT, is_reference)
from caosdb.common.utils import uuid, xml2str from caosdb.common.utils import uuid, xml2str
from caosdb.configuration import get_config from caosdb.configuration import get_config
from caosdb.connection.connection import get_connection from caosdb.connection.connection import get_connection
...@@ -51,8 +51,9 @@ from caosdb.exceptions import (AmbiguityException, AuthorizationException, ...@@ -51,8 +51,9 @@ from caosdb.exceptions import (AmbiguityException, AuthorizationException,
EntityHasNoDatatypeError, TransactionError, EntityHasNoDatatypeError, TransactionError,
UniqueNamesError, UnqualifiedParentsError, UniqueNamesError, UnqualifiedParentsError,
UnqualifiedPropertiesError, URITooLongException) UnqualifiedPropertiesError, URITooLongException)
from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER, from lxml import etree
LIST, REFERENCE, TEXT, is_reference)
from .datatype import is_reference
_ENTITY_URI_SEGMENT = "Entity" _ENTITY_URI_SEGMENT = "Entity"
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen # Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -25,6 +27,7 @@ ...@@ -25,6 +27,7 @@
# A. Schlemmer, 02/2018 # A. Schlemmer, 02/2018
import caosdb as db import caosdb as db
from caosdb.apiutils import apply_to_ids
from .record import testrecord from .record import testrecord
import pickle import pickle
import tempfile import tempfile
...@@ -42,3 +45,20 @@ def test_pickle_object(): ...@@ -42,3 +45,20 @@ def test_pickle_object():
f.seek(0) f.seek(0)
rn2 = pickle.load(f) rn2 = pickle.load(f)
assert r2.date == rn2.date assert r2.date == rn2.date
def test_apply_to_ids():
parent = db.RecordType(id=3456)
rec = db.Record(id=23)
p = db.Property(id=23345, datatype=db.INTEGER)
rec.add_parent(parent)
rec.add_property(p)
def invert(id_):
return id_ * -1
apply_to_ids([rec], invert)
assert invert(3456) == -3456
assert rec.parents[0].id == -3456
assert rec.properties[0].id == -23345
assert rec.id == -23
...@@ -22,42 +22,36 @@ ...@@ -22,42 +22,36 @@
# ** end header # ** end header
# #
"""Tests for the Entity class.""" """Tests for the Entity class."""
# pylint: disable=missing-docstring
import unittest import unittest
from caosdb import Entity, configure_connection from caosdb import (INTEGER, Entity, Property, Record, RecordType,
configure_connection)
from caosdb.connection.mockup import MockUpServerConnection 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(): class TestEntity(unittest.TestCase):
there(Entity)
def setUp(self):
self.assertIsNotNone(Entity)
configure_connection(url="unittests", username="testuser", configure_connection(url="unittests", username="testuser",
password="testpassword", timeout=200, password="testpassword", timeout=200,
implementation=MockUpServerConnection) implementation=MockUpServerConnection)
def hat(obj, attr):
tru(hasattr(obj, attr))
class TestEntity(unittest.TestCase):
def test_instance_variables(self): def test_instance_variables(self):
entity = Entity() entity = Entity()
hat(entity, "role") self.assertTrue(hasattr(entity, "role"))
hat(entity, "id") self.assertTrue(hasattr(entity, "id"))
hat(entity, "name") self.assertTrue(hasattr(entity, "name"))
hat(entity, "description") self.assertTrue(hasattr(entity, "description"))
hat(entity, "parents") self.assertTrue(hasattr(entity, "parents"))
hat(entity, "properties") self.assertTrue(hasattr(entity, "properties"))
def test_role(self): def test_role(self):
entity = Entity(role="TestRole") entity = Entity(role="TestRole")
eq(entity.role, "TestRole") self.assertEqual(entity.role, "TestRole")
entity.role = "TestRole2" entity.role = "TestRole2"
eq(entity.role, "TestRole2") self.assertEqual(entity.role, "TestRole2")
def test_instanciation(self): def test_instanciation(self):
self.assertRaises(Exception, Entity()) self.assertRaises(Exception, Entity())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment