Skip to content
Permalink
Browse files

share code

  • Loading branch information
wsanchez committed Feb 6, 2014
1 parent ea237d1 commit 38735043724ea1ce1519f300eed2d4a53198d34f
Showing with 17 additions and 24 deletions.
  1. +17 −24 twext/who/test/test_directory.py
@@ -732,11 +732,9 @@ def test_initWithIncorrectFieldTypes(self):
)


def test_initWithContainerClassFieldType_valid(self):
def _test_containerClassFieldType(self, callback):
"""
If C{valueType} is L{Names}, L{Values} or L{Flags}, the expected type
is L{NamedConstant}, L{ValueConstant} or L{FlagConstant}, respectively.
Check that these can be used as fields.
Scaffold for test_initWithContainerClassFieldType_*.
"""

class ConstantHavingDirectoryService(self.serviceClass):
@@ -758,44 +756,39 @@ class ConstantHavingDirectoryService(self.serviceClass):
(service.fieldName.access, Access.read),
):
fields = baseFields.copy()
callback(service, fields, fieldName, validValue)


def test_initWithContainerClassFieldType_valid(self):
"""
If C{valueType} is L{Names}, L{Values} or L{Flags}, the expected type
is L{NamedConstant}, L{ValueConstant} or L{FlagConstant}, respectively.
Check that these can be used as fields.
"""
def callback(service, fields, fieldName, validValue):
fields.update({fieldName: validValue})
record = self.makeRecord(fields=fields, service=service)
self.assertEquals(record.fields[fieldName], validValue)

self._test_containerClassFieldType(callback)


def test_initWithContainerClassFieldType_invalid(self):
"""
If C{valueType} is L{Names}, L{Values} or L{Flags}, the expected type
is L{NamedConstant}, L{ValueConstant} or L{FlagConstant}, respectively.
Check that other types raise.
"""

class ConstantHavingDirectoryService(self.serviceClass):
fieldName = ConstantsContainer((
self.serviceClass.fieldName, ConstantHavingFieldName
))

service = self.service(subClass=ConstantHavingDirectoryService)

baseFields = {
FieldName.uid: u"UID:sam",
FieldName.recordType: RecordType.user,
FieldName.shortNames: (u"sam",),
}

for fieldName, validValue in (
(service.fieldName.eyeColor, Color.blue),
(service.fieldName.language, Language.English),
(service.fieldName.access, Access.read),
):
def callback(service, fields, fieldName, validValue):
for invalidValue in (u"string", None, object()):
fields = baseFields.copy()
fields.update({fieldName: invalidValue})
self.assertRaises(
InvalidDirectoryRecordError,
self.makeRecord, fields=fields, service=service
)

self._test_containerClassFieldType(callback)


def test_repr(self):
"""

0 comments on commit 3873504

Please sign in to comment.
You can’t perform that action at this time.