From 0d1462defb083a7900ded57f3f8a7c4d9fa89d94 Mon Sep 17 00:00:00 2001 From: Florian Spreckelsen <florian.spreckelsen@gmx.net> Date: Fri, 14 Aug 2020 11:49:38 +0000 Subject: [PATCH] Tests for quotes around datetimes # Summary Adds a test for checking queries with quoted datetimes. See [#39](https://gitlab.com/caosdb/caosdb-server/-/issues/39) in caosdb-server. # Focus `test_issue_39` in `tests/test_issues_server.py` --- CHANGELOG.md | 3 +++ tests/test_issues_server.py | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5919bd2..6d70f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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. +- Test for [#39](https://gitlab.com/caosdb/caosdb-server/-/issues/39) + in caosdb server which checks if quoted datetimes in queries are + evaluated correctly. ### Changed (for changes in existing functionality) diff --git a/tests/test_issues_server.py b/tests/test_issues_server.py index 2bc35a4..2f4b5c5 100644 --- a/tests/test_issues_server.py +++ b/tests/test_issues_server.py @@ -25,13 +25,13 @@ """Tests for issues on gitlab.com, project caosdb-server.""" import caosdb as db -from caosdb.exceptions import EntityError +from caosdb.exceptions import EntityError, TransactionError import pytest def setup_module(): try: - db.execute_query("FIND ENTITY WITH ID > 100").delete() + db.execute_query("FIND ENTITY WITH ID > 99").delete() except Exception as delete_exc: print(delete_exc) @@ -48,6 +48,27 @@ def teardown(): # ########################### Issue tests start here ##################### + +def test_issue_39(): + """Query Language Bug - quotes around year + + Test for https://gitlab.com/caosdb/caosdb-server/-/issues/39 + """ + date_str = "2020-01-01" + prop_name = "Test_Date" + db.Property(name=prop_name, datatype=db.DATETIME).insert() + db.RecordType(name="Test_Type").add_property(name=prop_name).insert() + db.Record(name="Test_Record").add_parent(name="Test_Type").add_property( + name=prop_name, value=date_str).insert() + # Quotes around years should work in the query + ent = db.execute_query("FIND entity WITH A Test_Date IN \"2020\"", + unique=True) + assert ent.get_property(prop_name).value == date_str + # This should raise a transaction error + with pytest.raises(TransactionError): + db.execute_query("FIND entity WITH A Test_Date IN \"abcd\"") + + @pytest.mark.xfail(reason="to be fixed in server repo") def test_issue_62(): """datatype is not changed when recordtype name changes -- GitLab