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

add test for gene_length API

parent ac12a76b
Pipeline #18914 passed with stages
in 2 minutes and 10 seconds
import pandas as pd
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
import pandas as pd
from rest_framework import status
from rest_framework.test import APITestCase
from rest_framework_jwt.settings import api_settings
from metagenedb.api.catalog.views.gene import GeneViewSet
from metagenedb.apps.catalog.factory import GeneFactory
from metagenedb.common.utils.mocks.metagenedb import MetageneDBCatalogGeneAPIMock
class TestGenes(TestCase):
......@@ -66,3 +68,32 @@ class TestCountWindows(TestCase):
test_dict = geneviewset._count_windows(self.df, window_size=10,
window_col=self.window_col, stop_at=20)
self.assertDictEqual(test_dict, expected_dict)
class TestCountWindowsAPI(APITestCase):
def setUp(self):
self.gene_api = MetageneDBCatalogGeneAPIMock(self.client)
for i in range(2000, 4000, 350):
GeneFactory.create(length=i)
def test_gene_length_api(self):
expected_dict = {
'results': {
'counts': [0, 0, 3, 3],
'labels': ['<1.0k', '1.0k-2.0k', '2.0k-3.0k', '>3.0k']
}
}
self.assertDictEqual(self.gene_api.get_gene_length(), expected_dict)
def test_gene_length_api_stop_at_2000(self):
expected_dict = {
'results': {
'counts': [0, 0, 6],
'labels': ['<1.0k', '1.0k-2.0k', '>2.0k']
}
}
query_params = {
'stop_at': 2000
}
self.assertDictEqual(self.gene_api.get_gene_length(params=query_params), expected_dict)
......@@ -15,4 +15,5 @@ class GeneFactory(DjangoModelFactory):
model = models.Gene
gene_id = FuzzyLowerText(prefix='gene-', length=15)
gene_name = fuzzy.FuzzyText(prefix='name-', length=15)
length = fuzzy.FuzzyInteger(200, 10000)
......@@ -47,6 +47,13 @@ class MetageneDBCatalogGeneAPIMock(MetageneDBAPIMock):
KEY_ID = 'gene_id'
REVERSE_PATH = 'catalog:v1:genes'
def get_gene_length(self, params=None):
reverse_path = f"{self.reverse_path}-gene-length"
response = self.client.get(reverse(reverse_path), params)
if response.status_code in self.BAD_REQUESTS:
raise HTTPError
return response.json()
class MetageneDBCatalogTaxonomyAPIMock(MetageneDBAPIMock):
KEY_ID = 'gene_id'
......
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