#!/usr/share/ucs-test/runner python3
## desc: Check that required=True is enforced for singlevalue extended attributes
## tags: [udm]
## roles: [domaincontroller_master]
## exposure: careful
## packages:
##   - univention-config
##   - univention-directory-manager-tools

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


def main():
	with udm_test.UCSTestUDM() as udm:
		udm.create_object(
			'settings/extended_attribute',
			position=udm.UNIVENTION_CONTAINER,
			name=uts.random_string(),
			shortDescription='Test short description',
			CLIName='univentionUCSTestAttribute',
			module='groups/group',
			objectClass='univentionFreeAttributes',
			ldapMapping='univentionFreeAttribute15',
			valueRequired='1'
		)

		# try creating an udm object without the just created extended attribute given (expected to fail)
		try:
			udm.create_group()
		except udm_test.UCSTestUDM_CreateUDMObjectFailed:
			return

		utils.fail('UDM did not report an error while trying to create an object even though a required single value extended attribute was not given')


if __name__ == '__main__':
	main()
