Debian Codegraph @

dirsrvtests/tests/suites/lib389/idm/user_compare_st_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import os
10 import pytest
11 from lib389._constants import DEFAULT_SUFFIX
12 from lib389.idm.group import Groups
13 from lib389.idm.user import UserAccounts, UserAccount
14 from test389.topologies import topology_st as topology
15
16 pytestmark = pytest.mark.tier1
17
18 def test_user_compare(topology):
19 """
20 Testing compare function
21
22 :id: 26f2dea9-be1e-48ca-bcea-79592823390c
23
24 :setup: Standalone instance
25
26 :steps:
27 1. Testing comparison of two different users.
28 2. Testing comparison of 'str' object with itself.
29 3. Testing comparison of user with similar user (different object id).
30 4. Testing comparison of user with group.
31
32 :expectedresults:
33 1. Should fail to compare
34 2. Should raise value error
35 3. Should be the same despite uuid difference
36 4. Should fail to compare
37 """
38 users = UserAccounts(topology.standalone, DEFAULT_SUFFIX)
39 groups = Groups(topology.standalone, DEFAULT_SUFFIX)
40 # Create 1st user
41 user1_properties = {
42 'uid': 'testuser1',
43 'cn': 'testuser1',
44 'sn': 'user',
45 'uidNumber': '1000',
46 'gidNumber': '2000',
47 'homeDirectory': '/home/testuser1'
48 }
49
50 users.create(properties=user1_properties)
51 testuser1 = users.get('testuser1')
52 # Create 2nd user
53 user2_properties = {
54 'uid': 'testuser2',
55 'cn': 'testuser2',
56 'sn': 'user',
57 'uidNumber': '1001',
58 'gidNumber': '2002',
59 'homeDirectory': '/home/testuser2'
60 }
61
62 users.create(properties=user2_properties)
63 testuser2 = users.get('testuser2')
64 # create group
65 group_properties = {
66 'cn' : 'group1',
67 'description' : 'testgroup'
68 }
69
70 testuser1_copy = users.get("testuser1")
71 group = groups.create(properties=group_properties)
72
73 assert UserAccount.compare(testuser1, testuser2) is False
74
75 with pytest.raises(ValueError):
76 UserAccount.compare("test_str_object","test_str_object")
77
78 assert UserAccount.compare(testuser1, testuser1_copy)
79 assert UserAccount.compare(testuser1, group) is False
80
81
82 if __name__ == '__main__':
83 # Run isolated
84 # -s for DEBUG mode
85 CURRENT_FILE = os.path.realpath(__file__)
86 pytest.main("-s %s" % CURRENT_FILE)