View | Details | Raw Unified | Return to bug 41556
Collapse All | Expand All

(-)a/branches/ucs-4.1/ucs-4.1-2/management/univention-directory-manager-modules/modules/univention/admin/objects.py (-12 / +6 lines)
 Lines 119-125   def description(object): Link Here 
119
def shadow(lo, module, object, position):
119
def shadow(lo, module, object, position):
120
	'''if object is a container, return object and module the container
120
	'''if object is a container, return object and module the container
121
	shadows (that is usually the one that is subordinate in the LDAP tree)'''
121
	shadows (that is usually the one that is subordinate in the LDAP tree)'''
122
	
122
123
	if not object:
123
	if not object:
124
		return (None, None)
124
		return (None, None)
125
	dn=object.dn
125
	dn=object.dn
 Lines 142-153   def dn(object): Link Here 
142
	else:
142
	else:
143
		return None
143
		return None
144
144
145
def arg(object):
146
	if hasattr(object, 'arg'):
147
		return object.arg
148
	else:
149
		return None
150
151
def ocToType(oc):
145
def ocToType(oc):
152
	for module in univention.admin.modules.modules.values():
146
	for module in univention.admin.modules.modules.values():
153
		if univention.admin.modules.policyOc(module) == oc:
147
		if univention.admin.modules.policyOc(module) == oc:
 Lines 156-168   def ocToType(oc): Link Here 
156
def fixedAttribute(object, key):
150
def fixedAttribute(object, key):
157
	if not hasattr(object, 'fixedAttributes'):
151
	if not hasattr(object, 'fixedAttributes'):
158
		return 0
152
		return 0
159
	
153
160
	return object.fixedAttributes().get(key, 0)
154
	return object.fixedAttributes().get(key, 0)
161
155
162
def emptyAttribute(object, key):
156
def emptyAttribute(object, key):
163
	if not hasattr(object, 'emptyAttributes'):
157
	if not hasattr(object, 'emptyAttributes'):
164
		return 0
158
		return 0
165
	
159
166
	return object.emptyAttributes().get(key, 0)
160
	return object.emptyAttributes().get(key, 0)
167
161
168
def getPolicyReference(object, policy_type):
162
def getPolicyReference(object, policy_type):
 Lines 200-206   def replacePolicyReference(object, policy_type, new_reference): Link Here 
200
		return
194
		return
201
195
202
	removePolicyReference(object, policy_type)
196
	removePolicyReference(object, policy_type)
203
	
197
204
	univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'replacePolicyReference: appending reference: %s' % new_reference)
198
	univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'replacePolicyReference: appending reference: %s' % new_reference)
205
	object.policies.append(new_reference)
199
	object.policies.append(new_reference)
206
200
 Lines 210-216   def restorePolicyReference(object, policy_type): Link Here 
210
	module=univention.admin.modules.get(policy_type)
204
	module=univention.admin.modules.get(policy_type)
211
	if not module:
205
	if not module:
212
		return
206
		return
213
	
207
214
	removePolicyReference(object, policy_type)
208
	removePolicyReference(object, policy_type)
215
209
216
	restore=None
210
	restore=None
 Lines 231-237   def wantsCleanup(object): Link Here 
231
	object_module=univention.admin.modules.get(object_module)
225
	object_module=univention.admin.modules.get(object_module)
232
	if hasattr(object_module, 'docleanup'):
226
	if hasattr(object_module, 'docleanup'):
233
		wantsCleanup=object_module.docleanup
227
		wantsCleanup=object_module.docleanup
234
	
228
235
	return wantsCleanup
229
	return wantsCleanup
236
230
237
def performCleanup(object):
231
def performCleanup(object):
(-)a/branches/ucs-4.1/ucs-4.1-2/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-1 lines)
 Lines 992-998   def _doit(arglist): Link Here 
992
		try:
992
		try:
993
			for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
993
			for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
994
				out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) )
994
				out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) )
995
				out.append( 'ARG: %s' % univention.admin.objects.arg( object ) )
996
995
997
				if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'):
996
				if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'):
998
					object.open()
997
					object.open()
(-)a/branches/ucs-4.1/ucs-4.1-2/management/univention-directory-manager-modules/test/BaseTest.py (-24 / +1 lines)
 Lines 95-101   class BaseCase(TestCase): Link Here 
95
		self.__initOptions(options)
95
		self.__initOptions(options)
96
		self.ldap = self.__initAccess()
96
		self.ldap = self.__initAccess()
97
		self.__superordinate = None
97
		self.__superordinate = None
98
		self.__arg = None
99
98
100
	def __getDefaultBinddn(self):
99
	def __getDefaultBinddn(self):
101
		return self.rdn('cn=admin')
100
		return self.rdn('cn=admin')
 Lines 220-239   class BaseCase(TestCase): Link Here 
220
			return result[0]
219
			return result[0]
221
		return None, None
220
		return None, None
222
221
223
	def arg(self, argument = None):
224
		'''Set or query the current objects "arg".
225
226
		Set "arg" to "Argument", if given, otherwise just return it.
227
228
		Some objects are not stored in their own LDAP object but are
229
		attached to an existing object.  To identify such an object,
230
		both the DN and the "arg" are needed.
231
		'''
232
		if argument is None:
233
			return self.__arg
234
		self.__arg = argument
235
		return self.__arg
236
237
	def superordinate(self, argument = None):
222
	def superordinate(self, argument = None):
238
		'''Set or query the current objectts "superordinate".
223
		'''Set or query the current objectts "superordinate".
239
224
 Lines 256-262   class BaseCase(TestCase): Link Here 
256
			sup = getattr(argument, 'superordinate')
241
			sup = getattr(argument, 'superordinate')
257
		if callable(sup):
242
		if callable(sup):
258
			sup = sup()
243
			sup = sup()
259
		kwargs = { 'base': dn, 'scope': 'base', 'superordinate': sup } 
244
		kwargs = { 'base': dn, 'scope': 'base', 'superordinate': sup }
260
		res = supmod.lookup(self.__config, self.ldap, '', **kwargs)
245
		res = supmod.lookup(self.__config, self.ldap, '', **kwargs)
261
		self.__superordinate = res[0]
246
		self.__superordinate = res[0]
262
		return self.__superordinate
247
		return self.__superordinate
 Lines 296-306   class BaseCase(TestCase): Link Here 
296
			self.__command.append('--superordinate')
281
			self.__command.append('--superordinate')
297
			self.__command.append(self.__escape(superordinate))
282
			self.__command.append(self.__escape(superordinate))
298
283
299
		def arg(self, arg):
300
			'''Set the "arg" argument.'''
301
			self.__command.append('--arg')
302
			self.__command.append(self.__escape(arg))
303
304
		def dn(self, dn):
284
		def dn(self, dn):
305
			'''Set the "dn" argument.'''
285
			'''Set the "dn" argument.'''
306
			self.__command.append('--dn')
286
			self.__command.append('--dn')
 Lines 377-383   class BaseCase(TestCase): Link Here 
377
		# set superordinate if present
357
		# set superordinate if present
378
		if self.__superordinate:
358
		if self.__superordinate:
379
			cmd.superordinate(self.__superordinate.dn)
359
			cmd.superordinate(self.__superordinate.dn)
380
		# set arg if present
381
		if self.__arg:
382
			cmd.arg(self.__arg)
383
		return cmd
360
		return cmd
(-)a/branches/ucs-4.1/ucs-4.1-2/management/univention-directory-manager-modules/test/GenericTest.py (-34 / +39 lines)
 Lines 31-37    Link Here 
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
33
33
34
from BaseTest import BaseCase, TestError, ProcessFailedError
34
from BaseTest import BaseCase, TestError
35
35
36
36
37
class ObjectNotFoundError(TestError):
37
class ObjectNotFoundError(TestError):
 Lines 47-52   class ObjectNotFoundError(TestError): Link Here 
47
			% (test.name, helper, test.modname)
47
			% (test.name, helper, test.modname)
48
		TestError.__init__(self, error, test)
48
		TestError.__init__(self, error, test)
49
49
50
50
class LeftoverObjectFound(TestError):
51
class LeftoverObjectFound(TestError):
51
	'''Assertion error in the Univention Admin test suite.
52
	'''Assertion error in the Univention Admin test suite.
52
53
 Lines 60-65   class LeftoverObjectFound(TestError): Link Here 
60
			% (test.name, helper, test.modname)
61
			% (test.name, helper, test.modname)
61
		TestError.__init__(self, error, test)
62
		TestError.__init__(self, error, test)
62
63
64
63
class ObjectNotIdentifiedError(TestError):
65
class ObjectNotIdentifiedError(TestError):
64
	'''Assertion error in the Univention Admin test suite.
66
	'''Assertion error in the Univention Admin test suite.
65
67
 Lines 70-75   class ObjectNotIdentifiedError(TestError): Link Here 
70
			% (test.name, dn, test.modname)
72
			% (test.name, dn, test.modname)
71
		TestError.__init__(self, error, test)
73
		TestError.__init__(self, error, test)
72
74
75
73
class PropertyInvalidError(TestError):
76
class PropertyInvalidError(TestError):
74
	'''Assertion error in the Univention Admin test suite.
77
	'''Assertion error in the Univention Admin test suite.
75
78
 Lines 81-90   class PropertyInvalidError(TestError): Link Here 
81
		e1 = 'Incorrect property %s (%s)' % (property, description)
84
		e1 = 'Incorrect property %s (%s)' % (property, description)
82
		e2 = 'of object %s at DN %s (module %s).' \
85
		e2 = 'of object %s at DN %s (module %s).' \
83
		     % (test.name, dn, test.modname)
86
		     % (test.name, dn, test.modname)
84
		e3= 'Expected: "%s" Actual: "%s"' % (expected, actual)
87
		e3 = 'Expected: "%s" Actual: "%s"' % (expected, actual)
85
		error = '%s %s %s' % (e1, e2, e3)
88
		error = '%s %s %s' % (e1, e2, e3)
86
		TestError.__init__(self, error, test)
89
		TestError.__init__(self, error, test)
87
90
91
88
class ObjectClassNotPresentError(TestError):
92
class ObjectClassNotPresentError(TestError):
89
	'''Assertion error in the Univention Admin test suite.
93
	'''Assertion error in the Univention Admin test suite.
90
94
 Lines 97-103   class ObjectClassNotPresentError(TestError): Link Here 
97
		     % (option, description)
101
		     % (option, description)
98
		e2 = 'of object %s at DN %s (module %s).' \
102
		e2 = 'of object %s at DN %s (module %s).' \
99
		     % (test.name, dn, test.modname)
103
		     % (test.name, dn, test.modname)
100
		e3= 'Expected: "%s" Actual: "%s"' % (expected, actual)
104
		e3 = 'Expected: "%s" Actual: "%s"' % (expected, actual)
101
		error = '%s %s %s' % (e1, e2, e3)
105
		error = '%s %s %s' % (e1, e2, e3)
102
		TestError.__init__(self, error, test)
106
		TestError.__init__(self, error, test)
103
107
 Lines 157-171   class GenericTestCase(BaseCase): Link Here 
157
		# NOTE: this filter might be a little fragile...
161
		# NOTE: this filter might be a little fragile...
158
		cmd.filter('%s="%s"' % (self.identifier, self.name))
162
		cmd.filter('%s="%s"' % (self.identifier, self.name))
159
163
160
	def __setupCommandUpdate(self, cmd, name, properties, options = None):
164
	def __setupCommandUpdate(self, cmd, name, properties, options=None):
161
		descriptions = self.module.property_descriptions
165
		descriptions = self.module.property_descriptions
162
		special = set(('position',))
166
		special = set(('position',))
163
		single = (p for p in properties
167
		single = (
164
			  if not p in special
168
			p for p in properties
165
			  if not descriptions[p].multivalue)
169
			if p not in special
166
		multi  = (p for p in properties
170
			if not descriptions[p].multivalue)
167
			  if not p in special
171
		multi = (
168
			  if descriptions[p].multivalue)
172
			p for p in properties
173
			if p not in special
174
			if descriptions[p].multivalue)
169
		# set identifying property
175
		# set identifying property
170
		if name is not None:
176
		if name is not None:
171
			cmd.set(self.identifier, name)
177
			cmd.set(self.identifier, name)
 Lines 276-301   class GenericTestCase(BaseCase): Link Here 
276
		self.dn = dn
282
		self.dn = dn
277
		self.__leftover_dns.add(dn)
283
		self.__leftover_dns.add(dn)
278
284
279
	def testObjectExists(self, dn = None):
285
	def testObjectExists(self, dn=None):
280
		'''Check that the object exists.
286
		'''Check that the object exists.
281
287
282
		"DN", if given, indicates the DN of the object to test.
288
		"DN", if given, indicates the DN of the object to test.
283
		
289
284
		Raise "ObjectNotFoundError" if it does not exists.
290
		Raise "ObjectNotFoundError" if it does not exists.
285
		'''
291
		'''
286
		dn, attr = self.search(dn = dn)
292
		dn, attr = self.search(dn=dn)
287
		if attr is None:
293
		if attr is None:
288
			raise ObjectNotFoundError(self, dn)
294
			raise ObjectNotFoundError(self, dn)
289
		self.useDN(dn)
295
		self.useDN(dn)
290
296
291
	def testObjectExistsNot(self, dn = None):
297
	def testObjectExistsNot(self, dn=None):
292
		'''Check that the object does not exists.
298
		'''Check that the object does not exists.
293
299
294
		"DN", if given, indicates the DN of the object to test.
300
		"DN", if given, indicates the DN of the object to test.
295
301
296
		Raise "LeftoverObjectFound" if it does exists.
302
		Raise "LeftoverObjectFound" if it does exists.
297
		'''
303
		'''
298
		dn, attr = self.search(dn = dn)
304
		dn, attr = self.search(dn=dn)
299
		if bool(attr):
305
		if bool(attr):
300
			self.useDN(dn)
306
			self.useDN(dn)
301
			raise LeftoverObjectFound(self, dn)
307
			raise LeftoverObjectFound(self, dn)
 Lines 306-312   class GenericTestCase(BaseCase): Link Here 
306
		Raise "ObjectNotIdentifiedError" if the module cannot identify
312
		Raise "ObjectNotIdentifiedError" if the module cannot identify
307
		the current object.
313
		the current object.
308
		'''
314
		'''
309
		_, attr = self.search(dn = self.dn)
315
		_, attr = self.search(dn=self.dn)
310
		if not self.module.identify(self.dn, attr):
316
		if not self.module.identify(self.dn, attr):
311
			raise ObjectNotIdentifiedError(self, self.dn)
317
			raise ObjectNotIdentifiedError(self, self.dn)
312
318
 Lines 317-323   class GenericTestCase(BaseCase): Link Here 
317
323
318
		Raise "ObjectClassNotPresentError" if an option is not present.
324
		Raise "ObjectClassNotPresentError" if an option is not present.
319
		'''
325
		'''
320
		attr = self.ldap.get(dn = self.dn, attr = ['objectClass'])
326
		attr = self.ldap.get(dn=self.dn, attr=['objectClass'])
321
		for o in options:
327
		for o in options:
322
			classes = self.module.options[o].objectClasses
328
			classes = self.module.options[o].objectClasses
323
			if not classes:
329
			if not classes:
 Lines 336-349   class GenericTestCase(BaseCase): Link Here 
336
		values.
342
		values.
337
		'''
343
		'''
338
		special = set(('position',))
344
		special = set(('position',))
339
		props = (p for p in properties
345
		props = (
340
			 if not p in special
346
			p for p in properties
341
			 if not p in self.uncheckedProperties)
347
			if p not in special
342
		obj = self.open(dn = self.dn)
348
			if p not in self.uncheckedProperties)
349
		obj = self.open(dn=self.dn)
343
		for prop in props:
350
		for prop in props:
344
			self._testProperty(prop, obj, properties)
351
			self._testProperty(prop, obj, properties)
345
352
346
	def create(self, properties, options = None, name = None):
353
	def create(self, properties, options=None, name=None):
347
		'''Create an object of the current module.
354
		'''Create an object of the current module.
348
355
349
		"Properties" is a mapping from property names to values.
356
		"Properties" is a mapping from property names to values.
 Lines 357-365   class GenericTestCase(BaseCase): Link Here 
357
		self.__setupCommandUpdate(cmd, name, properties, options)
364
		self.__setupCommandUpdate(cmd, name, properties, options)
358
		return cmd.run()
365
		return cmd.run()
359
366
360
	def modify(self, properties, dn = None, name = None, newName = None):
367
	def modify(self, properties, dn=None, name=None, newName=None):
361
		'''Modify an object of the current module.
368
		'''Modify an object of the current module.
362
		
369
363
		"Properties" is a mapping from property names to values;
370
		"Properties" is a mapping from property names to values;
364
		only values that should be changed need to be included.
371
		only values that should be changed need to be included.
365
		"DN", if given, is the DN of the object to modify.
372
		"DN", if given, is the DN of the object to modify.
 Lines 376-384   class GenericTestCase(BaseCase): Link Here 
376
		self.__setupCommandUpdate(cmd, newName, properties)
383
		self.__setupCommandUpdate(cmd, newName, properties)
377
		return cmd.run()
384
		return cmd.run()
378
385
379
	def remove(self, name = None, dn = None, recursive = False):
386
	def remove(self, name=None, dn=None, recursive=False):
380
		'''Remove an object of the current module.
387
		'''Remove an object of the current module.
381
		
388
382
		"Name" is the name of the object to remove (defaults to the current objects name).
389
		"Name" is the name of the object to remove (defaults to the current objects name).
383
		"DN", if given, is the DN of the object to remove.
390
		"DN", if given, is the DN of the object to remove.
384
		"Recursive" should be True to remove the object recursively.
391
		"Recursive" should be True to remove the object recursively.
 Lines 391-397   class GenericTestCase(BaseCase): Link Here 
391
		if recursive:
398
		if recursive:
392
			cmd.recursive()
399
			cmd.recursive()
393
		return cmd.run()
400
		return cmd.run()
394
	
401
395
	def hookAfterCreated(self, dn):
402
	def hookAfterCreated(self, dn):
396
		'''Perform additional actions after creating an object.
403
		'''Perform additional actions after creating an object.
397
404
 Lines 418-424   class GenericTestCase(BaseCase): Link Here 
418
425
419
	def setUp(self):
426
	def setUp(self):
420
		'''Hook method for setting up the test fixture before exercising it.
427
		'''Hook method for setting up the test fixture before exercising it.
421
		
428
422
		Override this method to set up values for these properties:
429
		Override this method to set up values for these properties:
423
		"name": The name of the object that will be tested.
430
		"name": The name of the object that will be tested.
424
			You most definitely want to set this one.
431
			You most definitely want to set this one.
 Lines 460-466   class GenericTestCase(BaseCase): Link Here 
460
		self.createOptions = set()
467
		self.createOptions = set()
461
		self.dn = None
468
		self.dn = None
462
		self.superordinate()
469
		self.superordinate()
463
		self.arg()
464
		self.__leftover_dns = set()
470
		self.__leftover_dns = set()
465
471
466
	def runTest(self):
472
	def runTest(self):
 Lines 484-491   class GenericTestCase(BaseCase): Link Here 
484
		is identified by the module and has the correct options and
490
		is identified by the module and has the correct options and
485
		property values set.
491
		property values set.
486
		'''
492
		'''
487
		proc = self.create(self.createProperties,
493
		proc = self.create(self.createProperties, self.createOptions)
488
				   self.createOptions)
489
		self._checkProcess(proc, 'create')
494
		self._checkProcess(proc, 'create')
490
		self.testObjectExists(self.dn)
495
		self.testObjectExists(self.dn)
491
		self.testObjectIdentify()
496
		self.testObjectIdentify()
 Lines 500-506   class GenericTestCase(BaseCase): Link Here 
500
		exists, is identified by the module and has the correct property
505
		exists, is identified by the module and has the correct property
501
		values set.
506
		values set.
502
		'''
507
		'''
503
		proc = self.modify(self.modifyProperties, dn = self.dn)
508
		proc = self.modify(self.modifyProperties, dn=self.dn)
504
		self._checkProcess(proc, 'modify')
509
		self._checkProcess(proc, 'modify')
505
		if self.newName is not None:
510
		if self.newName is not None:
506
			self.dn = None
511
			self.dn = None
 Lines 516-522   class GenericTestCase(BaseCase): Link Here 
516
		This test removes the current object and then checks that it
521
		This test removes the current object and then checks that it
517
		does not exist any more.
522
		does not exist any more.
518
		'''
523
		'''
519
		proc = self.remove(dn = self.dn)
524
		proc = self.remove(dn=self.dn)
520
		self._checkProcess(proc, 'remove')
525
		self._checkProcess(proc, 'remove')
521
		self.testObjectExistsNot(self.dn)
526
		self.testObjectExistsNot(self.dn)
522
		self.hookAfterRemoved(self.dn)
527
		self.hookAfterRemoved(self.dn)
 Lines 529-535   class GenericTestCase(BaseCase): Link Here 
529
		When overriding this method, make sure you call to your superclass first!
534
		When overriding this method, make sure you call to your superclass first!
530
		'''
535
		'''
531
		for dn in self.__leftover_dns:
536
		for dn in self.__leftover_dns:
532
			self.remove(dn = dn, recursive = True)
537
			self.remove(dn=dn, recursive=True)
533
538
534
	def shortDescription(self):
539
	def shortDescription(self):
535
		return 'testing module %s' % self.modname
540
		return 'testing module %s' % self.modname
(-)a/branches/ucs-4.1/ucs-4.1-2/management/univention-directory-manager-modules/test/TestDnsZoneMxRecord.py (-6 lines)
 Lines 70-81   class DnsZoneMxRecordTestCase(GenericTestCase): Link Here 
70
			}
70
			}
71
		self.dn = self.__zone.dn
71
		self.dn = self.__zone.dn
72
72
73
	def hookAfterCreated(self, dn):
74
		self.arg(self.createProperties['mx'])
75
76
	def hookAfterModified(self, dn):
77
		self.arg(self.modifyProperties['mx'])
78
79
	# We cannot delete the record at the DN yet, so we can't check for
73
	# We cannot delete the record at the DN yet, so we can't check for
80
	# object non-existence by DN, so we need to override this method and
74
	# object non-existence by DN, so we need to override this method and
81
	# disable the check for object non-existence.
75
	# disable the check for object non-existence.
(-)a/branches/ucs-4.1/ucs-4.1-2/management/univention-directory-manager-modules/test/TestDnsZoneTxtRecord.py (-6 lines)
 Lines 70-81   class DnsZoneTxtRecordTestCase(GenericTestCase): Link Here 
70
			}
70
			}
71
		self.dn = self.__zone.dn
71
		self.dn = self.__zone.dn
72
72
73
	def hookAfterCreated(self, dn):
74
		self.arg(self.createProperties['txt'])
75
76
	def hookAfterModified(self, dn):
77
		self.arg(self.modifyProperties['txt'])
78
79
	# We cannot delete the record at the DN yet, so we can't check for
73
	# We cannot delete the record at the DN yet, so we can't check for
80
	# object non-existence by DN, so we need to override this method and
74
	# object non-existence by DN, so we need to override this method and
81
	# disable the check for object non-existence.
75
	# disable the check for object non-existence.

Return to bug 41556