1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-12-20 00:23:11 +02:00
Files
jc/tests/test_net_user.py

57 lines
2.0 KiB
Python
Raw Normal View History

import json
import os
import unittest
import jc.parsers.ipconfig
import jc.parsers.net_localgroup
import jc.parsers.net_user
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
test_files = [
"tests/fixtures/windows/windows-xp/net_user",
"tests/fixtures/windows/windows-xp/net_user.administrator",
"tests/fixtures/windows/windows-7/net_user",
"tests/fixtures/windows/windows-7/net_user.administrator",
"tests/fixtures/windows/windows-2008/net_user",
"tests/fixtures/windows/windows-2008/net_user.administrator",
"tests/fixtures/windows/windows-2016/net_user.administrators",
"tests/fixtures/windows/windows-2016/net_user",
"tests/fixtures/windows/windows-10/net_user",
"tests/fixtures/windows/windows-10/net_user.administrator",
"tests/fixtures/windows/windows-11/net_user",
"tests/fixtures/windows/windows-11/net_user.administrator"
]
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_net_localgroup(self):
"""
Test a sample Windows "net localgroup" 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.net_user.parse(in_var, quiet=True), out_var)
if __name__ == "__main__":
unittest.main()