#!/usr/share/ucs-test/runner python3
## desc: move the object and modify the standard container flag at the same time
## tags: [udm,apptest]
## roles: [domaincontroller_master]
## bugs: [41694]
## exposure: dangerous
## packages:
##   - univention-config
##   - univention-directory-manager-tools


from __future__ import print_function
import univention.testing.utils as utils
import univention.testing.udm as udm_test
from univention.testing.strings import random_string

if __name__ == '__main__':
	lo = utils.get_ldap_connection()
	with udm_test.UCSTestUDM() as udm:
		for object_type in ('container/cn', 'container/ou'):
			defalt_containers = 'cn=default containers,%s' % (udm.UNIVENTION_CONTAINER,)
			print('testing', object_type)
			computerPath = lo.getAttr(defalt_containers, 'univentionComputersObject')
			userPath = lo.getAttr(defalt_containers, 'univentionUsersObject')

			utils.verify_ldap_object(defalt_containers, {'univentionUsersObject': userPath, 'univentionComputersObject': computerPath})
			old_dn = udm.create_object(object_type, **{'name': random_string(), 'computerPath': '1'})
			computerPath.append(old_dn)

			utils.verify_ldap_object(defalt_containers, {'univentionUsersObject': userPath, 'univentionComputersObject': computerPath})

			new_dn = udm.modify_object(object_type, **{'name': random_string(), 'dn': old_dn, 'computerPath': '0', 'userPath': '1'})
			computerPath.remove(old_dn)
			userPath.append(new_dn)
			utils.verify_ldap_object(defalt_containers, {'univentionUsersObject': userPath, 'univentionComputersObject': computerPath})
