-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/gatewayconfig/bluetooth/test_wifi_configured_services_characteristic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from nmcli import Connection | ||
from gatewayconfig.bluetooth.characteristics.wifi_configured_services_characteristic import \ | ||
WifiConfiguredServicesCharacteristic | ||
from gatewayconfig.gatewayconfig_shared_state import GatewayconfigSharedState | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
from gatewayconfig.helpers import string_to_dbus_byte_array | ||
from lib.cputemp.service import Service | ||
|
||
|
||
class TestWifiConfiguredServicesCharacteristic(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.service = Service(201, '1111', True) | ||
|
||
@patch('lib.nmcli_custom.connection', | ||
return_value=[ | ||
Connection(name='supervisor0', uuid='00000005-0006-0007-0008-000000000009', | ||
conn_type='bridge', device='supervisor0'), | ||
Connection(name='TP-LINK', uuid='00000001-0002-0003-0004-000000000005', | ||
conn_type='wifi', device='wlan0'), | ||
Connection(name='Wired connection 1', uuid='0000000a-000b-000c-000d-00000000000e', | ||
conn_type='ethernet', device='eth0') | ||
]) | ||
def test_ReadValue(self, mock1): | ||
characteristic = WifiConfiguredServicesCharacteristic( | ||
self.service, | ||
GatewayconfigSharedState()) | ||
wifi_configured_services = characteristic.ReadValue({}) | ||
|
||
expected = string_to_dbus_byte_array(b'\n\x07TP-LINK') | ||
self.assertEqual(wifi_configured_services, expected) |
32 changes: 32 additions & 0 deletions
32
tests/gatewayconfig/bluetooth/test_wifi_connect_characteristic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import dbus | ||
|
||
from gatewayconfig.bluetooth.characteristics.wifi_connect_characteristic import \ | ||
WifiConnectCharacteristic | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
from gatewayconfig.helpers import string_to_dbus_byte_array | ||
from lib.cputemp.service import Service | ||
|
||
|
||
class TestWifiConnectCharacteristic(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.service = Service(202, '1111', True) | ||
|
||
@patch('gatewayconfig.bluetooth.characteristics.wifi_connect_characteristic.CommandThread') | ||
def test_WriteValue(self, mock1): | ||
try: | ||
with self.assertLogs( | ||
'gatewayconfig.bluetooth.characteristics', | ||
level='DEBUG') as cm: | ||
characteristic = WifiConnectCharacteristic(self.service) | ||
characteristic.WriteValue( | ||
dbus.Array(string_to_dbus_byte_array(b'\n\fTP-LINK_4672\x12\t123456789'), | ||
signature='y'), {}) | ||
|
||
self.assertGreaterEqual(len(cm.output), 2) | ||
self.assertIn('Write WiFi Connect', cm.output[0]) | ||
self.assertIn('Connecting to TP-LINK_4672 is started', cm.output[1]) | ||
except Exception as e: | ||
self.fail("Unexpected exception while testing WifiRemoveCharacteristic: %s" % str(e)) |
28 changes: 28 additions & 0 deletions
28
tests/gatewayconfig/bluetooth/test_wifi_remove_characteristic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from gatewayconfig.bluetooth.characteristics.wifi_remove_characteristic import \ | ||
WifiRemoveCharacteristic | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
from gatewayconfig.helpers import string_to_dbus_byte_array | ||
from lib.cputemp.service import Service | ||
|
||
|
||
class TestWifiRemoveCharacteristic(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.service = Service(203, '1111', True) | ||
|
||
@patch('lib.nmcli_custom.connection.delete') | ||
def test_WriteValue(self, mock1): | ||
try: | ||
with self.assertLogs( | ||
'gatewayconfig.bluetooth.characteristics.wifi_remove_characteristic', | ||
level='DEBUG') as cm: | ||
characteristic = WifiRemoveCharacteristic(self.service) | ||
characteristic.WriteValue(string_to_dbus_byte_array(b'\n\x07TP-LINK'), {}) | ||
|
||
self.assertEqual(len(cm.output), 2) | ||
self.assertIn('Write WiFi Remove', cm.output[0]) | ||
self.assertIn('Connection TP-LINK should be deleted', cm.output[1]) | ||
except Exception as e: | ||
self.fail("Unexpected exception while testing WifiRemoveCharacteristic: %s" % str(e)) |
30 changes: 30 additions & 0 deletions
30
tests/gatewayconfig/bluetooth/test_wifi_services_characteristic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from nmcli import DeviceWifi | ||
from gatewayconfig.bluetooth.characteristics.wifi_services_characteristic import \ | ||
WifiServicesCharacteristic | ||
from gatewayconfig.gatewayconfig_shared_state import GatewayconfigSharedState | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
from gatewayconfig.helpers import string_to_dbus_byte_array | ||
from lib.cputemp.service import Service | ||
|
||
|
||
class TestWifiServicesCharacteristic(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.service = Service(204, '1111', True) | ||
|
||
@patch('lib.nmcli_custom.device.wifi_rescan') | ||
@patch('lib.nmcli_custom.device.wifi', | ||
return_value=[ | ||
DeviceWifi(in_use=False, ssid='TP-LINK', mode='Infra', chan=5, rate=54, signal=100, | ||
security='WPA1'), | ||
DeviceWifi(in_use=True, ssid='PHICOMM', mode='Infra', chan=1, rate=44, signal=96, | ||
security='WPA2') | ||
]) | ||
def test_ReadValue(self, mock1, mock2): | ||
characteristic = WifiServicesCharacteristic(self.service, GatewayconfigSharedState()) | ||
wifi_services = characteristic.ReadValue({}) | ||
|
||
expected = string_to_dbus_byte_array(b'\n\x07TP-LINK\n\x07PHICOMM') | ||
self.assertEqual(wifi_services, expected) |
29 changes: 29 additions & 0 deletions
29
tests/gatewayconfig/bluetooth/test_wifi_ssid_characteristic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from nmcli import DeviceWifi | ||
from gatewayconfig.bluetooth.characteristics.wifi_ssid_characteristic import WifiSSIDCharacteristic | ||
from gatewayconfig.gatewayconfig_shared_state import GatewayconfigSharedState | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
from gatewayconfig.helpers import string_to_dbus_byte_array | ||
from lib.cputemp.service import Service | ||
|
||
|
||
class TestWifiSSIDCharacteristic(TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.service = Service(205, '1111', True) | ||
|
||
@patch('lib.nmcli_custom.device.wifi_rescan') | ||
@patch('lib.nmcli_custom.device.wifi', | ||
return_value=[ | ||
DeviceWifi(in_use=False, ssid='TP-LINK', mode='Infra', chan=5, rate=54, signal=100, | ||
security='WPA1'), | ||
DeviceWifi(in_use=True, ssid='PHICOMM', mode='Infra', chan=1, rate=44, signal=96, | ||
security='WPA2') | ||
]) | ||
def test_ReadValue(self, mock1, mock2): | ||
characteristic = WifiSSIDCharacteristic(self.service, GatewayconfigSharedState()) | ||
wifi_ssid = characteristic.ReadValue({}) | ||
|
||
expected = string_to_dbus_byte_array(b'PHICOMM') | ||
self.assertEqual(wifi_ssid, expected) |