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
29b5fc60
Commit
29b5fc60
authored
4 years ago
by
Eva Bardou
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add unit tests
parent
e2c1047b
No related branches found
No related tags found
No related merge requests found
Pipeline
#78345
passed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_elements_worker/test_transcriptions.py
+109
-0
109 additions, 0 deletions
tests/test_elements_worker/test_transcriptions.py
with
109 additions
and
0 deletions
tests/test_elements_worker/test_transcriptions.py
+
109
−
0
View file @
29b5fc60
...
@@ -28,6 +28,26 @@ TRANSCRIPTIONS_SAMPLE = [
...
@@ -28,6 +28,26 @@ TRANSCRIPTIONS_SAMPLE = [
"
text
"
:
"
line
"
,
"
text
"
:
"
line
"
,
},
},
]
]
TRANSCRIPTIONS_TO_INSERT
=
[
CachedTranscription
(
id
=
convert_str_uuid_to_hex
(
"
11111111-1111-1111-1111-111111111111
"
),
element_id
=
convert_str_uuid_to_hex
(
"
12341234-1234-1234-1234-123412341234
"
),
text
=
"
Hello!
"
,
confidence
=
0.42
,
worker_version_id
=
convert_str_uuid_to_hex
(
"
56785678-5678-5678-5678-567856785678
"
),
),
CachedTranscription
(
id
=
convert_str_uuid_to_hex
(
"
22222222-2222-2222-2222-222222222222
"
),
element_id
=
convert_str_uuid_to_hex
(
"
12341234-1234-1234-1234-123412341234
"
),
text
=
"
How are you?
"
,
confidence
=
0.42
,
worker_version_id
=
convert_str_uuid_to_hex
(
"
90129012-9012-9012-9012-901290129012
"
),
),
]
def
test_create_transcription_wrong_element
(
mock_elements_worker
):
def
test_create_transcription_wrong_element
(
mock_elements_worker
):
...
@@ -1155,3 +1175,92 @@ def test_list_transcriptions(responses, mock_elements_worker):
...
@@ -1155,3 +1175,92 @@ def test_list_transcriptions(responses, mock_elements_worker):
"
http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/
"
,
"
http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/
"
,
"
http://testserver/api/v1/element/12341234-1234-1234-1234-123412341234/transcriptions/
"
,
"
http://testserver/api/v1/element/12341234-1234-1234-1234-123412341234/transcriptions/
"
,
]
]
def
test_list_transcriptions_with_cache_unhandled_param
(
responses
,
mock_elements_worker_with_cache
):
elt
=
Element
({
"
id
"
:
"
12341234-1234-1234-1234-123412341234
"
})
with
pytest
.
raises
(
AssertionError
)
as
e
:
mock_elements_worker_with_cache
.
list_transcriptions
(
element
=
elt
,
element_type
=
"
page
"
)
assert
(
str
(
e
.
value
)
==
"
When using the local cache, you can only filter by
'
worker_version
'"
)
def
test_list_transcriptions_with_cache_skip_recursive
(
responses
,
mock_elements_worker_with_cache
):
# When the local cache is activated and the user defines the recursive filter, we should fallback to the API
elt
=
Element
({
"
id
"
:
"
12341234-1234-1234-1234-123412341234
"
})
trans
=
[
{
"
id
"
:
"
0000
"
,
"
text
"
:
"
hey
"
,
"
confidence
"
:
0.42
,
"
worker_version_id
"
:
"
56785678-5678-5678-5678-567856785678
"
,
"
element
"
:
None
,
},
]
responses
.
add
(
responses
.
GET
,
"
http://testserver/api/v1/element/12341234-1234-1234-1234-123412341234/transcriptions/?recursive=True
"
,
status
=
200
,
json
=
{
"
count
"
:
3
,
"
next
"
:
None
,
"
results
"
:
trans
,
},
)
for
idx
,
transcription
in
enumerate
(
mock_elements_worker_with_cache
.
list_transcriptions
(
element
=
elt
,
recursive
=
True
)
):
assert
transcription
==
trans
[
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/element/12341234-1234-1234-1234-123412341234/transcriptions/?recursive=True
"
,
]
def
test_list_transcriptions_with_cache
(
responses
,
mock_elements_worker_with_cache
):
elt
=
Element
({
"
id
"
:
"
12341234-1234-1234-1234-123412341234
"
})
for
idx
,
transcription
in
enumerate
(
mock_elements_worker_with_cache
.
list_transcriptions
(
element
=
elt
)
):
assert
transcription
==
[]
# Initialize SQLite cache with some transcriptions
mock_elements_worker_with_cache
.
cache
.
insert
(
"
transcriptions
"
,
TRANSCRIPTIONS_TO_INSERT
)
expected_tr
=
TRANSCRIPTIONS_TO_INSERT
for
idx
,
transcription
in
enumerate
(
mock_elements_worker_with_cache
.
list_transcriptions
(
element
=
elt
)
):
assert
transcription
==
expected_tr
[
idx
]
expected_tr
=
[
TRANSCRIPTIONS_TO_INSERT
[
0
]]
for
idx
,
transcription
in
enumerate
(
mock_elements_worker_with_cache
.
list_transcriptions
(
element
=
elt
,
worker_version
=
"
56785678-5678-5678-5678-567856785678
"
)
):
assert
transcription
==
expected_tr
[
idx
]
assert
len
(
responses
.
calls
)
==
2
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/
"
,
]
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