Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
api
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
cubicweb
cubes
api
Commits
879d152f8046
Commit
879d152f8046
authored
1 year ago
by
Arnaud Vergnet
Browse files
Options
Downloads
Patches
Plain Diff
test: add multipart tests
parent
ac3d9f698435
No related branches found
No related tags found
1 merge request
!52
feat: add routes to upload and download binaries
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_api_rql.py
+100
-0
100 additions, 0 deletions
test/test_api_rql.py
with
100 additions
and
0 deletions
test/test_api_rql.py
+
100
−
0
View file @
879d152f
...
...
@@ -198,3 +198,103 @@
"
specification.
"
,
"
title
"
:
"
OpenApiValidationError
"
,
}
class
ApiRqlMultipartTC
(
ApiRqlTC
):
@property
def
content_type
(
self
):
return
"
multipart/form-data
"
def
get_body
(
self
,
queries
:
list
):
return
{
"
queries
"
:
json
.
dumps
(
queries
)}
def
test_upload_file
(
self
):
self
.
login_request
()
queries
=
[
{
"
query
"
:
"
Insert EntityWithBinary X: X binary %(binary_ref)s
"
,
"
params
"
:
{
"
binary_ref
"
:
{
"
type
"
:
"
binary_reference
"
,
"
ref
"
:
"
test_file
"
}
},
}
]
response
=
self
.
webapp
.
post
(
self
.
get_api_path
(
"
rql
"
),
params
=
{
"
queries
"
:
json
.
dumps
(
queries
),
"
test_file
"
:
webtest
.
Upload
(
"
filename.txt
"
,
b
"
content
"
),
},
content_type
=
self
.
content_type
,
)
eid
=
response
.
json
[
0
][
0
][
0
]
with
self
.
admin_access
.
repo_cnx
()
as
cnx
:
rset
=
cnx
.
execute
(
"
Any X, B WHERE X eid %(eid)s, X binary B
"
,
{
"
eid
"
:
eid
})
binary
:
Binary
=
rset
[
0
][
1
]
self
.
assertEqual
(
binary
.
read
(),
b
"
content
"
)
def
test_upload_file_missing_reference
(
self
):
self
.
login_request
()
queries
=
[
{
"
query
"
:
"
Insert EntityWithBinary X: X binary %(binary_ref)s
"
,
"
params
"
:
{
"
binary_ref
"
:
{
"
type
"
:
"
binary_reference
"
,
"
ref
"
:
"
wrong_ref
"
}
},
}
]
response
=
self
.
webapp
.
post
(
self
.
get_api_path
(
"
rql
"
),
params
=
{
"
queries
"
:
json
.
dumps
(
queries
),
"
test_file
"
:
webtest
.
Upload
(
"
filename.txt
"
,
b
"
content
"
),
},
content_type
=
self
.
content_type
,
status
=
400
,
).
json
assert
response
==
{
"
message
"
:
"
Could not find binary of id wrong_ref
"
,
"
data
"
:
None
,
"
title
"
:
"
InvalidTransaction
"
,
}
def
test_upload_file_malformed_reference
(
self
):
self
.
login_request
()
queries
=
[
{
"
query
"
:
"
Insert EntityWithBinary X: X binary %(binary_ref)s
"
,
"
params
"
:
{
"
binary_ref
"
:
{
"
type
"
:
"
binary_reference
"
,
}
},
}
]
response
=
self
.
webapp
.
post
(
self
.
get_api_path
(
"
rql
"
),
params
=
{
"
queries
"
:
json
.
dumps
(
queries
),
"
test_file
"
:
webtest
.
Upload
(
"
filename.txt
"
,
b
"
content
"
),
},
content_type
=
self
.
content_type
,
status
=
400
,
).
json
assert
response
==
{
"
data
"
:
[
{
"
exception
"
:
"
ValidationError
"
,
"
message
"
:
"
{
'
type
'
:
'
binary_reference
'
} is valid under each of
"
"
{
'
additionalProperties
'
: False,
'
properties
'
: {
'
ref
'
:
"
"
{
'
type
'
:
'
string
'
},
'
type
'
: {
'
type
'
:
'
string
'
}},
"
"'
type
'
:
'
object
'
}, {
'
additionalProperties
'
: False,
"
"'
properties
'
: {
'
column
'
: {
'
type
'
:
'
number
'
},
"
"'
queryIndex
'
: {
'
type
'
:
'
number
'
},
'
row
'
: {
'
type
'
:
"
"'
number
'
},
'
type
'
: {
'
type
'
:
'
string
'
}},
'
type
'
:
"
"'
object
'
}
"
,
}
],
"
message
"
:
"
Your request could not be validated against the openapi
"
"
specification.
"
,
"
title
"
:
"
OpenApiValidationError
"
,
}
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