Commit c439ea81 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

test creation for bulklistserializer

parent a57a5807
Pipeline #14056 passed with stages
in 1 minute and 46 seconds
......@@ -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 = [
......
# Generated by Django 2.2.4 on 2019-08-27 11:05
# Generated by Django 2.2.4 on 2019-08-29 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'},
......
......@@ -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'
......
from rest_framework import serializers
from rest_framework.utils import model_meta
from rest_framework.utils import model_meta # noqa
class BulkListSerializer(serializers.ListSerializer):
......
......@@ -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))
......@@ -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'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment