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'")
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'")
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)
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'")
def testProvokeExceptions(self): """ Provokes exceptions. """ # No matching keyword propertyDefinitions = {("SYSTEM","__team_member__"):\ PropertyDefinition("team_member", propertyType = property_type.DatetimeType())} converter = KeywordSearchQueryConverter(propertyDefinitions) result = converter.convert("12 True penguin") self.assertEquals(result, "") #Empty property map propertyDefinitions = dict() converter = KeywordSearchQueryConverter(propertyDefinitions) result = converter.convert("12 True penguin") self.assertEquals(result, "") #Keyword with correct type but out of range of property propertyDefinitions = {("SYSTEM","team_member"):\ PropertyDefinition("team_member", propertyType = property_type.NumberType(minimum = 15))} converter = KeywordSearchQueryConverter(propertyDefinitions) result = converter.convert("12 True penguin") self.assertEquals(result, "")
def testConversionOnePropertyMultipleKeywordsInvalidTypes(self): """ Tests the conversion with only one property, multiple keywords and invalid types. """ propertyDefinitions = {("SYSTEM","__team_member__"):\ PropertyDefinition("team_member", propertyType = property_type.NumberType())} converter = KeywordSearchQueryConverter(propertyDefinitions) result = converter.convert("12 14.04 True penguin") self.assertEquals(result, "team_member like '12' OR team_member like '14.04'") propertyDefinitions = {("SYSTEM","__team_member__"):\ PropertyDefinition("team_member", propertyType = property_type.BooleanType())} converter._propertyDefinitions = propertyDefinitions result = converter.convert("12 14.04 True penguin") self.assertEquals(result, "team_member like 'True'") propertyDefinitions = {("SYSTEM","__team_member__"):\ PropertyDefinition("team_member", propertyType = property_type.DatetimeType())} converter._propertyDefinitions = propertyDefinitions result = converter.convert("12 14.04 True penguin 19.12.2000 11:54:56") self.assertEquals(result, "team_member like '19.12.2000'")
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 _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)