summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/tests/test_orchestrator.py
blob: 53e32c85ae6eaa6753ef92cb45adfd77dc12dc0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import inspect
import unittest
from unittest import mock

from orchestrator import Orchestrator as OrchestratorBase

from ..controllers.orchestrator import Orchestrator
from ..services.orchestrator import OrchFeature
from ..tests import ControllerTestCase


class OrchestratorControllerTest(ControllerTestCase):
    URL_STATUS = '/ui-api/orchestrator/status'
    URL_INVENTORY = '/api/orchestrator/inventory'

    @classmethod
    def setup_server(cls):
        cls.setup_controllers([Orchestrator])

    @mock.patch('dashboard.controllers.orchestrator.OrchClient.instance')
    def test_status_get(self, instance):
        status = {'available': False, 'description': ''}

        fake_client = mock.Mock()
        fake_client.status.return_value = status
        instance.return_value = fake_client

        self._get(self.URL_STATUS)
        self.assertStatus(200)
        self.assertJsonBody(status)


class TestOrchestrator(unittest.TestCase):
    def test_features_has_corresponding_methods(self):
        defined_methods = [v for k, v in inspect.getmembers(
            OrchFeature, lambda m: not inspect.isroutine(m)) if not k.startswith('_')]
        orchestrator_methods = [k for k, v in inspect.getmembers(
            OrchestratorBase, inspect.isroutine)]
        for method in defined_methods:
            self.assertIn(method, orchestrator_methods)