Skip to content

Commit

Permalink
Add tests for updated functions in proxy
Browse files Browse the repository at this point in the history
- test_has_service_state_in
- test_extract_manual_proxy
  • Loading branch information
guyonvarch committed Nov 8, 2023
1 parent 462e2c4 commit 6058d0b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions kiosk/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Then, start the kiosk browser with, for example:
bin/kiosk-browser http://localhost:8080/play.html http://localhost:3333
```

## Testing

bin/test

## Developer tools

Run with `QTWEBENGINE_REMOTE_DEBUGGING` equals to a specific port:
Expand Down
5 changes: 5 additions & 0 deletions kiosk/bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."

python -m pytest
1 change: 1 addition & 0 deletions kiosk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ python3Packages.buildPythonApplication rec {
requests
dbus-python
pygobject3
pytest
];

postInstall = ''
Expand Down
2 changes: 2 additions & 0 deletions kiosk/kiosk_browser/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def get_current_proxy(bus):
# the list. (From connman doc/overview-api.txt)
default_service = find(lambda s: has_service_state_in(s, ['online', 'ready']), services)

print(default_service)

if default_service:
return extract_manual_proxy(default_service)

Expand Down
21 changes: 21 additions & 0 deletions kiosk/kiosk_browser/test_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import dbus
from kiosk_browser import proxy

# Mocks

service_idle = dbus.Struct((dbus.ObjectPath('/net/connman/service/wifi_a0510b58100d_517561657374791f6e657e2d4d7060046065_managed_psk'), dbus.Dictionary({dbus.String('Type'): dbus.String('wifi', variant_level=1), dbus.String('Security'): dbus.Array([dbus.String('psk')], signature=dbus.Signature('s'), variant_level=1), dbus.String('State'): dbus.String('idle', variant_level=1), dbus.String('Strength'): dbus.Byte(54, variant_level=1), dbus.String('Favorite'): dbus.Boolean(False, variant_level=1), dbus.String('Immutable'): dbus.Boolean(False, variant_level=1), dbus.String('AutoConnect'): dbus.Boolean(False, variant_level=1), dbus.String('Name'): dbus.String('Super-Network', variant_level=1), dbus.String('Ethernet'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Interface'): dbus.String('wlp2s0', variant_level=1), dbus.String('Address'): dbus.String('B7:71:01:51:10:AD', variant_level=1), dbus.String('MTU'): dbus.UInt16(1500, variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv4'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv4.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv6'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv6.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Privacy'): dbus.String('prefered', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('Nameservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Timeservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Domains'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Proxy'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('Proxy.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('direct', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('mDNS'): dbus.Boolean(False, variant_level=1), dbus.String('mDNS.Configuration'): dbus.Boolean(False, variant_level=1), dbus.String('Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None)

service_online_direct = dbus.Struct((dbus.ObjectPath('/net/connman/service/wifi_a0510b58100d_517561657374791f6e657e2d4d7060046065_managed_psk'), dbus.Dictionary({dbus.String('Type'): dbus.String('wifi', variant_level=1), dbus.String('Security'): dbus.Array([dbus.String('psk')], signature=dbus.Signature('s'), variant_level=1), dbus.String('State'): dbus.String('online', variant_level=1), dbus.String('Strength'): dbus.Byte(53, variant_level=1), dbus.String('Favorite'): dbus.Boolean(True, variant_level=1), dbus.String('Immutable'): dbus.Boolean(False, variant_level=1), dbus.String('AutoConnect'): dbus.Boolean(True, variant_level=1), dbus.String('Name'): dbus.String('Super-Network', variant_level=1), dbus.String('Ethernet'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Interface'): dbus.String('wlp2s0', variant_level=1), dbus.String('Address'): dbus.String('B7:71:01:51:10:AD', variant_level=1), dbus.String('MTU'): dbus.UInt16(1500, variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv4'): dbus.Dictionary({dbus.String('Method'): dbus.String('dhcp', variant_level=1), dbus.String('Address'): dbus.String('192.168.1.1', variant_level=1), dbus.String('Netmask'): dbus.String('255.255.255.0', variant_level=1), dbus.String('Gateway'): dbus.String('192.168.1.254', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv4.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv6'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Address'): dbus.String('0a21:e0f:5ba:7390:3304:872c:531c:cbad', variant_level=1), dbus.String('PrefixLength'): dbus.Byte(64, variant_level=1), dbus.String('Privacy'): dbus.String('prefered', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv6.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Privacy'): dbus.String('prefered', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('Nameservers'): dbus.Array([dbus.String('192.168.1.254')], signature=dbus.Signature('s'), variant_level=1), dbus.String('Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Timeservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Domains'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Proxy'): dbus.Dictionary({dbus.String('Method'): dbus.String('direct', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('Proxy.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('direct', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('mDNS'): dbus.Boolean(False, variant_level=1), dbus.String('mDNS.Configuration'): dbus.Boolean(False, variant_level=1), dbus.String('Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None)

service_online_proxy = dbus.Struct((dbus.ObjectPath('/net/connman/service/wifi_a0510b58100d_517561657374791f6e657e2d4d7060046065_managed_psk'), dbus.Dictionary({dbus.String('Type'): dbus.String('wifi', variant_level=1), dbus.String('Security'): dbus.Array([dbus.String('psk')], signature=dbus.Signature('s'), variant_level=1), dbus.String('State'): dbus.String('online', variant_level=1), dbus.String('Strength'): dbus.Byte(51, variant_level=1), dbus.String('Favorite'): dbus.Boolean(True, variant_level=1), dbus.String('Immutable'): dbus.Boolean(False, variant_level=1), dbus.String('AutoConnect'): dbus.Boolean(True, variant_level=1), dbus.String('Name'): dbus.String('Super-Network', variant_level=1), dbus.String('Ethernet'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Interface'): dbus.String('wlp2s0', variant_level=1), dbus.String('Address'): dbus.String('B7:71:01:51:10:AD', variant_level=1), dbus.String('MTU'): dbus.UInt16(1500, variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv4'): dbus.Dictionary({dbus.String('Method'): dbus.String('dhcp', variant_level=1), dbus.String('Address'): dbus.String('192.168.1.1', variant_level=1), dbus.String('Netmask'): dbus.String('255.255.255.0', variant_level=1), dbus.String('Gateway'): dbus.String('192.168.1.254', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv4.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('dhcp', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv6'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Address'): dbus.String('0a21:e0f:5ba:7390:3304:872c:531c:cbad', variant_level=1), dbus.String('PrefixLength'): dbus.Byte(64, variant_level=1), dbus.String('Privacy'): dbus.String('prefered', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('IPv6.Configuration'): dbus.Dictionary({dbus.String('Method'): dbus.String('auto', variant_level=1), dbus.String('Privacy'): dbus.String('prefered', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('Nameservers'): dbus.Array([dbus.String('192.168.1.254')], signature=dbus.Signature('s'), variant_level=1), dbus.String('Nameservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Timeservers'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Timeservers.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Domains'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Domains.Configuration'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Proxy'): dbus.Dictionary({dbus.String('Servers'): dbus.Array([dbus.String('http://proxy.dividat.com:1234')], signature=dbus.Signature('s'), variant_level=1), dbus.String('Excludes'): dbus.Array([], signature=dbus.Signature('s'), variant_level=1), dbus.String('Method'): dbus.String('manual', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('Proxy.Configuration'): dbus.Dictionary({dbus.String('Servers'): dbus.Array([dbus.String('http://proxy.dividat.com')], signature=dbus.Signature('s'), variant_level=1), dbus.String('Method'): dbus.String('manual', variant_level=1)}, signature=dbus.Signature('sv'), variant_level=1), dbus.String('mDNS'): dbus.Boolean(False, variant_level=1), dbus.String('mDNS.Configuration'): dbus.Boolean(False, variant_level=1), dbus.String('Provider'): dbus.Dictionary({}, signature=dbus.Signature('sv'), variant_level=1)}, signature=dbus.Signature('sv'))), signature=None)

# Tests

def test_has_service_state_in():
assert proxy.has_service_state_in(service_idle, ['online', 'ready']) == False
assert proxy.has_service_state_in(service_online_direct, ['online', 'ready']) == True

def test_extract_manual_proxy():
assert proxy.extract_manual_proxy(service_idle) == None
assert proxy.extract_manual_proxy(service_online_direct) == None
assert proxy.extract_manual_proxy(service_online_proxy) == proxy.ProxyConfig('proxy.dividat.com', 1234, None, None)

0 comments on commit 6058d0b

Please sign in to comment.