Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
Workers
Base Worker
Commits
e4d0719c
Commit
e4d0719c
authored
4 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Add assert for query params
parent
6a44e282
No related branches found
No related tags found
No related merge requests found
Pipeline
#78297
passed
4 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker.py
+7
-6
7 additions, 6 deletions
arkindex_worker/worker.py
tests/test_elements_worker/test_elements.py
+6
-39
6 additions, 39 deletions
tests/test_elements_worker/test_elements.py
with
13 additions
and
45 deletions
arkindex_worker/worker.py
+
7
−
6
View file @
e4d0719c
...
...
@@ -889,12 +889,13 @@ class ElementsWorker(BaseWorker):
),
"
worker_version should be of type str
"
query_params
[
"
worker_version
"
]
=
worker_version
# Checking that we only have query_params handled by the cache
if
self
.
use_cache
and
set
(
query_params
.
keys
())
<=
{
"
name
"
,
"
type
"
,
"
worker_version
"
,
}:
if
self
.
use_cache
:
# Checking that we only received query_params handled by the cache
assert
set
(
query_params
.
keys
())
<=
{
"
name
"
,
"
type
"
,
"
worker_version
"
,
},
"
When using the local cache, you can only filter by
'
name
'
,
'
type
'
and/or
'
worker_version
'"
parent_id_hex
=
convert_str_uuid_to_hex
(
element
.
id
)
name_condition
=
f
"
AND name LIKE
'
%
{
name
}
%
'"
if
name
else
""
type_condition
=
f
"
AND type=
'
{
type
}
'"
if
type
else
""
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker/test_elements.py
+
6
−
39
View file @
e4d0719c
...
...
@@ -941,51 +941,18 @@ def test_list_element_children(responses, mock_elements_worker):
def
test_list_element_children_with_cache_unhandled_param
(
responses
,
mock_elements_worker_with_cache
mock_elements_worker_with_cache
,
):
"""
Calls list_elements_children on a worker using the cache.
The cache doesn
'
t contain any information about an element corpus and with_corpus query param is set to True.
The list_elements_children function will call the API (instead of the cache) to use the with_corpus param.
"""
elt
=
Element
({
"
id
"
:
"
12341234-1234-1234-1234-123412341234
"
})
expected_children
=
[
{
"
id
"
:
"
0000
"
,
"
type
"
:
"
page
"
,
"
name
"
:
"
Test
"
,
"
corpus
"
:
{},
"
thumbnail_url
"
:
None
,
"
zone
"
:
{},
"
best_classes
"
:
None
,
"
has_children
"
:
None
,
"
worker_version_id
"
:
None
,
}
]
responses
.
add
(
responses
.
GET
,
"
http://testserver/api/v1/elements/12341234-1234-1234-1234-123412341234/children/?with_corpus=True
"
,
status
=
200
,
json
=
{
"
count
"
:
1
,
"
next
"
:
None
,
"
results
"
:
expected_children
,
},
)
for
idx
,
child
in
enumerate
(
with
pytest
.
raises
(
AssertionError
)
as
e
:
mock_elements_worker_with_cache
.
list_element_children
(
element
=
elt
,
with_corpus
=
True
)
):
assert
child
==
expected_children
[
idx
]
assert
len
(
responses
.
calls
)
==
3
assert
[
call
.
request
.
url
for
call
in
responses
.
calls
]
==
[
"
http://testserver/api/v1/user/
"
,
"
http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/
"
,
"
http://testserver/api/v1/elements/12341234-1234-1234-1234-123412341234/children/?with_corpus=True
"
,
]
assert
(
str
(
e
.
value
)
==
"
When using the local cache, you can only filter by
'
name
'
,
'
type
'
and/or
'
worker_version
'"
)
def
test_list_element_children_with_cache
(
responses
,
mock_elements_worker_with_cache
):
...
...
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