def insert_materials(): body = request.get_json() search = body.get('search') if search is None: try: material = materials() material.mat_name = body.get('material_name') material.mat_desc = body.get('material_description') material.insert() return jsonify({ "success": True, "inserted_material_id": material.id }) except: abort(400) else: try: allMats = materials.searchByName(search) if allMats is None: abort(404) return jsonify({ "success": True, "materials_count": len(allMats), "materials": allMats }) except: abort(500)
def insert_order(self): material = materials() material.mat_name = "test 15" material.mat_desc = "test desc 15" material.insert() order = orders() order.order_notes = "order note15" order.insert() details = orders_details() details.quantity = 10 details.price = 15 details.material_det = material details.order_det = order details.insert() return order.id
def update_materials(material_id): body = request.get_json() material = materials() material = materials.query.get(material_id) if material is None: abort(404) try: material.mat_name = body.get('material_name') material.mat_desc = body.get('material_description') material.update() return jsonify({ "success": True, "updated_material": material.format() }) except: abort(500)
def test_update_material(self): material = materials() material.mat_name = "test 15" material.mat_desc = "test desc 15" material.insert() res = self.client().patch( '/materials/{}'.format(material.id), json={ "material_name": "hot choccolate 44", "material_description": "del choccolate 44" }, headers={'Authorization': self.accountant_key}) data = json.loads(res.data) material1 = data["updated_material"] self.assertTrue(data["success"]) self.assertTrue(data["updated_material"]) self.assertEqual(material1["name"], "hot choccolate 44") self.assertEqual(material1["description"], "del choccolate 44") self.assertEqual(material1["id"], material.id)
def insert_material(self): material = materials() material.mat_name = "test 15" material.mat_desc = "test desc 15" material.insert() return material