Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
cf187118
Commit
cf187118
authored
2 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
FIX: proper treatment for strings and bool in query creation
parent
a5d2fc72
No related branches found
No related tags found
2 merge requests
!91
Release 0.3
,
!86
FIX: boolean in query creation
Pipeline
#32749
passed
2 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/identifiable_adapters.py
+6
-4
6 additions, 4 deletions
src/caoscrawler/identifiable_adapters.py
unittests/test_identifiable_adapters.py
+10
-3
10 additions, 3 deletions
unittests/test_identifiable_adapters.py
with
16 additions
and
7 deletions
src/caoscrawler/identifiable_adapters.py
+
6
−
4
View file @
cf187118
...
...
@@ -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,11 +54,13 @@ def convert_value(value):
return
str
(
value
.
id
)
elif
isinstance
(
value
,
datetime
):
return
value
.
isoformat
()
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
:
return
f
"
{
value
}
"
return
str
(
value
).
strip
()
class
IdentifiableAdapter
(
metaclass
=
ABCMeta
):
...
...
@@ -97,7 +99,7 @@ class IdentifiableAdapter(metaclass=ABCMeta):
whether the required record already exists.
"""
query_string
=
"
FIND R
ecord
"
query_string
=
"
FIND R
ECORD
"
if
ident
.
record_type
is
not
None
:
query_string
+=
ident
.
record_type
for
ref
in
ident
.
backrefs
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_identifiable_adapters.py
+
10
−
3
View file @
cf187118
...
...
@@ -50,9 +50,9 @@ def test_create_query_for_identifiable():
"
h
"
:
db
.
Record
(
id
=
1111
),
"
i
"
:
db
.
File
(
id
=
1112
),
"
j
"
:
[
2222
,
db
.
Record
(
id
=
3333
)]}))
assert
(
query
.
lower
()
==
"
find record b with
name=
'
a
'
and
'
c
'
=
'
c
'
and
'
d
'
=
'
5
'
and
'
e
'
=
'
5.5
'"
"
and
'
f
'
=
'
2020-10-10
t
00:00:00
'
and
'
g
'
=
'
true
'
and
'
h
'
=
'
1111
'
and
'
i
'
=
'
1112
'
and
"
"'
j
'
=
'
2222
'
and
'
j
'
=
'
3333
'
"
)
assert
(
query
==
"
FIND RECORD B WITH
name=
'
A
'
AND
'
c
'
=
'
c
'
AND
'
d
'
=
'
5
'
AND
'
e
'
=
'
5.5
'"
"
AND
'
f
'
=
'
2020-10-10
T
00:00:00
'
AND
'
g
'
=
'
TRUE
'
AND
'
h
'
=
'
1111
'
AND
'
i
'
=
'
1112
'
AND
"
"'
j
'
=
'
2222
'
AND
'
j
'
=
'
3333
'
"
)
# The name can be the only identifiable
query
=
IdentifiableAdapter
.
create_query_for_identifiable
(
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment