#!/usr/share/ucs-test/runner python3
## desc: Create a usertemplate object and remove it
## tags: [udm-ldapextensions,apptest]
## roles: [domaincontroller_master]
## exposure: dangerous
## packages:
##   - univention-directory-manager-tools

import univention.testing.utils as utils
import univention.testing.udm as udm_test
import univention.testing.strings as uts

if __name__ == '__main__':
	with udm_test.UCSTestUDM() as udm:
		template_name = uts.random_name()
		try:
			template = udm.create_object('settings/usertemplate', name=template_name)
			utils.verify_ldap_object(template, {'cn': [template_name]})
		except udm_test.UCSTestUDM_CreateUDMObjectFailed as exc:
			utils.fail('settings/usertemplate could not be created: {}'.format(exc))
		except utils.LDAPObjectNotFound as exc:
			utils.fail('settings/usertemplate object was not found: {}'.format(exc))

		udm.remove_object('settings/usertemplate', dn=template)

		utils.verify_ldap_object(template, should_exist=False)
