def test_save(self): from core.Index import Index from core.Base import Base my_type = str(uuid.uuid4()) field = str(uuid.uuid4()) values = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] index = Index(my_type, field, values) index.save() ast = Base().get_all(Index.collection, {}) assert ast.count() == 1 assert ast[0]['type'] == my_type assert ast[0]['field'] == field assert ast[0]['values'] == values index2 = Index(my_type, field) assert index2._values == None index2 = index2.get() assert index2._values == values
def test_get_all(self): from core.Index import Index from core.Base import Base my_type1 = str(uuid.uuid4()) my_type2 = str(uuid.uuid4()) field1 = str(uuid.uuid4()) field2 = str(uuid.uuid4()) values1 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] index1 = Index(my_type1, field1, values1) index1.save() # values2 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] index2 = Index(my_type2, field2, values1) index2.save() indexes = Index.get_all() assert len(indexes) == 2 indexes = Index.get_all({Index._test_type: my_type1}) assert len(indexes) == 1 indexes = Index.get_all({Index._values: values1}) assert len(indexes) == 2 indexes = Index().get_all({'type': my_type1}) assert len(indexes) == 1