Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
textgrid-python-clients
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Service Desk
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
DARIAH-DE
TextGridRep
textgrid-python-clients
Commits
4ffeda23
Verified
Commit
4ffeda23
authored
7 months ago
by
Ubbo Veentjer
Browse files
Options
Downloads
Patches
Plain Diff
feat: add uri param to tgcrud create api method
parent
9bcc36fe
No related branches found
No related tags found
1 merge request
!78
Resolve "add uri param to tgcrud create API"
Pipeline
#494345
passed
7 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tgclients/crud.py
+16
-4
16 additions, 4 deletions
src/tgclients/crud.py
tests/integration/test_crud_integration.py
+18
-0
18 additions, 0 deletions
tests/integration/test_crud_integration.py
with
34 additions
and
4 deletions
src/tgclients/crud.py
+
16
−
4
View file @
4ffeda23
...
...
@@ -91,7 +91,12 @@ class TextgridCrudRequest:
return
self
.
_handle_response
(
response
)
def
create_resource
(
self
,
sid
:
str
,
project_id
:
str
,
data
:
Union
[
str
,
IO
[
Any
]],
metadata
:
Union
[
str
,
IO
[
Any
]]
self
,
sid
:
str
,
project_id
:
str
,
data
:
Union
[
str
,
IO
[
Any
]],
metadata
:
Union
[
str
,
IO
[
Any
]],
uri
:
Optional
[
str
]
=
None
,
)
->
Response
:
"""
Create a TextGrid object.
...
...
@@ -100,6 +105,7 @@ class TextgridCrudRequest:
project_id (str): Project ID
data (Union[str, IO[Any]]): the data
metadata (Union[str, IO[Any]]): the metadata
uri (Optional[str]): optionally set a TextGrid URI to use for new object (see get_uri method)
Raises:
TextgridCrudException: if HTTP status code >= 400
...
...
@@ -108,7 +114,7 @@ class TextgridCrudRequest:
Response: HTTP response from service with metadata from newly created object
"""
encoder
=
self
.
_prepare_multipart
(
metadata
,
data
)
params
=
{
'
sessionId
'
:
sid
,
'
projectId
'
:
project_id
,
'
createRevision
'
:
'
false
'
}
params
=
{
'
sessionId
'
:
sid
,
'
projectId
'
:
project_id
,
'
createRevision
'
:
'
false
'
,
'
uri
'
:
uri
}
response
=
self
.
_requests
.
post
(
self
.
_url
+
'
/
'
+
'
create
'
,
params
=
params
,
...
...
@@ -360,7 +366,12 @@ class TextgridCrud(TextgridCrudRequest):
super
().
__init__
(
config
,
for_publication
)
def
create_resource
(
self
,
sid
:
str
,
project_id
:
str
,
data
:
Union
[
str
,
IO
[
Any
]],
metadata
:
MetadataContainerType
self
,
sid
:
str
,
project_id
:
str
,
data
:
Union
[
str
,
IO
[
Any
]],
metadata
:
MetadataContainerType
,
uri
:
Optional
[
str
]
=
None
,
)
->
MetadataContainerType
:
"""
Create a TextGrid object.
...
...
@@ -369,6 +380,7 @@ class TextgridCrud(TextgridCrudRequest):
project_id (str): Project ID
data (Union[str, IO[Any]]): the data
metadata (MetadataContainerType): the metadata
uri (Optional[str]): optionally set a TextGrid URI to use for new object (see get_uri method)
Raises:
TextgridCrudException: if HTTP status code >= 400
...
...
@@ -377,7 +389,7 @@ class TextgridCrud(TextgridCrudRequest):
MetadataContainerType: metadata for newly created object
"""
metadata_string
=
self
.
_serializer
.
render
(
metadata
)
response
=
super
().
create_resource
(
sid
,
project_id
,
data
,
metadata_string
)
response
=
super
().
create_resource
(
sid
,
project_id
,
data
,
metadata_string
,
uri
=
uri
)
return
self
.
_parser
.
parse
(
BytesIO
(
response
.
content
),
MetadataContainerType
)
def
create_revision
(
# noqa: PLR0913
...
...
This diff is collapsed.
Click to expand it.
tests/integration/test_crud_integration.py
+
18
−
0
View file @
4ffeda23
...
...
@@ -209,3 +209,21 @@ class TestTextgridCrudIntegration:
assert
len
(
uris
)
==
2
for
uri
in
uris
:
assert
uri
.
startswith
(
'
textgrid:
'
)
@staticmethod
def
test_get_uri_and_create
(
crud
):
sid
=
os
.
getenv
(
'
SESSION_ID
'
)
project_id
=
os
.
getenv
(
'
PROJECT_ID
'
)
uris
=
crud
.
get_uri
(
sid
,
1
)
assert
len
(
uris
)
==
1
assert
uris
[
0
].
startswith
(
'
textgrid:
'
)
now
=
datetime
.
now
().
strftime
(
'
%Y-%m-%d-%H:%M:%S
'
)
metadata
=
TextgridMetadata
().
build
(
title
=
'
test
'
+
now
,
mimetype
=
'
text/xml
'
)
data
=
'
<content>here</content>
'
res
=
crud
.
create_resource
(
sid
,
project_id
,
data
,
metadata
,
uri
=
uris
[
0
])
textgrid_uri
=
res
.
object_value
.
generic
.
generated
.
textgrid_uri
.
value
assert
textgrid_uri
==
f
'
{
uris
[
0
]
}
.0
'
res
=
crud
.
delete_resource
(
sid
,
textgrid_uri
)
assert
res
.
status_code
==
204
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