1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-10-08 23:22:21 +02:00
Files
jc/tests/test_route_print.py
Jose E. Rodriguez 3b1af1a9b6 Feat: Introduce net-localgroup net-user and route-print parsers (#602)
* feat(patch): introduce net localgroup, net user, and route print parsers

* fix: fix net user parsing error

* fix: address PR findings

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
2025-09-04 14:47:28 -07:00

51 lines
1.6 KiB
Python

import json
import os
import unittest
import jc.parsers.ipconfig
import jc.parsers.net_localgroup
import jc.parsers.route_print
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
test_files = [
"tests/fixtures/windows/windows-xp/route_print",
"tests/fixtures/windows/windows-7/route_print",
"tests/fixtures/windows/windows-2008/route_print",
"tests/fixtures/windows/windows-2016/route_print",
"tests/fixtures/windows/windows-10/route_print",
"tests/fixtures/windows/windows-11/route_print"
]
def setUp(self):
for tf in MyTests.test_files:
in_file = os.path.join(THIS_DIR, os.pardir, f"{tf}.out")
out_file = os.path.join(THIS_DIR, os.pardir, f"{tf}.json")
with open(in_file, "r", encoding="utf-8") as f:
setattr(self, self.varName(tf), f.read())
with open(out_file, "r", encoding="utf-8") as f:
setattr(self, self.varName(tf) + "_json", json.loads(f.read()))
def varName(self, path):
return (
path.replace("tests/fixtures/windows", "")
.replace("-", "_")
.replace("/", "_")
)
def test_windows_route_print(self):
"""
Test a sample Windows "route print" command output
"""
for tf in MyTests.test_files:
in_var = getattr(self, self.varName(tf))
out_var = getattr(self, self.varName(tf) + "_json")
self.assertEqual(jc.parsers.route_print.parse(in_var, quiet=True), out_var)
if __name__ == "__main__":
unittest.main()