Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
6c2b7116
Verified
Commit
6c2b7116
authored
4 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Add tests
parent
84d32ae6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/serializers/ml.py
+7
-8
7 additions, 8 deletions
arkindex/documents/serializers/ml.py
arkindex/documents/tests/test_bulk_transcriptions.py
+98
-0
98 additions, 0 deletions
arkindex/documents/tests/test_bulk_transcriptions.py
with
105 additions
and
8 deletions
arkindex/documents/serializers/ml.py
+
7
−
8
View file @
6c2b7116
...
...
@@ -395,14 +395,13 @@ class TranscriptionBulkSerializer(serializers.Serializer):
if
not
missing_ids
:
return
data
# Return an error message with list indexes just like DRF's ListField, for easier debugging
errors
=
{}
for
i
,
transcription
in
enumerate
(
data
[
'
transcriptions
'
]):
if
transcription
[
'
element_id
'
]
in
missing_ids
:
errors
[
str
(
i
)]
=
{
"
element_id
"
:
[
f
'
Element
{
transcription
[
"
element_id
"
]
}
was not found or cannot be written to.
'
],
}
raise
ValidationError
({
'
transcriptions
'
:
errors
})
# Return an error message as a list just like DRF's ListField, for easier debugging
raise
ValidationError
({
'
transcriptions
'
:
[
{
"
element_id
"
:
[
f
'
Element
{
transcription
[
"
element_id
"
]
}
was not found or cannot be written to.
'
]}
if
transcription
[
'
element_id
'
]
in
missing_ids
else
{}
for
i
,
transcription
in
enumerate
(
data
[
'
transcriptions
'
])
]})
def
create
(
self
,
validated_data
):
transcriptions
=
[
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_bulk_transcriptions.py
0 → 100644
+
98
−
0
View file @
6c2b7116
from
django.urls
import
reverse
from
rest_framework
import
status
from
arkindex_common.enums
import
TranscriptionType
from
arkindex.project.tests
import
FixtureAPITestCase
class
TestBulkTranscriptions
(
FixtureAPITestCase
):
def
test_bulk_transcriptions_requires_login
(
self
):
with
self
.
assertNumQueries
(
0
):
response
=
self
.
client
.
post
(
reverse
(
'
api:transcription-bulk
'
))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
def
test_bulk_transcriptions_not_found
(
self
):
self
.
client
.
force_login
(
self
.
user
)
self
.
user
.
corpus_right
.
all
().
delete
()
forbidden_element
=
self
.
corpus
.
elements
.
get
(
name
=
'
Volume 1, page 1r
'
)
with
self
.
assertNumQueries
(
3
):
response
=
self
.
client
.
post
(
reverse
(
'
api:transcription-bulk
'
),
{
"
transcriptions
"
:
[
{
"
element_id
"
:
str
(
forbidden_element
.
id
),
"
type
"
:
TranscriptionType
.
Word
.
value
,
"
text
"
:
"
lol
"
,
"
score
"
:
0.4
},
{
"
element_id
"
:
"
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
"
,
"
type
"
:
TranscriptionType
.
Word
.
value
,
"
text
"
:
"
lol
"
,
"
score
"
:
0.4
}
],
},
format
=
'
json
'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
json
(),
{
'
transcriptions
'
:
[
{
'
element_id
'
:
[
f
'
Element
{
forbidden_element
.
id
}
was not found or cannot be written to.
'
]},
{
'
element_id
'
:
[
'
Element aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa was not found or cannot be written to.
'
]},
]
})
def
test_bulk_transcriptions
(
self
):
self
.
client
.
force_login
(
self
.
user
)
element1
=
self
.
corpus
.
elements
.
get
(
name
=
'
Volume 2
'
)
element2
=
self
.
corpus
.
elements
.
get
(
name
=
'
Volume 2, page 1r
'
)
self
.
assertFalse
(
element1
.
transcriptions
.
exists
())
self
.
assertFalse
(
element2
.
transcriptions
.
exists
())
with
self
.
assertNumQueries
(
4
):
response
=
self
.
client
.
post
(
reverse
(
'
api:transcription-bulk
'
),
{
"
transcriptions
"
:
[
{
"
element_id
"
:
str
(
element1
.
id
),
"
type
"
:
TranscriptionType
.
Word
.
value
,
"
text
"
:
"
Sneasel
"
,
"
score
"
:
0.54
},
{
"
element_id
"
:
str
(
element2
.
id
),
"
type
"
:
TranscriptionType
.
Line
.
value
,
"
text
"
:
"
Charizard
"
,
"
score
"
:
0.85
},
{
"
element_id
"
:
str
(
element1
.
id
),
"
type
"
:
TranscriptionType
.
Word
.
value
,
"
text
"
:
"
Raticate
"
,
"
score
"
:
0.12
},
],
},
format
=
'
json
'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
self
.
assertCountEqual
(
list
(
element1
.
transcriptions
.
values
(
'
type
'
,
'
text
'
,
'
score
'
)),
[
{
"
type
"
:
TranscriptionType
.
Word
,
"
text
"
:
"
Sneasel
"
,
"
score
"
:
0.54
},
{
"
type
"
:
TranscriptionType
.
Word
,
"
text
"
:
"
Raticate
"
,
"
score
"
:
0.12
},
]
)
self
.
assertCountEqual
(
list
(
element2
.
transcriptions
.
values
(
'
type
'
,
'
text
'
,
'
score
'
)),
[{
"
type
"
:
TranscriptionType
.
Line
,
"
text
"
:
"
Charizard
"
,
"
score
"
:
0.85
}]
)
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