Exemplo n.º 1
0
def mock_controller(hass):
    """Mock a UniFi Controller."""
    hass.data[UNIFI_CONFIG] = {}
    controller = unifi.UniFiController(hass, None)

    controller._site_role = "admin"

    controller.api = Mock()
    controller.mock_requests = []

    controller.mock_client_responses = deque()
    controller.mock_device_responses = deque()
    controller.mock_client_all_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs["method"] = method
        kwargs["path"] = path
        controller.mock_requests.append(kwargs)
        if path == "s/{site}/stat/sta":
            return controller.mock_client_responses.popleft()
        if path == "s/{site}/stat/device":
            return controller.mock_device_responses.popleft()
        if path == "s/{site}/rest/user":
            return controller.mock_client_all_responses.popleft()
        return None

    controller.api.clients = Clients({}, mock_request)
    controller.api.devices = Devices({}, mock_request)
    controller.api.clients_all = ClientsAll({}, mock_request)

    return controller
Exemplo n.º 2
0
def mock_controller(hass):
    """Mock a UniFi Controller."""
    controller = unifi.UniFiController(hass, None)

    controller.api = Mock()
    controller.mock_requests = []

    controller.mock_client_responses = deque()
    controller.mock_device_responses = deque()

    async def mock_request(method, path, **kwargs):
        kwargs['method'] = method
        kwargs['path'] = path
        controller.mock_requests.append(kwargs)
        if path == 's/{site}/stat/sta':
            return controller.mock_client_responses.popleft()
        if path == 's/{site}/stat/device':
            return controller.mock_device_responses.popleft()
        return None

    controller.api.clients = Clients({}, mock_request)
    controller.api.devices = Devices({}, mock_request)

    return controller