Beispiel #1
0
 def test_get_class_name(self):
     name = Introspection.get_class_name(DummyClass())
     assert_is_instance(name, str)
     assert_equals(name, 'dummyclass')
     name = Introspection.get_class_name(DummyClass)
     assert_is_instance(name, str)
     assert_equals(name, 'dummyclass')
Beispiel #2
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)
Beispiel #3
0
 def test_get_searchable_attributes(self):
     attributes = Introspection.get_searchable_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('ipv4network', attributes)
     assert_not_in('_do_not_store', attributes)
     assert_in('custom_attribute', attributes)
Beispiel #4
0
    def test_get_path(self, monkeypatch):
        def mock_expanduser(user):
            return os.getcwd().rstrip(os.sep)
        monkeypatch.setattr(os.path, 'expanduser', mock_expanduser)
        index_path = Index.get_path(DummyClass)
        class_name = DummyClass.__name__.lower()
        package = [m.lower() for m in Introspection.get_instance_path(DummyClass)]
        expected = os.sep.join([os.getcwd().rstrip(os.sep), '.data'] + package + [class_name])
        assert index_path == expected

        index_path = Index.get_path(DummyClass())
        assert index_path == expected
Beispiel #5
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
Beispiel #6
0
 def test_is_class_instance(self):
     assert_true(Introspection.is_class_instance(DummyClass()))
     assert_false(Introspection.is_class_instance(DummyClass))