File: test_id.py

package info (click to toggle)
jc 1.25.4-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 101,000 kB
  • sloc: python: 69,889; sh: 722; xml: 278; makefile: 5
file content (84 lines) | stat: -rw-r--r-- 3,318 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import json
import unittest
import jc.parsers.id

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


class MyTests(unittest.TestCase):

    # input
    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/id.out'), 'r', encoding='utf-8') as f:
        centos_7_7_id = f.read()

    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/id.out'), 'r', encoding='utf-8') as f:
        osx_10_14_6_id = f.read()

    # output
    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/id.json'), 'r', encoding='utf-8') as f:
        centos_7_7_id_json = json.loads(f.read())

    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/id.json'), 'r', encoding='utf-8') as f:
        osx_10_14_6_id_json = json.loads(f.read())


    def test_id_nodata(self):
        """
        Test 'id' with no data
        """
        self.assertEqual(jc.parsers.id.parse('', quiet=True), {})

    def test_id_no_name(self):
        """
        Test 'id' with no name
        """
        self.assertEqual(
            jc.parsers.id.parse('uid=1000 gid=1000 groups=1000,10', quiet=True),
            {'uid': {'id': 1000, 'name': None}, 'gid': {'id': 1000, 'name': None}, 'groups': [{'id': 1000, 'name': None}, {'id': 10, 'name': None}]}
        )

        self.assertEqual(
            jc.parsers.id.parse('uid=1000(user) gid=1000 groups=1000,10(wheel)', quiet=True),
            {'uid': {'id': 1000, 'name': 'user'}, 'gid': {'id': 1000, 'name': None}, 'groups': [{'id': 1000, 'name': None}, {'id': 10, 'name': 'wheel'}]}
        )

    def test_id_space(self):
        """
        Test 'id' with with space in name
        """
        self.assertEqual(
            jc.parsers.id.parse('uid=1000(user 1) gid=1000 groups=1000,10(wheel)', quiet=True),
            {'uid': {'id': 1000, 'name': 'user 1'}, 'gid': {'id': 1000, 'name': None}, 'groups': [{'id': 1000, 'name': None}, {'id': 10, 'name': 'wheel'}]}
        )

        self.assertEqual(
            jc.parsers.id.parse('uid=1000(user) gid=1000(group 1) groups=1000,10(wheel)', quiet=True),
            {'uid': {'id': 1000, 'name': 'user'}, 'gid': {'id': 1000, 'name': 'group 1'}, 'groups': [{'id': 1000, 'name': None}, {'id': 10, 'name': 'wheel'}]}
        )

        self.assertEqual(
            jc.parsers.id.parse('uid=1000(user) gid=1000 groups=1000,10(wheel 1)', quiet=True),
            {'uid': {'id': 1000, 'name': 'user'}, 'gid': {'id': 1000, 'name': None}, 'groups': [{'id': 1000, 'name': None}, {'id': 10, 'name': 'wheel 1'}]}
        )

        self.assertEqual(
            jc.parsers.id.parse('uid=1000(user 1) gid=1000(group 1) groups=1000,10(wheel 1)', quiet=True),
            {'uid': {'id': 1000, 'name': 'user 1'}, 'gid': {'id': 1000, 'name': 'group 1'}, 'groups': [{'id': 1000, 'name': None}, {'id': 10, 'name': 'wheel 1'}]}
        )

    def test_id_centos_7_7(self):
        """
        Test 'id' on Centos 7.7
        """
        self.assertEqual(jc.parsers.id.parse(self.centos_7_7_id, quiet=True), self.centos_7_7_id_json)

    def test_id_osx_10_14_6(self):
        """
        Test 'id' on OSX 10.14.6
        """
        self.assertEqual(jc.parsers.id.parse(self.osx_10_14_6_id, quiet=True), self.osx_10_14_6_id_json)


if __name__ == '__main__':
    unittest.main()