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
c439ea81
Commit
c439ea81
authored
Aug 29, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
test creation for bulklistserializer
parent
a57a5807
Pipeline
#14056
passed with stages
in 1 minute and 46 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/urls.py
View file @
c439ea81
...
...
@@ -5,9 +5,9 @@ from metagenedb.api.catalog.views import FunctionViewSet, GeneViewSet, TaxonomyV
api_router
=
DefaultRouter
()
api_router
.
register
(
r
'functions'
,
FunctionViewSet
,
base
_
name
=
'functions'
)
api_router
.
register
(
r
'genes'
,
GeneViewSet
,
base
_
name
=
'genes'
)
api_router
.
register
(
r
'taxonomy'
,
TaxonomyViewSet
,
base
_
name
=
'taxonomy'
)
api_router
.
register
(
r
'functions'
,
FunctionViewSet
,
basename
=
'functions'
)
api_router
.
register
(
r
'genes'
,
GeneViewSet
,
basename
=
'genes'
)
api_router
.
register
(
r
'taxonomy'
,
TaxonomyViewSet
,
basename
=
'taxonomy'
)
urlpatterns
=
[
...
...
backend/metagenedb/apps/catalog/migrations/0009_meta_taxonomy.py
→
backend/metagenedb/apps/catalog/migrations/0009_meta_taxonomy
_functions
.py
View file @
c439ea81
# Generated by Django 2.2.4 on 2019-08-2
7 11:05
# Generated by Django 2.2.4 on 2019-08-2
9 09:23
from
django.db
import
migrations
...
...
@@ -10,6 +10,10 @@ class Migration(migrations.Migration):
]
operations
=
[
migrations
.
AlterModelOptions
(
name
=
'function'
,
options
=
{
'ordering'
:
[
'-function_id'
]},
),
migrations
.
AlterModelOptions
(
name
=
'taxonomy'
,
options
=
{
'ordering'
:
[
'-tax_id'
],
'verbose_name_plural'
:
'Taxonomy'
},
...
...
backend/metagenedb/apps/catalog/models/function.py
View file @
c439ea81
...
...
@@ -18,6 +18,9 @@ class Function(models.Model):
def
__str__
(
self
):
return
self
.
function_id
class
Meta
:
ordering
=
[
'-function_id'
]
class
KeggOrthology
(
Function
):
SOURCE
=
'kegg'
...
...
backend/metagenedb/apps/catalog/serializers/bulk_list.py
View file @
c439ea81
from
rest_framework
import
serializers
from
rest_framework.utils
import
model_meta
from
rest_framework.utils
import
model_meta
# noqa
class
BulkListSerializer
(
serializers
.
ListSerializer
):
...
...
backend/metagenedb/apps/catalog/serializers/test_bulk_list.py
View file @
c439ea81
...
...
@@ -2,6 +2,10 @@ from copy import deepcopy
from
unittest
import
TestCase
from
unittest.mock
import
Mock
from
rest_framework.test
import
APITestCase
from
metagenedb.common.utils.mocks.metagenedb
import
MetageneDBCatalogFunctionAPIMock
from
metagenedb.apps.catalog.serializers
import
FunctionSerializer
from
metagenedb.apps.catalog.serializers.bulk_list
import
BulkListSerializer
...
...
@@ -51,3 +55,31 @@ class TestExtractManyToMany(TestCase):
tested_list
=
self
.
bulk_list_serializer
.
_extract_many_to_many
(
self
.
data
,
self
.
info
)
self
.
assertListEqual
(
tested_list
,
expected_list
)
self
.
assertListEqual
(
ori_list
,
self
.
data
)
class
TestCreateBulk
(
APITestCase
):
"""
We are going to use an Serializer based on a real model since there are interactions with the DB.
We are using the FunctionListSerializer for the moment (through FunctionSerializer(many=True)).
"""
def
setUp
(
self
):
self
.
function_api
=
MetageneDBCatalogFunctionAPIMock
(
self
.
client
)
def
test_create_functions
(
self
):
validated_data
=
[
{
"function_id"
:
"k_test1"
,
"source"
:
"kegg"
,
"name"
:
"Kegg Test 1"
},
{
"function_id"
:
"k_test2"
,
"source"
:
"kegg"
,
"name"
:
"Kegg Test 2"
}
]
serializer
=
FunctionSerializer
(
many
=
True
)
tested_instances
=
serializer
.
create
(
validated_data
)
self
.
assertEqual
(
self
.
function_api
.
get_all
()[
'count'
],
2
)
self
.
assertEqual
(
len
(
tested_instances
),
len
(
validated_data
))
backend/metagenedb/common/utils/mocks/metagenedb.py
View file @
c439ea81
...
...
@@ -51,3 +51,8 @@ class MetageneDBCatalogGeneAPIMock(MetageneDBAPIMock):
class
MetageneDBCatalogTaxonomyAPIMock
(
MetageneDBAPIMock
):
KEY_ID
=
'gene_id'
REVERSE_PATH
=
'catalog:v1:taxonomy'
class
MetageneDBCatalogFunctionAPIMock
(
MetageneDBAPIMock
):
KEY_ID
=
'function_id'
REVERSE_PATH
=
'catalog:v1:functions'
Write
Preview
Supports
Markdown
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