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
9df82ff2
Commit
9df82ff2
authored
3 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add an SQLite content type to uploaded exports
parent
5180dcda
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1379
Add an SQLite content type to uploaded exports
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/export/__init__.py
+13
-1
13 additions, 1 deletion
arkindex/documents/export/__init__.py
arkindex/documents/tests/tasks/test_export.py
+10
-2
10 additions, 2 deletions
arkindex/documents/tests/tasks/test_export.py
with
23 additions
and
3 deletions
arkindex/documents/export/__init__.py
+
13
−
1
View file @
9df82ff2
...
...
@@ -4,9 +4,11 @@ import os
import
sqlite3
import
tempfile
import
uuid
from
datetime
import
datetime
,
timezone
from
pathlib
import
Path
from
django.db
import
connections
from
django.utils.text
import
slugify
from
django_rq
import
job
from
rq
import
get_current_job
...
...
@@ -119,7 +121,17 @@ def export_corpus(corpus_export: CorpusExport) -> None:
if
rq_job
:
rq_job
.
set_description
(
f
'
Uploading export for corpus
{
corpus_export
.
corpus
.
name
}
'
)
rq_job
.
set_progress
(
0.0
)
corpus_export
.
s3_object
.
upload_file
(
db_path
,
Callback
=
progress_callback
)
# Set the filename in a HTTP header to make downloaded exports nicer
filename
=
f
'
{
slugify
(
corpus_export
.
corpus
.
name
)[
:
100
]
}
-
{
datetime
.
now
(
timezone
.
utc
).
strftime
(
"
%Y%m%d-%H%M%S
"
)
}
.sqlite
'
corpus_export
.
s3_object
.
upload_file
(
db_path
,
Callback
=
progress_callback
,
ExtraArgs
=
{
'
ContentType
'
:
'
application/vnd.sqlite3
'
,
'
ContentDisposition
'
:
f
'
attachment; filename=
"
{
filename
}
"'
},
)
corpus_export
.
state
=
CorpusExportState
.
Done
corpus_export
.
save
()
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/tasks/test_export.py
+
10
−
2
View file @
9df82ff2
import
json
import
os
import
sqlite3
from
datetime
import
datetime
,
timezone
from
unittest.mock
import
call
,
patch
from
arkindex.dataimport.models
import
WorkerVersion
...
...
@@ -21,9 +22,12 @@ from arkindex.project.tests import FixtureTestCase
class
TestExport
(
FixtureTestCase
):
@patch
(
'
arkindex.documents.export.datetime
'
)
@patch
(
'
arkindex.documents.export.os.unlink
'
)
@patch
(
'
arkindex.project.aws.s3.Object
'
)
def
test_export
(
self
,
s3_object_mock
,
unlink_mock
):
def
test_export
(
self
,
s3_object_mock
,
unlink_mock
,
datetime_mock
):
datetime_mock
.
now
.
return_value
=
datetime
(
2042
,
1
,
1
,
12
,
34
,
56
,
tzinfo
=
timezone
.
utc
)
element
=
self
.
corpus
.
elements
.
get
(
name
=
'
Volume 1
'
)
transcription
=
Transcription
.
objects
.
first
()
version
=
WorkerVersion
.
objects
.
get
(
worker__slug
=
'
reco
'
)
...
...
@@ -68,8 +72,12 @@ class TestExport(FixtureTestCase):
self
.
assertEqual
(
s3_object_mock
().
upload_file
.
call_count
,
1
)
args
,
kwargs
=
s3_object_mock
().
upload_file
.
call_args
self
.
assertCountEqual
(
kwargs
.
keys
(),
{
'
Callback
'
})
self
.
assertCountEqual
(
kwargs
.
keys
(),
{
'
Callback
'
,
'
ExtraArgs
'
})
self
.
assertTrue
(
callable
(
kwargs
[
'
Callback
'
]))
self
.
assertDictEqual
(
kwargs
[
'
ExtraArgs
'
],
{
'
ContentType
'
:
'
application/vnd.sqlite3
'
,
'
ContentDisposition
'
:
'
attachment; filename=
"
unit-tests-20420101-123456.sqlite
"'
})
self
.
assertEqual
(
len
(
args
),
1
)
# Retrieve the database path from the S3 upload argument
db_path
=
args
[
0
]
...
...
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