def get(self, test_type): testType = TestTypeCore.get_one({TestTypeCore._test_type: test_type}) if testType is None: abort(404) indexes = IndexCore.get_all({IndexCore._test_type: test_type}) indexes = [prep_index(index) for index in indexes] return jsonify(result='Success', indexes=indexes, count=len(indexes))
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
def test_repr_getter_setter(self): from core.Index import Index my_type = str(uuid.uuid4()) field = str(uuid.uuid4()) index = Index(my_type, field) assert '{0}'.format(index) == '<Index {0} ({1}) : 0 values>'.format(field, my_type) assert index.to_dict() == {'type': my_type, 'field': field} index._values = ['a', 'b', 'c'] assert '{0}'.format(index) == '<Index {0} ({1}) : 3 values>'.format(field, my_type) index2 = Index.from_dict(index.to_dict()) assert index2.to_dict() == index.to_dict()