test_function.py 1.66 KB
Newer Older
1
2
3
4
from rest_framework.test import APITestCase

import mock

5
from metagenedb.apps.catalog.factory import EggNOGv5Factory, KeggOrthologyFactory
6
7
8
from metagenedb.common.utils.mocks.metagenedb import (
    MetageneDBCatalogFunctionAPIMock, MetageneDBCatalogKeggOrthologyAPIMock
)
9
10


11
class TestKeggOrthologyViewSet(APITestCase):
12
13
14

    def setUp(self):
        self.function_api = MetageneDBCatalogFunctionAPIMock(self.client)
15
16
        self.kegg_ortho_api = MetageneDBCatalogKeggOrthologyAPIMock(self.client)
        self.kegg_function = KeggOrthologyFactory.create()
17
        self.eggnog_function = EggNOGv5Factory.create()
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

    def test_retrieve(self):
        for function in [self.kegg_function, self.eggnog_function]:
            expected_function = {
                'function_id': function.function_id,
                'name': function.name,
                'source': function.source
            }
            self.assertDictEqual(self.function_api.get(function.function_id), expected_function)

    def test_retrieve_detailed_available(self):
        query_params = {
            'detailed': 'true'
        }
        class_to_mock = 'metagenedb.api.catalog.views.function.GetFunctionExternalInfo'
        detailed_kegg = {
            'function_id': self.kegg_function.function_id,
            'name': self.kegg_function.name,
            'details': 'some details'
        }
        with mock.patch(class_to_mock) as MockGetFunctionExternalInfo:
            MockGetFunctionExternalInfo.return_value.get_details.return_value = detailed_kegg
40
            tested_dict = self.kegg_ortho_api.get(self.kegg_function.function_id, params=query_params)
41
        self.assertDictEqual(tested_dict, detailed_kegg)