Skip to content

Commit

Permalink
test: add TestDiagnosticCharacteristic
Browse files Browse the repository at this point in the history
  • Loading branch information
posterzh committed Nov 24, 2021
1 parent eed9261 commit 3108262
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions tests/gatewayconfig/bluetooth/test_diagnostics_characteristic.py
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()

0 comments on commit 3108262

Please sign in to comment.