-
-
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.
test: add TestDiagnosticCharacteristic
- Loading branch information
Showing
1 changed file
with
36 additions
and
13 deletions.
There are no files selected for viewing
49 changes: 36 additions & 13 deletions
49
tests/gatewayconfig/bluetooth/test_diagnostics_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 |
---|---|---|
@@ -1,31 +1,54 @@ | ||
import pytest | ||
import sys | ||
import uuid | ||
from io import StringIO | ||
from lib.cputemp.service import Service | ||
|
||
from unittest import TestCase | ||
import dbus | ||
import dbus.mainloop.glib | ||
from unittest.mock import patch, mock_open | ||
|
||
from gatewayconfig.bluetooth.characteristics.diagnostics_characteristic import DiagnosticsCharacteristic | ||
|
||
from unittest.mock import patch, Mock | ||
from gatewayconfig.bluetooth.characteristics.diagnostics_characteristic \ | ||
import DiagnosticsCharacteristic | ||
|
||
# Should correspond with BluetoothConnectionAdvertisement.ADVERTISEMENT_SERVICE_UUID | ||
DEFAULT_SERVICE_UUID = '0fda92b2-44a2-4af2-84f5-fa682baa2b8d' | ||
VALID_LE_ADVERTISEMENT_IFACE = 'org.bluez.LEAdvertisement1' | ||
INVALID_LE_ADVERTISEMENT_IFACE = 'org.fake.iface' | ||
|
||
|
||
class TestDiagnosticCharacteristic(TestCase): | ||
|
||
# Prevent error log diff from being trimmed | ||
maxDiff = None | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.service = Service(200, '1111', True) | ||
|
||
def test_instantiation(self): | ||
service = Service(200, '1111', True) | ||
diagnostics_characteristic = DiagnosticsCharacteristic(service, | ||
diagnostics_characteristic = DiagnosticsCharacteristic(self.service, | ||
'A1:B2:C3:DD:E5:F6', | ||
'B1:B2:C3:DD:E5:F6', | ||
'2021.06.26.4') | ||
self.assertIsInstance(diagnostics_characteristic, DiagnosticsCharacteristic) | ||
|
||
@patch('dbus.SessionBus') | ||
@patch('dbus.Interface', return_value=Mock( | ||
P2PStatus=Mock(return_value={ | ||
'connected': '1', | ||
'dialable': '0', | ||
'height': '100', | ||
'nat_type': 'NAT', | ||
}))) | ||
def test_get_p2pstatus(self, mock_dbus_session_bus, mock_dbus_interface): | ||
diagnostics_characteristic = DiagnosticsCharacteristic(self.service, | ||
'A1:B2:C3:DD:E5:F6', | ||
'B1:B2:C3:DD:E5:F6', | ||
'2021.06.26.4') | ||
p2pstatus = diagnostics_characteristic.get_p2pstatus() | ||
print("p2pstatus: %s" % p2pstatus) | ||
|
||
expected = { | ||
'connected': '1', | ||
'dialable': '0', | ||
'height': '100', | ||
'nat_type': 'NAT', | ||
} | ||
self.assertDictEqual(p2pstatus, expected) | ||
|
||
mock_dbus_session_bus.assert_called() | ||
mock_dbus_interface.assert_called() |