Exemplo n.º 1
0
 def test_get_schema(self):
     schema = Index.get_schema(DummyClass())
     assert_is_instance(schema, Schema)
     fields = schema._fields.keys()
     for attribute in Introspection.get_storeable_attributes(DummyClass()):
         assert_in(attribute, fields)
     assert_in(InstanceIndex.cache_property, fields)
     assert_in(InstanceIndex.pickled_fields, fields)
     assert_in(InstanceIndex.instance_key, fields)
Exemplo n.º 2
0
 def test_get_storeable_attributes(self):
     attributes = Introspection.get_storeable_attributes(DummyClass())
     attributes = [attribute for attribute in attributes]
     assert_in('string', attributes)
     assert_in('integer', attributes)
     assert_in('float', attributes)
     assert_in('datetime', attributes)
     assert_in('bool', attributes)
     assert_in('unicode', attributes)
     assert_not_in('_do_not_store', attributes)
     assert_in('ipv4network', attributes)
     assert_in('custom_attribute', attributes)
Exemplo n.º 3
0
 def encode(cls, instance, cache_timestamp=None):
     """ Convert an instance into a dictonary that can be indexed """
     index_instance = dict()
     if hasattr(instance, cls.docnum_property):
         index_instance['docnum'] = getattr(instance, cls.docnum_property)
     blacklist = (cls.docnum_property, )
     attributes = Introspection.get_storeable_attributes(instance, blacklist)
     for attribute in attributes:
         value = getattr(instance, attribute)
         if isinstance(value, str):
             value = unicode(value)
         index_instance[attribute] = value
     index_instance[cls.instance_key] = instance
     index_instance[cls.cache_property] = cls._get_timestamp(cache_timestamp=cache_timestamp)
     return index_instance