Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataCatalog
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
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
eFlows4HPC WP2
DataCatalog
Commits
788b7a13
Commit
788b7a13
authored
3 years ago
by
Jedrzej Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
test for delete and response models defined
parent
60ee463f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#69477
passed
3 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apiserver/main.py
+18
-19
18 additions, 19 deletions
apiserver/main.py
tests/apiserver_tests/test_apiwithauth.py
+16
-2
16 additions, 2 deletions
tests/apiserver_tests/test_apiwithauth.py
with
34 additions
and
21 deletions
apiserver/main.py
+
18
−
19
View file @
788b7a13
...
@@ -4,6 +4,7 @@ Main module of data catalog api
...
@@ -4,6 +4,7 @@ Main module of data catalog api
import
logging
import
logging
from
datetime
import
timedelta
from
datetime
import
timedelta
from
enum
import
Enum
from
enum
import
Enum
from
typing
import
List
,
Tuple
from
fastapi
import
FastAPI
,
HTTPException
,
Request
,
status
from
fastapi
import
FastAPI
,
HTTPException
,
Request
,
status
from
fastapi.param_functions
import
Depends
from
fastapi.param_functions
import
Depends
...
@@ -42,16 +43,6 @@ def my_user(token=Depends(oauth2_scheme)):
...
@@ -42,16 +43,6 @@ def my_user(token=Depends(oauth2_scheme)):
def
my_auth
(
form_data
:
OAuth2PasswordRequestForm
=
Depends
()):
def
my_auth
(
form_data
:
OAuth2PasswordRequestForm
=
Depends
()):
return
authenticate_user
(
userdb
,
form_data
.
username
,
form_data
.
password
)
return
authenticate_user
(
userdb
,
form_data
.
username
,
form_data
.
password
)
@app.get
(
"
/
"
)
async
def
get_types
():
"""
list types of data locations, currently datasets
(will be provided by the pillars) and targets (possible storage
locations for worklfow results or similar)
"""
return
[{
element
.
value
:
"
/
"
+
element
.
value
}
for
element
in
LocationDataType
]
@app.get
(
"
/me
"
,
response_model
=
User
)
@app.get
(
"
/me
"
,
response_model
=
User
)
async
def
read_users_me
(
user
=
Depends
(
my_user
)):
async
def
read_users_me
(
user
=
Depends
(
my_user
)):
"""
return information about the currently logged in user
"""
"""
return information about the currently logged in user
"""
...
@@ -73,14 +64,27 @@ async def login_for_access_token(user=Depends(my_auth)):
...
@@ -73,14 +64,27 @@ async def login_for_access_token(user=Depends(my_auth)):
)
)
return
{
"
access_token
"
:
access_token
,
"
token_type
"
:
"
bearer
"
}
return
{
"
access_token
"
:
access_token
,
"
token_type
"
:
"
bearer
"
}
@app.get
(
"
/
"
,
response_model
=
List
[
dict
[
str
,
str
]])
async
def
get_types
():
"""
list types of data locations, currently datasets
(will be provided by the pillars) and targets (possible storage
locations for worklfow results or similar)
"""
return
[{
element
.
value
:
"
/
"
+
element
.
value
}
for
element
in
LocationDataType
]
@app.get
(
"
/{location_data_type}
"
)
@app.get
(
"
/{location_data_type}
"
,
response_model
=
List
[
Tuple
[
str
,
str
]]
)
async
def
list_datasets
(
location_data_type
:
LocationDataType
):
async
def
list_datasets
(
location_data_type
:
LocationDataType
):
"""
list id and name of every registered dataset for the specified type
"""
"""
list id and name of every registered dataset for the specified type
"""
return
adapter
.
get_list
(
location_data_type
)
return
adapter
.
get_list
(
location_data_type
)
@app.post
(
"
/{location_data_type}
"
)
@app.get
(
"
/{location_data_type}/{dataset_id}
"
,
response_model
=
LocationData
)
async
def
get_specific_dataset
(
location_data_type
:
LocationDataType
,
dataset_id
:
str
):
"""
returns all information about a specific dataset, identified by id
"""
return
adapter
.
get_details
(
location_data_type
,
dataset_id
)
@app.post
(
"
/{location_data_type}
"
,
response_model
=
Tuple
[
str
,
LocationData
])
async
def
add_dataset
(
location_data_type
:
LocationDataType
,
async
def
add_dataset
(
location_data_type
:
LocationDataType
,
dataset
:
LocationData
,
dataset
:
LocationData
,
user
:
User
=
Depends
(
my_user
)):
user
:
User
=
Depends
(
my_user
)):
...
@@ -88,13 +92,7 @@ async def add_dataset(location_data_type: LocationDataType,
...
@@ -88,13 +92,7 @@ async def add_dataset(location_data_type: LocationDataType,
return
adapter
.
add_new
(
location_data_type
,
dataset
,
user
.
username
)
return
adapter
.
add_new
(
location_data_type
,
dataset
,
user
.
username
)
@app.get
(
"
/{location_data_type}/{dataset_id}
"
)
@app.put
(
"
/{location_data_type}/{dataset_id}
"
,
response_model
=
Tuple
[
str
,
LocationData
])
async
def
get_specific_dataset
(
location_data_type
:
LocationDataType
,
dataset_id
:
str
):
"""
returns all information about a specific dataset, identified by id
"""
return
adapter
.
get_details
(
location_data_type
,
dataset_id
)
@app.put
(
"
/{location_data_type}/{dataset_id}
"
)
async
def
update_specific_dataset
(
location_data_type
:
LocationDataType
,
async
def
update_specific_dataset
(
location_data_type
:
LocationDataType
,
dataset_id
:
str
,
dataset
:
LocationData
,
dataset_id
:
str
,
dataset
:
LocationData
,
user
:
User
=
Depends
(
my_user
)):
user
:
User
=
Depends
(
my_user
)):
...
@@ -111,6 +109,7 @@ async def delete_specific_dataset(location_data_type: LocationDataType,
...
@@ -111,6 +109,7 @@ async def delete_specific_dataset(location_data_type: LocationDataType,
return
adapter
.
delete
(
location_data_type
,
dataset_id
,
user
.
username
)
return
adapter
.
delete
(
location_data_type
,
dataset_id
,
user
.
username
)
@app.exception_handler
(
FileNotFoundError
)
@app.exception_handler
(
FileNotFoundError
)
async
def
not_found_handler
(
request
:
Request
,
ex
:
FileNotFoundError
):
async
def
not_found_handler
(
request
:
Request
,
ex
:
FileNotFoundError
):
oid
=
request
.
path_params
.
get
(
'
dataset_id
'
,
''
)
oid
=
request
.
path_params
.
get
(
'
dataset_id
'
,
''
)
...
...
This diff is collapsed.
Click to expand it.
tests/apiserver_tests/test_apiwithauth.py
+
16
−
2
View file @
788b7a13
...
@@ -37,9 +37,7 @@ class UserTests(TestCase):
...
@@ -37,9 +37,7 @@ class UserTests(TestCase):
'
metadata
'
:
{
'
key
'
:
'
value
'
}
'
metadata
'
:
{
'
key
'
:
'
value
'
}
}
}
rsp
=
self
.
client
.
post
(
'
/dataset
'
,
json
=
my_data
)
rsp
=
self
.
client
.
post
(
'
/dataset
'
,
json
=
my_data
)
print
(
rsp
.
content
)
self
.
assertEqual
(
rsp
.
status_code
,
200
)
self
.
assertEqual
(
rsp
.
status_code
,
200
)
print
(
rsp
.
content
)
(
oid
,
dty
)
=
rsp
.
json
()
(
oid
,
dty
)
=
rsp
.
json
()
self
.
assertIsNotNone
(
oid
)
self
.
assertIsNotNone
(
oid
)
...
@@ -48,6 +46,22 @@ class UserTests(TestCase):
...
@@ -48,6 +46,22 @@ class UserTests(TestCase):
self
.
client
.
delete
(
f
"
/dataset/
{
oid
}
"
)
self
.
client
.
delete
(
f
"
/dataset/
{
oid
}
"
)
def
test_delete
(
self
):
rsp
=
self
.
client
.
delete
(
"
/dataset/foo
"
)
self
.
assertEqual
(
rsp
.
status_code
,
404
,
'
deleted called on non-existing
'
)
rsp
=
self
.
client
.
post
(
'
/dataset
'
,
json
=
{
'
name
'
:
'
some dataset
'
,
'
url
'
:
'
http://loc.me/1
'
}
)
self
.
assertEqual
(
rsp
.
status_code
,
200
)
(
oid
,
dty
)
=
rsp
.
json
()
rsp
=
self
.
client
.
delete
(
f
"
/dataset/
{
oid
}
"
)
self
.
assertEqual
(
rsp
.
status_code
,
200
)
def
test_create_and_get
(
self
):
def
test_create_and_get
(
self
):
dss
=
[{
'
name
'
:
f
"
ds_
{
i
}
"
,
'
url
'
:
f
"
http://www.o.com/
{
i
}
"
}
for
i
in
range
(
5
)]
dss
=
[{
'
name
'
:
f
"
ds_
{
i
}
"
,
'
url
'
:
f
"
http://www.o.com/
{
i
}
"
}
for
i
in
range
(
5
)]
for
d
in
dss
:
for
d
in
dss
:
...
...
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