#!/usr/share/ucs-test/runner python3
## desc: Create settings/extended_attribute with all attributes set
## tags: [udm]
## roles: [domaincontroller_master]
## exposure: careful
## packages:
##   - univention-config
##   - univention-directory-manager-tools


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

if __name__ == '__main__':
	with udm_test.UCSTestUDM() as udm:
		properties = {
			'name': uts.random_name(),
			'shortDescription': uts.random_string(),
			'CLIName': uts.random_name(),
			'module': 'users/user',
			'objectClass': 'univentionFreeAttributes',
			'ldapMapping': 'univentionFreeAttribute15',
			'longDescription': uts.random_string(),
			'translationShortDescription': 'de_DE %s' % uts.random_string(),
			'translationLongDescription': 'de_DE %s' % uts.random_string(),
			'translationTabName': 'de_DE %s' % uts.random_string(),
			'syntax': 'string',
			'hook': uts.random_string(),
			'multivalue': '1',
			'default': uts.random_string(),
			'disableUDMWeb': '1',
			'tabName': uts.random_string(),
			'tabPosition': '1',
			'groupName': uts.random_string(),
			'groupPosition': '1',
			'tabAdvanced': '1',
			'overwriteTab': '1',
			'fullWidth': '1',
			'mayChange': '1',
			'notEditable': '1',
			'valueRequired': '1',
			'deleteObjectClass': '1',
			'version': uts.random_string(),
			'doNotSearch': '1',
			'set': {'options': uts.random_string()}  # "options" property of settings/extended_attribute collides with already existing keyword argument "options"
		}

		extended_attribute = udm.create_object('settings/extended_attribute', position=udm.UNIVENTION_CONTAINER, **properties)

		utils.verify_ldap_object(extended_attribute, {
			'univentionUDMPropertyShortDescription': [properties['shortDescription']],
			'univentionUDMPropertyModule': [properties['module']],
			'univentionUDMPropertyLdapMapping': [properties['ldapMapping']],
			'univentionUDMPropertyCLIName': [properties['CLIName']],
			'univentionUDMPropertyObjectClass': [properties['objectClass']],
			'univentionUDMPropertyLongDescription': [properties['longDescription']],
			'univentionUDMPropertySyntax': [properties['syntax']],
			'univentionUDMPropertyHook': [properties['hook']],
			'univentionUDMPropertyMultivalue': [properties['multivalue']],
			'univentionUDMPropertyDefault': [properties['default']],
			'univentionUDMPropertyLayoutDisable': [properties['disableUDMWeb']],
			'univentionUDMPropertyLayoutTabName': [properties['tabName']],
			'univentionUDMPropertyLayoutPosition': [properties['tabPosition']],
			'univentionUDMPropertyLayoutGroupName': [properties['groupName']],
			'univentionUDMPropertyLayoutGroupPosition': [properties['groupPosition']],
			'univentionUDMPropertyLayoutTabAdvanced': [properties['tabAdvanced']],
			'univentionUDMPropertyLayoutOverwriteTab': [properties['overwriteTab']],
			'univentionUDMPropertyLayoutFullWidth': [properties['fullWidth']],
			'univentionUDMPropertyValueMayChange': [properties['mayChange']],
			'univentionUDMPropertyValueNotEditable': [properties['notEditable']],
			'univentionUDMPropertyDeleteObjectClass': [properties['deleteObjectClass']],
			'univentionUDMPropertyVersion': [properties['version']],
			'univentionUDMPropertyOptions': [properties['set']['options']],
			'univentionUDMPropertyDoNotSearch': [properties['doNotSearch']]
		})
