def test_update(setup_module):
    first = First(id=988019, guid="testguid111")
    first = FirstService().update(first)
    assert first is None

    first = First(id=988019, version=25, guid="testguid111")
    first = FirstService().update(first)
    assert first is not None
    assert first.guid is "testguid111"
def prove():
    # 证明单例的有效性
    first_service = FirstService()
    f2 = FirstService()
    f3 = FirstService()

    print(first_service.find_list())
    from super_init_wrapper import instance
    return str(instance)
def test_find_one(setup_module):
    query = {
        First.id == 988020,
        # First.version ==1,
        First.guid == "testguid",
    }
    entityone = FirstService().find_one(query)
    assert entityone is not None
    query = {
        First.id == 988020,
        First.version == 3,
        # First.guid == "testguid",
    }
    entityone = FirstService().find_one(query)
    assert entityone is None
def save():
    json_dict = RequestBody()
    entity = json_dict_entity(json_dict, First)
    entity = FirstService().update(entity)
    if entity is not None:
        return ReturnUtil().ok(entity)
    else:
        return ReturnUtil().falid()
def test_find_id_max(setup_module):
    max_id = FirstService().find_id_max()
    assert max_id == max_id
def test_add(setup_module):
    first_service = FirstService()
    first = First(guid="testguid", address="xxx-xxx-xx")
    max_id = FirstService().find_id_max()
    assert first_service.create(first).id == max_id + 1
    # session=Session()
    # st=Student(Sname="中文名字",Ssex="女",Sage=2,Sdept="3")
    # session.add(st)
    # session.commit()
    # session.close()
    #
    # session=Session()
    # list=session.query(Student).all()
    # print(list)
    # session.commit()

    # page_size = 2
    # page_index = 1
    # Session = sessionmaker(bind=engine)
    # session = Session()
    # entity_query={
    #     First.id==988014
    # }
    # x=session.query(First).filter(*entity_query).limit(page_size).offset((page_index-1)*page_size).all()
    # print(x)
    # entity_query={}
    # print(session.query(First).filter(*entity_query).all())
    # session.close()
    # entity_query={}

    # print(FirstService().find_by_id(988014))

    query = {}
    entity_list = FirstService().find_pagenation(query, Pagenation())
    print(ReturnUtil().ok(entity_list))
def createBatch():
    json_dict = RequestBody()
    entities = [json_dict_entity(entity, First) for entity in json_dict]
    FirstService().create_batch(entities)
    return ReturnUtil().ok()
from FirstService.First import First
from FirstService.FirstService import FirstService
# from Application import app
from flask import Blueprint
from flask import request

from Pagenation import Pagenation
from RequestBase import RequestBody, json_dict_entity, json_to_query
from Utils.ReturnUtil import ReturnUtil

firstController = Blueprint("first", __name__)
first_service = FirstService()


@firstController.route('/find_by_id', methods=['GET'])
def find_by_id():
    id = request.args.get("id")  # 获取  get  参数
    entity = first_service.find_by_id(id)
    return ReturnUtil().ok(entity)


@firstController.route('/find_by_ids', methods=["POST"])
def find_by_ids():
    entity_list = first_service.find_by_ids(
        [1218444021506121730, 1209285449480388610])
    print(entity_list[0].id, entity_list[1].id)
    return ""


@firstController.route('/list', methods=["POST"])
def find_list():