def test_add_hole_without_height(add_wall): wall = Wall.query.first() Wall.add_hole(wall.id, width=1.2, amount=2) hole = Hole.query.first() assert hole.height == None with pytest.raises(ValueError): assert hole.area
def test_update_processing_when_done_above_1(add_wall): wall = Wall.query.first() Wall.add_processing(wall.id, year=2020, month="December", done=0.6) processing = wall.processing[0] Wall.edit_processing(processing.id, done=1.35) assert wall.processing[0].done == 1.0 assert wall.left_to_sale == 0.0
def test_add_processing_when_overrun(add_wall): wall = Wall.query.first() Wall.add_processing(wall.id, year=2020, month="December", done=0.4) Wall.add_processing(wall.id, year=2020, month="December", done=0.7) wall = Wall.query.filter_by(id=wall.id).first() assert wall.processing.filter_by(id=1).first().done == 0.4 assert wall.processing.filter_by(id=2).first().done == 0.6 assert wall.left_to_sale == 0.0
def add_wall() -> str: form = WallForm(g.current_invest.id) if form.validate_on_submit(): Wall.add_wall(g.current_invest.id, **form.data) flash("You added a new wall.") return redirect(url_for("masonry_works.walls")) return render_template("production/masonry_works/forms/wall_form.html", title="Add Wall", form=form)
def add_hole() -> str: wall_id = request.args.get("wall_id") form = HoleForm() if form.validate_on_submit(): Wall.add_hole(wall_id, **form.data) flash("You added a new hole.") next_page = request.args.get("next_page") if not next_page: next_page = url_for("masonry_works.modify", wall_id=wall_id) return redirect(next_page) return render_template("production/masonry_works/forms/hole_form.html", title="Add Hole", form=form)
def test_update_wall(add_wall): wall = Wall.query.first() assert wall.wall_height == 3.1 assert wall.gross_wall_area == 32.55 assert wall.wall_area_to_survey == 32.55 assert wall.wall_area_to_sale == 32.55 assert wall.left_to_sale == 1.0 Wall.edit_wall(wall.id, floor_ord=4) assert wall.wall_height == 2.2 assert wall.gross_wall_area == 23.1 assert wall.wall_area_to_survey == 23.1 assert wall.wall_area_to_sale == 23.1 assert wall.left_to_sale == 1.0
def test_update_hole(add_wall): wall = Wall.query.first() Wall.add_hole(wall.id, width=1.2, height=2.0, amount=2) assert wall.holes[0].width == 1.2 assert wall.holes[0].height == 2.0 assert wall.holes[0].amount == 2 assert wall.wall_area_to_survey == 27.75 hole = wall.holes[0] Wall.edit_hole(hole.id, width=1.5, height=2.5, amount=1) assert wall.holes[0].width == 1.5 assert wall.holes[0].height == 2.5 assert wall.holes[0].amount == 1 assert wall.wall_area_to_survey == 28.8
def create_wall(): data = request.get_json() or {} if 'width' not in data or 'height' not in data or 'grade' not in data: return bad_request('must include width, height and grade') wall = Wall() data['active'] = False wall.from_dict(data) db.session.add(wall) db.session.commit() response = jsonify(wall.to_dict()) response.status_code = 201 response.headers['Location'] = url_for('api.get_wall', wallid=wall.id) return response
def test_post(client, test_with_authenticated_user, wall_data): Wall.add_wall(**wall_data) wall = Wall.query.first() wall_data["sector"] = "A" form = WallForm(original_local_id=wall.local_id, **wall_data) assert wall.sector == "G" response = client.post( url_for("masonry_works.edit_wall", wall_id=wall.id), data=form.data, follow_redirects=True, ) assert response.status_code == 200 assert b"You modified the wall." in response.data assert wall.sector == "A"
def add_new_wall(data): uuid = data.get('uuid') name = data.get('name') texture_id = data.get('texture_id') room_id = data.get('room_id') x_pos = data.get('x_pos') y_pos = data.get('y_pos') z_pos = data.get('z_pos') user_id = get_user_id(uuid=uuid) if user_id: wall = Wall(room_id=room_id, texture_id=texture_id, name=name, x_pos=x_pos, y_pos=y_pos, z_pos=z_pos) wall.save() return generate_wall_created_success_response(wall) else: return generate_user_not_login_response()
def test_upload_holes(app_and_db, add_investment): investment = Investment.query.first() Wall.upload_walls(investment.id, "test/walls.csv") Wall.upload_holes(investment.id, "test/holes.csv") messages = Wall.upload_holes(investment.id, "test/holes.csv") assert len(Hole.query.all()) == 5 assert len(messages) == 3 assert messages[0] == "Uploaded 5 items." assert ( messages[1] == "Items: [5, 1, 1, 1] not added because they has the wrong format.") assert ( messages[2] == "Items: [6, 7, 12, 13, 14, 15, 16, 17] not added because wall with specified id does not exist. Add wall first." )
def delete_processing() -> str: wall_id = request.args.get("wall_id") proc_id = request.args.get("proc_id") form = WarrantyForm() if form.validate_on_submit(): if form.no.data: flash("Processing has not been deleted.") elif form.yes.data: Wall.delete_processing(proc_id) flash("Processing has been deleted.") return redirect(url_for("masonry_works.processing", wall_id=wall_id)) return render_template( "warranty_form.html", title="Delete Processing", form=form, )
def test_update_processing(add_wall): wall = Wall.query.first() Wall.add_processing(wall.id, year=2020, month="December", done=0.3) assert wall.processing[0].year == 2020 assert wall.processing[0].month == "December" assert wall.processing[0].done == 0.3 assert wall.left_to_sale == 0.7 processing = wall.processing[0] Wall.edit_processing(processing.id, year=2021, month="January", done=0.6) assert wall.processing[0].year == 2021 assert wall.processing[0].month == "January" assert wall.processing[0].done == 0.6 assert wall.left_to_sale == 0.4
def delete_hole() -> str: wall_id = request.args.get("wall_id") hole_id = request.args.get("hole_id") form = WarrantyForm() if form.validate_on_submit(): if form.no.data: flash("Hole has not been deleted.") elif form.yes.data: Wall.delete_hole(hole_id) flash("Hole has been deleted.") return redirect(url_for("masonry_works.holes", wall_id=wall_id)) return render_template( "warranty_form.html", title="Delete Hole", form=form, )
def walls() -> str: sector = request.args.get("sector") level = request.args.get("level") localization = request.args.get("localization") brick_type = request.args.get("brick_type") wall_width = request.args.get("wall_width") items = Wall.get_all_items(g.current_invest.id) if sector: items = items.filter_by(sector=sector) if level: items = items.filter_by(level=level) if localization: items = items.filter_by(localization=localization) if brick_type: items = items.filter_by(brick_type=brick_type) if wall_width: items = items.filter_by(wall_width=wall_width) items = items.order_by("local_id").all() total = TotalAreas(items) return render_template( "production/masonry_works/walls.html", title="Walls", items=items, total=total, categories=Categories(Wall), )
def validate_local_id(self, local_id): if local_id.data != self.original_local_id: ids = [ wall.local_id for wall in Wall.get_all_items(self.invest_id).all() ] if local_id.data in ids: raise ValidationError("Id must be unique!")
def edit_processing() -> str: wall_id = request.args.get("wall_id") proc_id = request.args.get("proc_id") processing = Processing.query.filter_by(id=proc_id).first() form = ProcessingForm() if form.validate_on_submit(): Wall.edit_processing(proc_id, **form.data) flash("You modified the processing.") return redirect(url_for("masonry_works.processing", wall_id=wall_id)) elif request.method == "GET": form.year.data = processing.year form.month.data = processing.month form.done.data = processing.done return render_template( "production/masonry_works/forms/processing_form.html", title="Edit Processing", form=form, )
def test_upload_processing(app_and_db, add_investment): investment = Investment.query.first() Wall.upload_walls(investment.id, "test/walls.csv") Wall.upload_processing(investment.id, "test/processing.csv") messages = Wall.upload_processing(investment.id, "test/processing.csv") assert len(Processing.query.all()) == 6 assert len(messages) == 4 assert messages[0] == "Uploaded 6 items." assert ( messages[1] == "Items: [1, 1, 1, 2, 2] not added because they has the wrong format." ) assert ( messages[2] == "Items: [7, 8, 9] not added because wall with specified id does not exist. Add wall first." ) assert (messages[3] == "Items: [1, 3] not added because value of left_to_sale is 0.")
def edit_hole() -> str: wall_id = request.args.get("wall_id") hole_id = request.args.get("hole_id") hole = Hole.query.filter_by(id=hole_id).first() form = HoleForm() if form.validate_on_submit(): Wall.edit_hole(hole_id, **form.data) flash("You modified the hole.") return redirect(url_for("masonry_works.holes", wall_id=wall_id)) elif request.method == "GET": form.width.data = hole.width form.height.data = hole.height form.amount.data = hole.amount return render_template( "production/masonry_works/forms/hole_form.html", title="Edit Hole", form=form, )
def test_add_wall(app_and_db, wall_data): Wall.add_wall(**wall_data) wall = Wall.query.first() Wall.add_hole(wall.id, width=1.2, height=2.0, amount=2) Wall.add_hole(wall.id, width=2.2, height=2.0, amount=1) Wall.add_processing(wall.id, year=2020, month="December", done=0.4) assert wall.wall_height == 3.1 assert wall.gross_wall_area == 32.55 assert wall.wall_area_to_survey == 23.35 assert wall.wall_area_to_sale == 29.15 assert wall.left_to_sale == 0.6
def delete_wall() -> str: wall_id = request.args.get("wall_id") form = WarrantyForm() if form.validate_on_submit(): if form.no.data: flash("Wall has not been deleted.") next_page = request.args.get("next_page") if not next_page: next_page = url_for("masonry_works.walls") return redirect(next_page) elif form.yes.data: Wall.delete_wall(wall_id) flash("Wall has been deleted.") return redirect(url_for("masonry_works.walls")) return render_template( "warranty_form.html", title="Delete Wall", form=form, )
def test_upload_walls(app_and_db, add_investment): investment = Investment.query.first() messages = Wall.upload_walls(investment.id, "test/walls.csv") assert len(Wall.query.all()) == 5 assert len(messages) == 2 assert messages[0] == "Uploaded 6 items." assert ( messages[1] == "Items: [8, 9, 10, 11, 12, 13, 14, 15] not added because they has the wrong format." ) assert Wall.query.filter_by(id=1).first().wall_width == 18
def processing() -> str: wall_id = request.args.get("wall_id") items = Processing.get_items_by_wall_id(wall_id) left_to_sale = Wall.get_left_to_sale(wall_id) return render_template( "production/masonry_works/processing.html", title="Processing", items=items, wall_id=wall_id, left_to_sale=left_to_sale, )
def edit_wall() -> str: wall_id = request.args.get("wall_id") wall = Wall.query.filter_by(id=wall_id).first() form = WallForm(invest_id=g.current_invest.id, original_local_id=wall.local_id) if form.validate_on_submit(): Wall.edit_wall(wall_id, **form.data) flash("You modified the wall.") return redirect(url_for("masonry_works.modify", wall_id=wall_id)) elif request.method == "GET": form.local_id.data = wall.local_id form.sector.data = wall.sector form.level.data = wall.level form.localization.data = wall.localization form.brick_type.data = wall.brick_type form.wall_width.data = wall.wall_width form.wall_length.data = wall.wall_length form.floor_ord.data = wall.floor_ord form.ceiling_ord.data = wall.ceiling_ord return render_template( "production/masonry_works/forms/wall_form.html", title="Edit Wall", form=form, )
def test_update_processing_when_overrun(add_wall): wall = Wall.query.first() Wall.add_processing(wall.id, year=2020, month="December", done=0.6) Wall.add_processing(wall.id, year=2020, month="December", done=0.3) assert wall.processing.filter_by(id=1).first().done == 0.6 assert wall.processing.filter_by(id=2).first().done == 0.3 assert wall.left_to_sale == 0.1 Wall.edit_processing(2, done=0.5) assert wall.processing.filter_by(id=1).first().done == 0.6 assert wall.processing.filter_by(id=2).first().done == 0.4 assert wall.left_to_sale == 0.0
def test_create_item_when_wrong_attribute(wall_data): wall_data["wrong_attr"] = 5 item = Wall.create_item(**wall_data) assert item
def get_walls(): page = request.args.get('page', 1, type=int) per_page = min(request.args.get('per_page', 1000, type=int), 1000) data = Wall.to_collection_dict(Wall.query, page, per_page, 'api.get_walls') data['active'] = any(wall.active is True for wall in Wall.query.all()) return jsonify(data)
def add_processing(app_and_db): Wall.add_processing(wall_id=1, year=2020, month="December", done=0.4)
def add_hole(app_and_db): Wall.add_hole(wall_id=1, width=1.2, height=2.25, amount=2)
def add_wall(app_and_db, wall_data): Wall.add_wall(**wall_data)