Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IIIF
backend
Merge requests
!2
Draft:Generic api v1
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
Draft:Generic api v1
generic-api-v1
into
master
Overview
0
Commits
18
Pipelines
0
Changes
7
Open
Draft:Generic api v1
David Beniamine
requested to merge
generic-api-v1
into
master
Feb 1, 2023
Overview
0
Commits
18
Pipelines
0
Changes
7
Adds a generic api URIs and models
Prefix path with api version
Generic config
Database initialization
Generic resources
Use generic Model
Auto documentation for parameter
Auto documentation for return values
Generic routes
group
GET
POST
item
GET
POST
PUT
PATCH
DELETE
ORM
tests
test infrastucture and simple exemple
Add data
Test storing data
Work on fake database
Edited
Feb 1, 2023
by
David Beniamine
0
0
Merge request reports
Viewing commit
afc7e288
Show latest version
7 files
+
56
−
35
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Verified
afc7e288
Working test with fixtures
· afc7e288
David Beniamine
authored
Feb 15, 2023
Mirador_backend/tests/test_mirador_resource.py
+
55
−
9
View file @ 57ce660a
Edit in single-file editor
Open in Web IDE
Show full file
@@ -4,14 +4,60 @@ from Mirador_backend.tests.tester import TestCase
class
MiradorResourceTest
(
TestCase
):
base
=
'
/mirador_resource
'
headers
=
{
"
Content-Type
"
:
"
application/json
"
}
def
testGet
(
self
):
# TODO payload
payload
=
json
.
dumps
({})
response
=
self
.
client
.
get
(
self
.
base
+
'
/1
'
,
headers
=
{
"
Content-Type
"
:
"
application/json
"
},
data
=
payload
)
def
getData
(
self
):
return
self
.
getFixtureRecordsByModel
(
self
.
fixtures
[
0
],
'
Mirador_backend.models.MiradorResource
'
)
self
.
assertEqual
(
200
,
response
.
status_code
)
# TODO test actual behavior with fixture data
self
.
assertEqual
(
'
get
'
,
response
.
json
[
'
method
'
])
self
.
assertEqual
(
int
,
type
(
response
.
json
[
'
id
'
]))
def
get
(
self
,
id
,
inFixtures
=
True
,
raw
=
None
):
response
=
self
.
client
.
get
(
f
'
{
self
.
base
}
/
{
id
}
'
,
headers
=
self
.
headers
)
if
inFixtures
:
self
.
assertGoodResponse
(
response
,
next
(
x
for
x
in
self
.
getData
()
if
x
[
'
id
'
]
==
1
))
elif
raw
is
not
None
:
self
.
assertGoodResponse
(
response
,
raw
)
else
:
self
.
assertBadResponse
(
response
,
404
)
def
testGetOne
(
self
):
self
.
get
(
1
)
def
testGetAll
(
self
):
response
=
self
.
client
.
get
(
self
.
base
,
headers
=
self
.
headers
)
self
.
assertGoodResponse
(
response
,
{
str
(
x
[
'
id
'
]):
x
for
x
in
self
.
getData
()})
def
testPut
(
self
):
id
=
3
self
.
get
(
id
,
False
)
data
=
{
'
content
'
:
'
{
"
a
"
:
"
b
"
}
'
}
payload
=
json
.
dumps
(
data
)
response
=
self
.
client
.
put
(
f
'
{
self
.
base
}
/
{
id
}
'
,
headers
=
self
.
headers
,
data
=
payload
)
data
[
'
id
'
]
=
id
self
.
assertGoodResponse
(
response
,
data
)
self
.
get
(
id
,
False
,
data
)
def
testPost
(
self
):
id
=
2
self
.
get
(
id
,
False
)
data
=
{
'
content
'
:
'
{
"
a
"
:
"
b
"
}
'
}
payload
=
json
.
dumps
(
data
)
response
=
self
.
client
.
post
(
f
'
{
self
.
base
}
'
,
headers
=
self
.
headers
,
data
=
payload
)
data
[
'
id
'
]
=
id
self
.
assertGoodResponse
(
response
,
data
)
self
.
get
(
id
,
False
,
data
)
def
testPatch
(
self
):
id
=
1
self
.
get
(
id
)
data
=
{
'
content
'
:
'
{
"
a
"
:
"
b
"
}
'
}
payload
=
json
.
dumps
(
data
)
response
=
self
.
client
.
patch
(
f
'
{
self
.
base
}
/
{
id
}
'
,
headers
=
self
.
headers
,
data
=
payload
)
data
[
'
id
'
]
=
id
self
.
assertGoodResponse
(
response
,
data
)
self
.
get
(
id
,
False
,
data
)
def
testDelete
(
self
):
id
=
1
self
.
get
(
id
)
response
=
self
.
client
.
delete
(
f
'
{
self
.
base
}
/
{
id
}
'
,
headers
=
self
.
headers
)
self
.
assertGoodResponse
(
response
,
{
'
success
'
:
True
})
self
.
get
(
id
,
False
)
Loading