• Flask CURD


    from app import db

    class Curd(object):
    def init(self,modelName):
    self.db_model = globals()[modelName]

    def read(self,**filters):
        '''
    
        :param filters: {key1:value1,key2,value2}
        :return:
        '''
        obj = self.db_model.query.filter_by(**filters).all()
        return obj
    
    def create(self, records):
        '''
        根据db_model向不同的表中插入测试数据
        :param modelName:
        :param records: [{},{}]
        :return:
        '''
        for record in records:
            api_purpose = record['api_purpose']
            request_url = record['request_url']
            request_method = record['request_method']
            request_data_type = record['request_data_type']
            request_data = record['request_data']
            assert_method = record['assert_method']
            check_point = record['check_point']
            correlation = record['correlation']
            active = record['active']
            creater = record['creater']
            project = record['project']
    
            case = self.db_model(api_purpose=api_purpose, request_url=request_url,
                                           request_method=request_method,
                                           request_data_type=request_data_type, request_data=request_data,
                                           assert_method=assert_method, check_point=check_point,
                                           correlation=correlation, active=active,
                                           creater=creater, project=project)
    
            db.session.add(case)
        db.session.commit()
    
    def update(self, **kwargs):
        pass
    
    def delete(self):
        pass
  • 相关阅读:
    知识点拾遗——装饰器
    知识点拾遗——函数部分
    re模块和分组
    re模块进阶
    面向对象总结
    模块总结整理
    项目目录结构
    日志(模块logging)
    位、字节、字符 概念
    socketserver实现并发通讯
  • 原文地址:https://www.cnblogs.com/ziki/p/13952010.html
Copyright © 2020-2023  润新知