Ejemplo n.º 1
0
class _City(domain.DomainObject):    
    name = domain.DomainProperty(property_type.StringType(5), "", "City Name", "Name of the city.")
    zip = domain.DomainProperty(property_type.StringType(), "", "ZIP", "The postal code of the city.")
    
    def __init__(self, name="", zip_=""):
        domain.DomainObject.__init__(self)
        self.name = name
        self.zip = zip_
Ejemplo n.º 2
0
 def setUp(self):
     """ Creates the required test environment. """
     
     self._propDef = PropertyDefinition(
         "testID", constants.USER_PROPERTY_CATEGORY, property_type.StringType())
     self._registry = PropertyDefinitionRegistry(PropertyDefinitionFactory(), True)
     self._regPropsNumber = len(self._registry.registeredPropertyDefinitions)
Ejemplo n.º 3
0
class _Address(domain.DomainObject):
    street = domain.DomainProperty(property_type.StringType(), "", "Street",
                                   "This is the street name.")
    streetNumber = domain.DomainProperty(property_type.NumberType(), None,
                                         "Street Number",
                                         "This is the street number.")
    city = domain.DomainProperty(property_type.DomainObjectType(_City),
                                 _City(), "City", "This is the city.")
Ejemplo n.º 4
0
 def testConversionOnePropertyMultipleKeywords(self):
     """ Tests the conversion with only one property and multiple keywords. """
     
     propDef = PropertyDefinition("animal_type", propertyType = property_type.StringType())
     propertyDefinitions = {("SYSTEM","__animal_type__"): propDef}
     
     converter = KeywordSearchQueryConverter(propertyDefinitions)
     result = converter.convert("penguin dolphin")
     self.assertEquals(result, "animal_type like 'penguin' OR animal_type like 'dolphin'")
Ejemplo n.º 5
0
 def testConversionMultiplePropertiesMultipleKeywords(self):
     """ Tests the conversion with multiple properties and multiple keywords. """
     
     repository = {("SYSTEM" ,"__animal_type__"): \
                     PropertyDefinition("animal_type", propertyType = property_type.StringType()),
                   ("SYSTEM", "__skin_color__"):\
                     PropertyDefinition("skin_color", propertyType = property_type.AnyType()) }
     
     converter = KeywordSearchQueryConverter(repository)
     result = converter.convert("penguin dolphin")
     self.assertEquals(result, "skin_color like 'penguin' OR animal_type like 'penguin' " \
                       "OR skin_color like 'dolphin' OR animal_type like 'dolphin'")
Ejemplo n.º 6
0
 def testConversionMultipleProperties(self):
     """ Tests the conversion with multiple properties and one keyword. """
     
     propertyDefinitions = {("SYSTEM" ,"__animal_type__"): \
                              PropertyDefinition("animal_type", displayName = "animal_type",
                                                 propertyType = property_type.StringType()),
                            ("SYSTEM", "__skin_color__"):\
                              PropertyDefinition("skin_color", propertyType = property_type.AnyType())}
     
     converter = KeywordSearchQueryConverter(propertyDefinitions)
     result = converter.convert("penguin")
     self.assertEquals(result, "skin_color like 'penguin' OR animal_type like 'penguin'")
Ejemplo n.º 7
0
 def testDeepCopy(self):
     allowedTypes = [property_type.StringType()]
     aPropType = property_type.ListType(allowedTypes, 1, 2, True)
     aPropTypeCopy = deepcopy(aPropType)
     
     for propType in [aPropType, aPropTypeCopy]:
         self.assertEquals(len(propType.restrictions), 3)
         self.assertEquals(len(propType.restrictions[constants.ALLOWED_SUB_TYPES]), 1)
         self.assertEquals(propType.restrictions["subTypes"], 
                           [subType.name for subType in allowedTypes])
         self.assertEquals(propType.restrictions[constants.MINIMUM_LENGTH], 1)
         self.assertEquals(propType.restrictions[constants.MAXIMUM_LENGTH], 2)
         self.assertTrue(propType.notNull)
Ejemplo n.º 8
0
    def _initUnmanagedSystemProperties(self):
        """ Defines the common system-specific properties. """

        options = [mimeType for mimeType in mimetypes.types_map.values()]
        mimeTypeValidator = property_type.StringType(options=options)
        mimeTypeProperty = PropertyDefinition(
            const.MIME_TYPE_ID, const.UNMANAGED_SYSTEM_PROPERTY_CATEGORY,
            mimeTypeValidator, const.MIME_TYPE_DISPLAYNAME,
            const.MIME_TYPE_DESCRIPTION)
        self._systemPropertyDefinitions.append(mimeTypeProperty)

        resourceCreationProperty = PropertyDefinition(
            const.CREATION_DATETIME_ID,
            const.UNMANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.DatetimeType(), const.CREATION_DATETIME_DISPLAYNAME,
            const.CREATION_DATETIME_DESCRIPTION)
        self._systemPropertyDefinitions.append(resourceCreationProperty)

        resourceModificationProperty = PropertyDefinition(
            const.MODIFICATION_DATETIME_ID,
            const.UNMANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.DatetimeType(),
            const.MODIFICATION_DATETIME_DISPLAYNAME,
            const.MODIFICATION_DATETIME_DESCRIPTION)
        self._systemPropertyDefinitions.append(resourceModificationProperty)

        sizeProperty = PropertyDefinition(
            const.SIZE_ID, const.UNMANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.NumberType(0, None), const.SIZE_DISPLAYNAME,
            const.SIZE_DESCRIPTION)
        self._systemPropertyDefinitions.append(sizeProperty)

        ownerProperty = PropertyDefinition(
            const.OWNER_ID, const.UNMANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.StringType(), const.OWNER_DISPLAYNAME,
            const.OWNER_DESCRIPTION)
        self._systemPropertyDefinitions.append(ownerProperty)
    def testRestrictions(self):
        """ Demonstrates the restriction attribute. """

        expectedRestrictions = dict()
        for key, value in expectedRestrictions.iteritems():
            self.assertTrue(key in self._propertyDef.restrictions)
            self.assertEquals(value, self._propertyDef.restrictions[key])

        anotherPropDef = prop_def.PropertyDefinition(
            "identifier", "category", property_type.StringType(10, 100))
        expectedRestrictions[constants.MINIMUM_LENGTH] = 10
        expectedRestrictions[constants.MAXIMUM_LENGTH] = 100
        for key, value in expectedRestrictions.iteritems():
            self.assertTrue(key in anotherPropDef.restrictions)
            self.assertEquals(value, anotherPropDef.restrictions[key])
Ejemplo n.º 10
0
class _Author(domain.DomainObject):
    name = domain.DomainProperty(property_type.StringType(), None, "Name",
                                 "This is the author name")
    mainAddress = domain.DomainProperty(
        property_type.DomainObjectType(_Address), _Address(), "Addresses",
        "The main address.")
    addresses = domain.DomainProperty(
        property_type.ListType([property_type.DomainObjectType(_Address)]),
        None, "Addresses", "These are additional addresses.")

    def __init__(self, name="", mainAddress=None, addresses=None):
        domain.DomainObject.__init__(self)
        self.name = name
        if not mainAddress is None:
            self.mainAddress = mainAddress
        if not addresses is None:
            self.addresses = addresses

    @name.setValidate
    def _validateName(self):
        if self.name is None or len(self.name) == 0:
            raise ValueError("Name should not be empty.")
Ejemplo n.º 11
0
 def testDomainPropertyRepresentation(self):
     domainProperty = domain.DomainProperty(property_type.StringType())
     self.assertEquals(repr(domainProperty), ": String\n")
Ejemplo n.º 12
0
class _City(domain.DomainObject):
    name = domain.DomainProperty(property_type.StringType(), "", "City Name",
                                 "Name of the city.")
    zip = domain.DomainProperty(property_type.StringType(), "", "ZIP",
                                "The postal code of the city.")
    def setUp(self):
        """ Initializes the property instance. """

        self._propertyDef = prop_def.PropertyDefinition(
            "name", constants.USER_PROPERTY_CATEGORY,
            property_type.StringType())
Ejemplo n.º 14
0
 def setUp(self):
     """ Creates the test fixture. """
     
     self._propertyType = property_type.StringType()
Ejemplo n.º 15
0
    def _initManagedSystemProperties(self):
        """ Defines the common system-specific properties. """

        dataTypeProperty = PropertyDefinition(
            const.DATATYPE_ID, const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.StringType(), const.DATATYPE_DISPLAYNAME,
            const.DATATYPE_DESCRIPTION)
        self._systemPropertyDefinitions.append(dataTypeProperty)

        datastoreProperty = PropertyDefinition(
            const.DATASTORE_NAME_ID, const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.StringType(), const.DATASTORE_DISPLAYNAME,
            const.DATASTORE_NAME_DESCRIPTION)
        self._systemPropertyDefinitions.append(datastoreProperty)

        fileSizeProperty = PropertyDefinition(
            const.CONTENT_SIZE_ID, const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.NumberType(0, None), const.CONTENT_SIZE_DISPLAYNAME,
            const.CONTENT_SIZE_DESCRIPTION)
        self._systemPropertyDefinitions.append(fileSizeProperty)

        fileCreationProperty = PropertyDefinition(
            const.CONTENT_CREATION_DATETIME_PROPERTY_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.DatetimeType(), const.CONTENT_CREATION_DISPLAYNAME,
            const.CONTENT_CREATION_DATETIME_DESCRIPTION)
        self._systemPropertyDefinitions.append(fileCreationProperty)

        fileModificationProperty = PropertyDefinition(
            const.CONTENT_MODIFICATION_DATETIME_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.DatetimeType(),
            const.CONTENT_MODIFICATION_DATETIME_DISPLAYNAME,
            const.CONTENT_MODIFICATION_DATETIME_DESCRIPTION)
        self._systemPropertyDefinitions.append(fileModificationProperty)

        archiveIdentifierProperty = PropertyDefinition(
            const.CONTENT_IDENTIFIER_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY, property_type.StringType(),
            const.CONTENT_IDENTIFIER, const.CONTENT_IDENTIFIER_DESCRIPTION)
        self._systemPropertyDefinitions.append(archiveIdentifierProperty)

        archiveRetentionExceededProperty = PropertyDefinition(
            const.ARCHIVE_RETENTION_EXCEEDED_DATETIME_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.DatetimeType(),
            const.ARCHIVE_RETENTION_EXCEEDED_DISPLAYNAME,
            const.ARCHIVE_RETENTION_EXCEEDED_DESCRIPTION)
        self._systemPropertyDefinitions.append(
            archiveRetentionExceededProperty)

        archiveRootCollectionProperty = PropertyDefinition(
            const.ARCHIVE_ROOT_COLLECTION_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY, property_type.StringType(),
            const.ARCHIVE_ROOT_COLLECTION_DISPLAYNAME,
            const.ARCHIVE_ROOT_COLLECTION_DESCRIPTION)
        self._systemPropertyDefinitions.append(archiveRootCollectionProperty)

        archivePartIndexProperty = PropertyDefinition(
            const.ARCHIVE_PART_INDEX_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.NumberType(0, None),
            const.ARCHIVE_PART_INDEX_DISPLAYNAME,
            const.ARCHIVE_PART_INDEX_DESCRIPTION)
        self._systemPropertyDefinitions.append(archivePartIndexProperty)

        archivePartCount = PropertyDefinition(
            const.ARCHIVE_PART_COUNT_ID,
            const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.NumberType(0, None),
            const.ARCHIVE_PART_COUNT_DISPLAYNAME,
            const.ARCHIVE_PART_COUNT_DESCRIPTION)
        self._systemPropertyDefinitions.append(archivePartCount)

        dataFormatProperty = PropertyDefinition(
            const.DATA_FORMAT_ID, const.MANAGED_SYSTEM_PROPERTY_CATEGORY,
            property_type.StringType(), const.DATA_FORMAT_DISPLAYNAME,
            const.DATA_FORMAT_DESCRIPTION)
        self._systemPropertyDefinitions.append(dataFormatProperty)

        # init default property definitions
        self._defaultCollectionPropertyDefinitions.append(dataTypeProperty)
        self._defaultResourcePropertyDefinitions.append(dataFormatProperty)
        self._defaultResourcePropertyDefinitions.append(datastoreProperty)
        self._defaultResourcePropertyDefinitions.append(fileCreationProperty)
        self._defaultResourcePropertyDefinitions.append(
            fileModificationProperty)
        self._defaultResourcePropertyDefinitions.append(fileSizeProperty)
        self._defaultArchivePropertyDefinitions.append(datastoreProperty)
        self._defaultArchivePropertyDefinitions.append(
            archiveRetentionExceededProperty)