Newer
Older
# Copyright 2019 Dom Sekotill <dom.sekotill@kodo.org.uk>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Test cases for wpa_supplicant.client.interfaces.InterfaceClient
"""
import unittest
import anyio
from tests.unit import anyio as anyio_mock
from wpa_supplicant.client import interfaces
class MethodsTests(unittest.TestCase):
"""
Tests for InterfaceClient methods
"""
def setUp(self):
async def _make_client():
return interfaces.InterfaceClient()
self.client = client = anyio.run(_make_client)
client.sock = anyio_mock.AsyncMock()
client.sock.send.side_effect = len
@anyio_mock.with_anyio()
async def test_scan(self):
"""
Check that a scan command waits for a notification then terminates correctly
"""
async with self.client as client:
client.sock.recv.side_effect = [
b"OK", # Response to "ATTACH"
b"OK", # Response to "SCAN"
b"<3>CTRL-EVENT-SCAN-RESULTS",
b"good=value\nid=1\n", # Response to "BSS 1"
b"good=value\nid=2\n", # Response to "BSS 2"
b"", # Response to "BSS 3"
b"OK", # Response to "DETACH"
]
async for bss in client.scan():
self.assertIsInstance(bss, dict)