1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add tests

This commit is contained in:
Kelly Brazil
2022-02-25 11:19:20 -08:00
parent 7b9722d255
commit 554ca61d17
11 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1 @@
[{"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","type":"ethernet","timestamp":1645643581,"timestamp_real":"Wed 23 Feb 2022 11:13:01 AM PST","autoconnect":"yes","autoconnect_priority":0,"readonly":"no","dbus_path":"/org/freedesktop/NetworkManager/Settings/1","active":"yes","device":"ens33","state":"activated","active_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","slave":null,"filename":"/etc/sysconfig/network-scripts/ifcfg-ens33"}]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[{"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","type":"ethernet","device":"ens33"}]

View File

@ -0,0 +1 @@
[{"device":"ens33","type":"ethernet","state":"connected","ip4_connectivity":"full","ip6_connectivity":"full","dbus_path":"/org/freedesktop/NetworkManager/Devices/2","connection":"ens33","con_uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1"},{"device":"docker0","type":"bridge","state":"unmanaged","ip4_connectivity":"unknown","ip6_connectivity":"unknown","dbus_path":"/org/freedesktop/NetworkManager/Devices/3","connection":null,"con_uuid":null,"con_path":null},{"device":"lo","type":"loopback","state":"unmanaged","ip4_connectivity":"unknown","ip6_connectivity":"unknown","dbus_path":"/org/freedesktop/NetworkManager/Devices/1","connection":null,"con_uuid":null,"con_path":null}]

View File

@ -0,0 +1 @@
[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:3B:58:0E","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","wired_properties_carrier":"on","ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}}]

View File

@ -0,0 +1 @@
[{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null}]

View File

@ -0,0 +1 @@
[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:3B:58:0E","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","wired_properties_carrier":"on","ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}},{"device":"docker0","type":"bridge","hwaddr":"02:42:99:67:E8:21","mtu":1500,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"172.17.0.1/16","ip4_gateway":null,"ip4_route_1":{"dst":"172.17.0.0/16","nh":"0.0.0.0","mt":0},"ip6_gateway":null},{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null}]

View File

@ -0,0 +1 @@
[{"device":"ens33","type":"ethernet","state":"connected","connection":"ens33"},{"device":"docker0","type":"bridge","state":"unmanaged","connection":null},{"device":"lo","type":"loopback","state":"unmanaged","connection":null}]

View File

@ -0,0 +1 @@
[{"running":"running","version":"1.18.0","state":"connected","startup":"started","connectivity":"full","networking":"enabled","wifi_hw":"enabled","wifi":"enabled","wwan_hw":"enabled","wwan":"enabled"}]

View File

@ -0,0 +1 @@
[{"org_freedesktop_networkmanager_enable_disable_network":"yes","org_freedesktop_networkmanager_enable_disable_wifi":"yes","org_freedesktop_networkmanager_enable_disable_wwan":"yes","org_freedesktop_networkmanager_enable_disable_wimax":"yes","org_freedesktop_networkmanager_sleep_wake":"yes","org_freedesktop_networkmanager_network_control":"yes","org_freedesktop_networkmanager_wifi_share_protected":"yes","org_freedesktop_networkmanager_wifi_share_open":"yes","org_freedesktop_networkmanager_settings_modify_system":"yes","org_freedesktop_networkmanager_settings_modify_own":"yes","org_freedesktop_networkmanager_settings_modify_hostname":"yes","org_freedesktop_networkmanager_settings_modify_global_dns":"yes","org_freedesktop_networkmanager_reload":"yes","org_freedesktop_networkmanager_checkpoint_rollback":"yes","org_freedesktop_networkmanager_enable_disable_statistics":"yes","org_freedesktop_networkmanager_enable_disable_connectivity_check":"yes","org_freedesktop_networkmanager_wifi_scan":"unknown"}]

155
tests/test_nmcli.py Normal file
View File

@ -0,0 +1,155 @@
import os
import unittest
import json
import jc.parsers.nmcli
from jc.exceptions import ParseError
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_connection_all = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_connection_show_ens33 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_connection = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-all.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_all = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-ens33.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_show_ens33 = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-lo.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_show_lo = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_show = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-all.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_general_all = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.out'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_general_permissions = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_connection_all_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_connection_show_ens33_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_connection_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-all.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_all_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-ens33.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_show_ens33_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-lo.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_show_lo_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_show_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_device_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-all.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_general_all_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.json'), 'r', encoding='utf-8') as f:
self.centos_7_7_nmcli_general_permissions_json = json.loads(f.read())
def test_nmcli_nodata(self):
"""
Test 'nmcli' with no data
"""
self.assertEqual(jc.parsers.nmcli.parse('', quiet=True), [])
def test_nmcli_centos_7_7(self):
"""
Test 'nmcli' on Centos 7.7 - this should raise a ParseError exception
"""
self.assertRaises(ParseError, jc.parsers.nmcli.parse, self.centos_7_7_nmcli, quiet=True)
def test_nmcli_connection_all_centos_7_7(self):
"""
Test 'nmcli -f all connection' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection_all, quiet=True), self.centos_7_7_nmcli_connection_all_json)
def test_nmcli_connection_show_ens33_centos_7_7(self):
"""
Test 'nmcli connection show ens33' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection_show_ens33, quiet=True), self.centos_7_7_nmcli_connection_show_ens33_json)
def test_nmcli_connection_centos_7_7(self):
"""
Test 'nmcli connection' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection, quiet=True), self.centos_7_7_nmcli_connection_json)
def test_nmcli_device_all_centos_7_7(self):
"""
Test 'nmcli -f all device' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_all, quiet=True), self.centos_7_7_nmcli_device_all_json)
def test_nmcli_device_show_ens33_centos_7_7(self):
"""
Test 'nmcli device show ens33' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show_ens33, quiet=True), self.centos_7_7_nmcli_device_show_ens33_json)
def test_nmcli_device_show_lo_centos_7_7(self):
"""
Test 'nmcli device show lo' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show_lo, quiet=True), self.centos_7_7_nmcli_device_show_lo_json)
def test_nmcli_device_show_centos_7_7(self):
"""
Test 'nmcli device show' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show, quiet=True), self.centos_7_7_nmcli_device_show_json)
def test_nmcli_device_centos_7_7(self):
"""
Test 'nmcli device' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device, quiet=True), self.centos_7_7_nmcli_device_json)
def test_nmcli_general_all_centos_7_7(self):
"""
Test 'nmcli -f all general' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_all, quiet=True), self.centos_7_7_nmcli_general_all_json)
def test_nmcli_general_permissions_centos_7_7(self):
"""
Test 'nmcli general permissions' on Centos 7.7
"""
self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_permissions, quiet=True), self.centos_7_7_nmcli_general_permissions_json)
if __name__ == '__main__':
unittest.main()