Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
118d26dc
Commit
118d26dc
authored
Aug 30, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
Start testing for simple PUT to object directly
parent
e8663338
Changes
4
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/urls.py
View file @
118d26dc
from
django.conf.urls
import
url
,
include
from
rest_framework.routers
import
DefaultRouter
from
rest_framework.routers
import
DefaultRouter
,
DynamicRoute
,
Route
from
metagenedb.api.catalog.views
import
FunctionViewSet
,
GeneViewSet
,
TaxonomyViewSet
api_router
=
DefaultRouter
()
class
CustomRouter
(
DefaultRouter
):
routes
=
[
# List route.
Route
(
url
=
r
'^{prefix}{trailing_slash}$'
,
mapping
=
{
'get'
:
'list'
,
'put'
:
'update'
,
'post'
:
'create'
},
name
=
'{basename}-list'
,
detail
=
False
,
initkwargs
=
{
'suffix'
:
'List'
}
),
# Dynamically generated list routes. Generated using
# @action(detail=False) decorator on methods of the viewset.
DynamicRoute
(
url
=
r
'^{prefix}/{url_path}{trailing_slash}$'
,
name
=
'{basename}-{url_name}'
,
detail
=
False
,
initkwargs
=
{}
),
# Detail route.
Route
(
url
=
r
'^{prefix}/{lookup}{trailing_slash}$'
,
mapping
=
{
'get'
:
'retrieve'
,
'put'
:
'update'
,
'patch'
:
'partial_update'
,
'delete'
:
'destroy'
},
name
=
'{basename}-detail'
,
detail
=
True
,
initkwargs
=
{
'suffix'
:
'Instance'
}
),
# Dynamically generated detail routes. Generated using
# @action(detail=True) decorator on methods of the viewset.
DynamicRoute
(
url
=
r
'^{prefix}/{lookup}/{url_path}{trailing_slash}$'
,
name
=
'{basename}-{url_name}'
,
detail
=
True
,
initkwargs
=
{}
),
]
api_router
=
CustomRouter
()
api_router
.
register
(
r
'functions'
,
FunctionViewSet
,
basename
=
'functions'
)
api_router
.
register
(
r
'genes'
,
GeneViewSet
,
basename
=
'genes'
)
api_router
.
register
(
r
'taxonomy'
,
TaxonomyViewSet
,
basename
=
'taxonomy'
)
...
...
backend/metagenedb/api/catalog/views/bulk_viewset.py
View file @
118d26dc
...
...
@@ -27,3 +27,22 @@ class BulkViewSet(ModelViewSet):
self
.
_created_payload
(
serializer
,
request
),
status
=
status
.
HTTP_201_CREATED
,
headers
=
headers
)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
if
self
.
lookup_field
in
kwargs
.
keys
():
# perform the classic update
return
super
().
update
(
request
,
*
args
,
**
kwargs
)
if
isinstance
(
request
.
data
,
list
):
print
(
"this is a list man"
)
# instance = self.get_object()
# serializer = self.get_serializer(instance, data=request.data, partial=partial)
# serializer.is_valid(raise_exception=True)
# self.perform_update(serializer)
# if getattr(instance, '_prefetched_objects_cache', None):
# # If 'prefetch_related' has been applied to a queryset, we need to
# # forcibly invalidate the prefetch cache on the instance.
# instance._prefetched_objects_cache = {}
# return Response(serializer.data)
return
Response
({
'wait'
:
'for it'
})
backend/metagenedb/api/catalog/views/test_bulk_viewset.py
View file @
118d26dc
from
rest_framework.test
import
APITestCase
from
metagenedb.apps.catalog.factory
import
FunctionFactory
from
metagenedb.common.utils.mocks.metagenedb
import
MetageneDBCatalogFunctionAPIMock
...
...
@@ -50,5 +51,27 @@ class TestOperationsBulkViewSet(APITestCase):
for
element
in
data
:
self
.
assertDictEqual
(
self
.
function_api
.
get
(
element
[
'function_id'
]),
element
)
def
test_update_existing_function
(
self
):
function
=
FunctionFactory
()
data
=
{
"function_id"
:
function
.
function_id
,
"source"
:
function
.
source
,
"name"
:
"Kegg Test 1"
}
self
.
function_api
.
put
(
data
,
function
.
function_id
)
self
.
assertDictEqual
(
self
.
function_api
.
get
(
function
.
function_id
),
data
)
def
test_update_existing_functions
(
self
):
pass
data
=
[
{
"function_id"
:
"k_test1"
,
"source"
:
"kegg"
,
"name"
:
"Kegg Test 1"
},
{
"function_id"
:
"k_test2"
,
"source"
:
"kegg"
,
"name"
:
"Kegg Test 2"
}
]
print
(
self
.
function_api
.
put
(
data
))
backend/metagenedb/common/utils/mocks/metagenedb.py
View file @
118d26dc
...
...
@@ -38,9 +38,11 @@ class MetageneDBAPIMock(MetageneDBCatalogGeneAPI):
raise
HTTPError
return
response
.
json
()
def
put
(
self
,
entry_id
,
data
):
return
self
.
client
.
put
(
reverse
(
f
'
{
self
.
reverse_path
}
-detail'
,
kwargs
=
{
self
.
KEY_ID
:
entry_id
}),
data
,
format
=
'json'
).
json
()
def
put
(
self
,
data
,
entry_id
=
None
):
if
entry_id
:
return
self
.
client
.
put
(
reverse
(
f
'
{
self
.
reverse_path
}
-detail'
,
kwargs
=
{
self
.
KEY_ID
:
entry_id
}),
data
,
format
=
'json'
).
json
()
return
self
.
client
.
put
(
reverse
(
f
'
{
self
.
reverse_path
}
-list'
),
data
,
format
=
'json'
).
json
()
class
MetageneDBCatalogGeneAPIMock
(
MetageneDBAPIMock
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment