def add(): gender = request.form.get('info_gender', type=int) age = request.form.get('info_age', type=int) province = request.form.get('info_province') stock = request.form.get('info_stock', type=int) insurance = request.form.get('info_ins', type=int) travel = request.form.get('info_travel', type=int) children = request.form.get('info_children', type=int) monthly = request.form.get('info_monthly', type=int) rent = request.form.get('info_rent', type=int) income = request.form.get('info_income', type=int) savings = request.form.get('info_savings', type=int) plan = PlanData(id_=None, gender=gender, user_id=None, age=age, province_code=province, stock=stock, rent=rent, mpayment=monthly, insurance=insurance, tour=travel, has_children=children, savings=savings, mincome=income, create_time=None, update_time=None) validator = Formula(plan=plan).validate() if validator['code'] == errors.err_ok: session['wxplan'] = plan.to_dict() if g.user: PlanData.add_or_update(gender=gender, user_id=g.user.id, age=age, province_code=province, stock=stock, rent=rent, mpayment=monthly, insurance=insurance, tour=travel, has_children=children, savings=savings, mincome=income) return jsonify(r=True) return jsonify(r=False, d=validator)
def test_validation(self): account = self.add_account() user_id = account.id plan = PlanData(id_=None, gender=1, user_id=user_id, age=30, province_code=u'110000', stock=1, rent=123, mpayment=123, insurance=1, tour=1, has_children=1, savings=10000, mincome=2000, create_time=None, update_time=None) formula = Formula(plan=plan) validator = formula.validate() assert validator == {'name': 'result', 'code': errors.err_ok}
def test_gen_simple_report(self): plan = PlanData(id_=None, gender=1, user_id=None, age=30, province_code=u'110000', stock=-1, rent=1, mpayment=-1, insurance=-1, tour=-1, has_children=-1, savings=20, mincome=20, update_time=None, create_time=None) formula = Formula(plan=plan) assert formula.get_practice_need_msavings_factor() == 0 assert formula.get_practice_pocket_money_factor() == 19 assert formula.get_theory_children_tour_factor() == 0 assert formula.get_practice_children_tour_factor() == 0 assert abs(formula.get_this_year_norm_dist() - 0.401612399) < 0.00001 assert abs(formula.get_raise_quota() - Decimal(0.0365)) < Decimal(0.00001)