Debian Codegraph @

dirsrvtests/tests/suites/clu/dsidm_bulk_update_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2023 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 ldap
10 import logging
11 import pytest
12 import os
13 from lib389._constants import DEFAULT_SUFFIX
14 from test389.topologies import topology_st as topo
15 from lib389.cli_base import FakeArgs
16 from lib389.cli_idm.account import bulk_update
17 from lib389.idm.user import UserAccounts
18
19 logging.getLogger(__name__).setLevel(logging.DEBUG)
20 log = logging.getLogger(__name__)
21
22
23 @pytest.fixture(scope="function")
24 def create_test_users(topo):
25 users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
26 u_range = list(range(5))
27 for idx in u_range:
28 try:
29 users.create(properties={
30 'uid': f'testuser{idx}',
31 'cn': f'testuser{idx}',
32 'sn': f'user{idx}',
33 'uidNumber': f'{1000 + idx}',
34 'gidNumber': f'{1000 + idx}',
35 'homeDirectory': f'/home/testuser{idx}'
36 })
37 except ldap.ALREADY_EXISTS:
38 pass
39
40
41 def test_bulk_operations(topo, create_test_users):
42 """Testing adding, replacing, an removing attribute/values to a bulk set
43 of users
44
45 :id: c89ff057-2f44-4070-8d42-850257025b2b
46 :setup: Standalone Instance
47 :steps:
48 1. Bulk add attribute
49 2. Bulk replace attribute
50 3. Bulk delete attribute
51 :expectedresults:
52 1. Success
53 2. Success
54 3. Success
55 """
56 inst = topo.standalone
57
58 args = FakeArgs()
59 args.json = False
60 args.basedn = DEFAULT_SUFFIX
61 args.scope = ldap.SCOPE_SUBTREE
62 args.filter = "(uid=*)"
63 args.stop = False
64 args.changes = []
65
66 # Test ADD
67 args.changes = ['add:objectclass:extensibleObject']
68 bulk_update(inst, DEFAULT_SUFFIX, log, args)
69 users = UserAccounts(inst, DEFAULT_SUFFIX).list()
70 for user in users:
71 assert 'extensibleobject' in user.get_attr_vals_utf8_l('objectclass')
72
73 # Test REPLACE
74 args.changes = ['replace:cn:hello_new_cn']
75 bulk_update(inst, DEFAULT_SUFFIX, log, args)
76 users = UserAccounts(inst, DEFAULT_SUFFIX).list()
77 for user in users:
78 assert user.get_attr_val_utf8_l('cn') == "hello_new_cn"
79
80 # Test DELETE
81 args.changes = ['delete:objectclass:extensibleObject']
82 bulk_update(inst, DEFAULT_SUFFIX, log, args)
83 users = UserAccounts(inst, DEFAULT_SUFFIX).list()
84 for user in users:
85 assert 'extensibleobject' not in user.get_attr_vals_utf8_l('objectclass')
86
87
88 if __name__ == '__main__':
89 # Run isolated
90 # -s for DEBUG mode
91 CURRENT_FILE = os.path.realpath(__file__)
92 pytest.main(["-s", CURRENT_FILE])