diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 28881e5a282b42fe963f3a097b9c6ef0208f504a..3568978b12aabada85d1bad795d8194e17f1febc 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -42,7 +42,7 @@ def convert_value(value): Parameters ---------- - value : The property of which the value shall be returned. + value : the value that shall be returned and potentially converted. Returns ------- @@ -54,12 +54,9 @@ def convert_value(value): return str(value.id) elif isinstance(value, datetime): return value.isoformat() - - # TODO: check whether this here is needed: - # elif isinstance(value, bool): - # return str(value).upper() - - elif type(value) == str: + elif isinstance(value, bool): + return str(value).upper() + elif isinstance(value, str): # replace single quotes, otherwise they may break the queries return value.replace("\'", "\\'") else: @@ -106,7 +103,7 @@ class IdentifiableAdapter(metaclass=ABCMeta): whether the required record already exists. """ - query_string = "FIND Record " + query_string = "FIND RECORD " if ident.record_type is not None: query_string += ident.record_type for ref in ident.backrefs: diff --git a/unittests/test_identifiable_adapters.py b/unittests/test_identifiable_adapters.py index 6817b9e6993c0ec509354b68ff60d9a9caf534ae..7f1ba9d752f1fa2cc1afacc7a5ec281451a79e2d 100644 --- a/unittests/test_identifiable_adapters.py +++ b/unittests/test_identifiable_adapters.py @@ -71,6 +71,13 @@ def test_create_query_for_identifiable(): assert query.lower() == ("find record person which is referenced by 14433 and which is " "referenced by 333 and with 'last_name'='b' ") + # With single quote in string + query = IdentifiableAdapter.create_query_for_identifiable( + Identifiable(record_type="Person", backrefs=[], properties={'last_name': "B'Or"})) + print("find record person which is referenced by 14433 and which is " + "referenced by 333 and with 'last_name'='B\\'Or' ") + assert query == ("FIND RECORD Person WITH 'last_name'='B\\'Or' ") + def test_load_from_yaml_file(): ident = CaosDBIdentifiableAdapter()