Commit 3ef8fa18 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

WebUI component:

- Fixed unit tests
parent ceb52784
Loading
Loading
Loading
Loading
+23 −39
Original line number Diff line number Diff line
@@ -34,51 +34,35 @@ class TestWebUI(ClientTestCase):
        'WTF_CSRF_ENABLED': False,
    })

    def _patch_call(self, target: str, return_value):
        patcher = mock.patch(target)
        patched_call = patcher.start()
        patched_call.return_value = return_value
        self.addCleanup(patcher.stop)
        return patched_call

    def setUp(self, client: FlaskClient) -> None:

        device_list = DeviceList()
        device_obj = device_list.devices.add() # pylint: disable=no-member
        device_obj.device_id.device_uuid.uuid = 'EMULATED'

        self.mocker_delete_device = mock.patch('webui.service.device.routes.device_client.DeleteDevice')
        self.mocker_delete_device.return_value = Empty()
        self.mocker_delete_device.start()
        self.addCleanup(self.mocker_delete_device.stop)

        self.mocker_list_context_ids = mock.patch('webui.service.device.routes.context_client.ListContextIds')
        self.mocker_list_context_ids.return_value = ContextIdList()  # returns an empty list
        self.mocker_list_context_ids.start()
        self.addCleanup(self.mocker_list_context_ids.stop)

        self.mocker_list_devices = mock.patch('webui.service.device.routes.context_client.ListDevices')
        self.mocker_list_devices.return_value = DeviceList()  # returns an empty list
        self.mocker_list_devices.start()
        self.addCleanup(self.mocker_list_devices.stop)

        self.mocker_select_device = mock.patch('webui.service.device.routes.context_client.SelectDevice')
        self.mocker_select_device.return_value = device_list
        self.mocker_select_device.start()
        self.addCleanup(self.mocker_select_device.stop)

        self.mocker_add_device = mock.patch('webui.service.device.routes.device_client.AddDevice')
        self.mocker_add_device.return_value = DeviceId()
        self.mocker_add_device.start()
        self.addCleanup(self.mocker_add_device.stop)

        self.mocker_list_topology_ids = mock.patch('webui.service.device.routes.context_client.ListTopologyIds')
        self.mocker_list_topology_ids.return_value = TopologyIdList()
        self.mocker_list_topology_ids.start()
        self.addCleanup(self.mocker_list_topology_ids.stop)

        self.mocker_main_list_contexts = mock.patch('webui.service.main.routes.context_client.ListContexts')
        self.mocker_main_list_contexts.return_value = ContextList()
        self.mocker_main_list_contexts.start()
        self.addCleanup(self.mocker_main_list_contexts.stop)

        self.mocker_main_list_topologies = mock.patch('webui.service.main.routes.context_client.ListTopologies')
        self.mocker_main_list_topologies.return_value = TopologyList()
        self.mocker_main_list_topologies.start()
        self.addCleanup(self.mocker_main_list_topologies.stop)
        self.mocker_delete_device = self._patch_call(
            'webui.service.device.routes.device_client.DeleteDevice', Empty())
        self.mocker_list_context_ids = self._patch_call(
            'webui.service.device.routes.context_client.ListContextIds', ContextIdList())
        self.mocker_list_devices = self._patch_call(
            'webui.service.device.routes.context_client.ListDevices', DeviceList())
        self.mocker_select_device = self._patch_call(
            'webui.service.device.routes.context_client.SelectDevice', device_list)
        self.mocker_add_device = self._patch_call(
            'webui.service.device.routes.device_client.AddDevice', DeviceId())
        self.mocker_list_topology_ids = self._patch_call(
            'webui.service.device.routes.context_client.ListTopologyIds', TopologyIdList())
        self.mocker_main_list_contexts = self._patch_call(
            'webui.service.main.routes.context_client.ListContexts', ContextList())
        self.mocker_main_list_topologies = self._patch_call(
            'webui.service.main.routes.context_client.ListTopologies', TopologyList())

        return super().setUp(client)