From f970d1e2138c06f671c8c93940fccb6204413260 Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <florian.spreckelsen@gmx.net>
Date: Mon, 15 Jun 2020 16:07:14 +0000
Subject: [PATCH] Server 62 renaming

---
 CHANGELOG.md                |  4 ++++
 tests/test_issues_server.py | 34 +++++++++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc813ab..0027b3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added (for new features)
 
+- Tests for [#62](https://gitlab.com/caosdb/caosdb-server/-/issues/62)
+  in caosdb-server-project, i.e., renaming of a RecordType that should
+  be reflected in properties with that RT as datatype.
+
 ### Changed (for changes in existing functionality)
 
 ### Deprecated (for soon-to-be removed features)
diff --git a/tests/test_issues_server.py b/tests/test_issues_server.py
index 3b24e1f..88f9134 100644
--- a/tests/test_issues_server.py
+++ b/tests/test_issues_server.py
@@ -3,8 +3,9 @@
 # ** header v3.0
 # This file is a part of the CaosDB Project.
 #
-# Copyright (c) 2020 IndiScale GmbH (www.indiscale.com)
-# Copyright (c) 2020 Daniel Hornung (d.hornung@indiscale.com)
+# Copyright (c) 2020 IndiScale GmbH <info@indiscale.com>
+# Copyright (c) 2020 Daniel Hornung <d.hornung@indiscale.com>
+# Copyright (c) 2020 Florian Spreckelsen <f.spreckelsen@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
@@ -21,9 +22,11 @@
 #
 # ** end header
 
-"""Tests for issues on gitlab.com, project caosdb-mysqlbackend."""
+"""Tests for issues on gitlab.com, project caosdb-server."""
 
 import caosdb as db
+from caosdb.exceptions import EntityError
+import pytest
 
 
 def setup_module():
@@ -45,6 +48,31 @@ def teardown():
 
 # ########################### Issue tests start here ###########################
 
+@pytest.mark.xfail(reason="to be fixed in server repo")
+def test_issue_62():
+    """datatype is not changed when recordtype name changes
+
+    Tests for https://gitlab.com/caosdb/caosdb-server/-/issues/62
+    """
+    db.RecordType(name="Test_RTA").insert()
+    db.Property(name="Test_Prop", datatype="Test_RTA").insert()
+    db.Record(name="Test_Record").add_parent(
+        name="Test_RTA").add_property(name="Test_Prop").insert()
+    # rename Test_RTA to Test_RTB
+    rtb = db.execute_query("FIND RecordType Test_RTA", unique=True)
+    rtb.name = "Test_RTB"
+    rtb.update()
+    # renaming has to be reflected in Test_Record and Test_Prop
+    rec = db.execute_query("FIND Record Test_Record", unique=True)
+    assert rec.parents[0].name == rtb.name
+    prop = db.execute_query("FIND Property Test_Prop", unique=True)
+    assert prop.datatype == rtb.name  # fails; datatype not updated
+    # Can't use Test_RTA as datatype anymore
+    prop2 = db.Property(name="Test_Prop2", datatype="Test_RTA")
+    with pytest.raises(EntityError):
+        prop2.insert()
+
+
 def test_issue_85_a():
     """SQLIntegrityConstraintViolationException for special inheritance patterns.
 
-- 
GitLab