Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Python Integration Tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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 Python Integration Tests
Commits
7cc4a4c3
Verified
Commit
7cc4a4c3
authored
2 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev' into f-server-144
parents
b8feea22
22760ada
No related branches found
No related tags found
1 merge request
!60
TST: Test for issue server#143.
Pipeline
#35683
passed
2 years ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_issues_server.py
+12
-0
12 additions, 0 deletions
tests/test_issues_server.py
tests/test_pylib_caching.py
+89
-0
89 additions, 0 deletions
tests/test_pylib_caching.py
tox.ini
+3
-0
3 additions, 0 deletions
tox.ini
with
104 additions
and
0 deletions
tests/test_issues_server.py
+
12
−
0
View file @
7cc4a4c3
...
...
@@ -1303,3 +1303,15 @@ def test_166():
"
exists_property
"
,
234243
).
insert
()
assert
[
e
.
msg
for
e
in
cm
.
value
.
errors
]
==
[
"
Entity has unqualified parents.
"
]
@pytest.mark.xfail
(
reason
=
"
fix needed
"
)
def
test_195
():
"""
https://gitlab.com/caosdb/caosdb-server/-/issues/195
"""
admin
.
_insert_role
(
name
=
CURATOR_ROLE
,
description
=
"
Desc
"
)
perms
=
admin
.
_get_permissions
(
CURATOR_ROLE
)
g
=
admin
.
PermissionRule
(
action
=
"
Grant
"
,
permission
=
"
INVALID_PERMISSION:*
"
)
perms
.
add
(
g
)
with
pytest
.
raises
(
Exception
):
admin
.
_set_permissions
(
CURATOR_ROLE
,
permission_rules
=
perms
)
This diff is collapsed.
Click to expand it.
tests/test_pylib_caching.py
0 → 100644
+
89
−
0
View file @
7cc4a4c3
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2023 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2023 Daniel Hornung <d.hornung@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
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Test the Python-side caching of server queries.
"""
import
os
from
datetime
import
datetime
import
caosdb
as
db
from
caosdb.cached
import
cached_query
,
cached_get_entity_by
,
cache_clear
def
setup_function
():
d
=
db
.
execute_query
(
"
FIND Entity WITH ID > 99
"
)
if
len
(
d
)
>
0
:
d
.
delete
()
cache_clear
()
with
open
(
"
test.dat
"
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
upload_file
:
upload_file
.
write
(
"
hello world
\n
"
)
def
teardown_function
():
setup_function
()
try
:
os
.
remove
(
"
test.dat
"
)
except
Exception
as
e
:
print
(
e
)
def
test_caching
():
"""
Test if cached functions work at all.
"""
rect
=
db
.
RecordType
(
name
=
"
RT1
"
).
insert
()
rec
=
db
.
Record
(
name
=
"
rec1
"
).
add_parent
(
rect
).
insert
()
for
res
in
(
cached_get_entity_by
(
eid
=
rec
.
id
),
cached_get_entity_by
(
name
=
rec
.
name
),
cached_get_entity_by
(
query
=
"
FIND RECORD rec1
"
),
cached_query
(
"
FIND RECORD rec1
"
)[
0
],
):
assert
res
.
id
==
rec
.
id
file_
=
db
.
File
(
name
=
"
TestFile
"
,
description
=
"
Testfile Desc
"
,
path
=
"
testfiles/test.dat
"
,
file
=
"
test.dat
"
).
insert
()
res
=
cached_get_entity_by
(
path
=
"
testfiles/test.dat
"
)
assert
file_
.
id
==
res
.
id
def
test_caching_speed
():
"""
Test if caching is faster that uncached access.
"""
rect
=
db
.
RecordType
(
name
=
"
RT1
"
).
insert
()
db
.
Record
(
name
=
"
rec1
"
).
add_parent
(
rect
).
insert
()
# Retrieve once to set up server-side caching.
db
.
execute_query
(
"
FIND RECORD rec1
"
)
# uncached
before
=
datetime
.
now
()
cached_query
(
"
FIND RECORD rec1
"
)
after
=
datetime
.
now
()
time_uncached
=
after
-
before
# cached
before
=
datetime
.
now
()
cached_query
(
"
FIND RECORD rec1
"
)
after
=
datetime
.
now
()
time_cached
=
after
-
before
error_str
=
f
"
Cached query was not faster than uncached,
{
time_uncached
}
vs.
{
time_cached
}
"
assert
time_cached
<
time_uncached
,
error_str
This diff is collapsed.
Click to expand it.
tox.ini
+
3
−
0
View file @
7cc4a4c3
...
...
@@ -5,6 +5,9 @@ skip_missing_interpreters = true
[pycodestyle]
max_line_length
=
100
[flake8]
max-line-length
=
100
[testenv]
setenv
=
PASSWORD_STORE_DIR = {env:HOME}/.password-store
passenv
=
PYCAOSDBINI
...
...
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