def test_create_team_with_wrong_parameters(self, client): test_title = "test_team_1" test_data = {"new_wrong_title": test_title} resp = client.post(url_for("settings_team.team-create"), data=json.dumps(test_data)) assert resp.status_code == 400 assert resp.json == {"error": EXC_FIELD_IS_REQUIRED.format("title")}
def test_delete_project_with_wrong_parameters(self, client): test_data = {"id_for_delete": 1} resp = client.delete( url_for("settings_project.project-delete"), data=json.dumps(test_data), ) assert resp.status_code == 400 assert resp.json == {"error": EXC_FIELD_IS_REQUIRED.format("id")}
def test_update_cpu_price_with_wrong_parameters(self, client): test_server_id = 2 test_cpu_price = 5.2 test_data = {"id": test_server_id, "wrong_cpu_price": test_cpu_price} resp = client.put( url_for("settings_server.server-update-cpu-price"), data=json.dumps(test_data), ) assert resp.status_code == 400 assert resp.json == {"error": EXC_FIELD_IS_REQUIRED.format("cpu_price")}
def test_update_team_with_wrong_parameters(self, client): test_title = "test_new_title" test_team_id = 1 test_data = {"wrong_id": test_team_id, "title": test_title} resp = client.put( url_for("settings_team.team-update-title"), data=json.dumps(test_data), ) assert resp.status_code == 400 assert resp.json == {"error": EXC_FIELD_IS_REQUIRED.format("id")}
def test_detach_project_with_wrong_parameters(self, client): test_services_group_id = 2 test_data = {"wrong_services_group_id": test_services_group_id} resp = client.put( url_for("settings_project.project-detach"), data=json.dumps(test_data), ) assert resp.status_code == 400 assert resp.json == { "error": EXC_FIELD_IS_REQUIRED.format("services_group_id") }
def test_update_memory_price_with_wrong_parameters(self, client): test_cluster_id = 3 test_memory_price = 5.2 test_data = { "id": test_cluster_id, "wrong_memory_price": test_memory_price, } resp = client.put( url_for("settings_cluster.cluster-update-memory-price"), data=json.dumps(test_data), ) assert resp.status_code == 400 assert resp.json == { "error": EXC_FIELD_IS_REQUIRED.format("memory_price") }
def dispatch_request(self): data_for_delete = json.loads(request.data) if "id" in data_for_delete: try: valid_data_for_delete = UpdateProjectTeamModel( **data_for_delete) except ValidationError as e: return jsonify({"error": e.errors()}), 400 try: TeamManager( db.session).delete(team_id=valid_data_for_delete.id) except TeamManagerException as exc: return jsonify({"error": exc.error_text}), 400 return jsonify({"success": True}) return jsonify({"error": EXC_FIELD_IS_REQUIRED.format("id")}), 400
def dispatch_request(self): data_for_create = json.loads(request.data) if "title" in data_for_create: try: valid_data_for_create = UpdateProjectTeamModel( **data_for_create) except ValidationError as e: return jsonify({"error": e.errors()}), 400 try: new_team = TeamManager( db.session).create(title=valid_data_for_create.title) except TeamManagerException as exc: return jsonify({"error": exc.error_text}), 400 return jsonify({ "success": True, "id": new_team.id, "title": new_team.title }) return jsonify({"error": EXC_FIELD_IS_REQUIRED.format("title")}), 400
def dispatch_request(self): data_for_detach = json.loads(request.data) for parameter in PARAMETERS_DETACH_PROJECT_TEAM: if parameter not in data_for_detach: return ( jsonify({"error": EXC_FIELD_IS_REQUIRED.format(parameter)}), 400, ) try: valid_data_for_detach = AttachDetachProjectTeamModel( **data_for_detach) except ValidationError as e: return jsonify({"error": e.errors()}), 400 try: TeamManager(db.session).detach_from_services_group( services_group_id=valid_data_for_detach.services_group_id) except TeamManagerException as exc: return jsonify({"error": exc.error_text}), 400 return jsonify({"success": True})
def dispatch_request(self): data_for_update = json.loads(request.data) for parameter in PARAMETERS_SERVER_CLUSTER_CPU_PRICE: if parameter not in data_for_update: return ( jsonify({"error": EXC_FIELD_IS_REQUIRED.format(parameter)}), 400, ) try: valid_data_for_create = UpdateServerClusterModel(**data_for_update) except ValidationError as e: return jsonify({"error": e.errors()}), 400 try: ServerManager(db.session).set_cpu_price( server_id=valid_data_for_create.id, new_cpu_price=valid_data_for_create.cpu_price, ) except ServerManagerException as exc: return jsonify({"error": exc.error_text}), 400 return jsonify({"success": True})
def dispatch_request(self): data_for_update = json.loads(request.data) for parameter in PARAMETERS_PROJECT_TEAM: if parameter not in data_for_update: return ( jsonify({"error": EXC_FIELD_IS_REQUIRED.format(parameter)}), 400, ) try: valid_data_for_update = UpdateProjectTeamModel(**data_for_update) except ValidationError as e: return jsonify({"error": e.errors()}), 400 try: TeamManager(db.session).update( team_id=valid_data_for_update.id, new_title=valid_data_for_update.title, ) except TeamManagerException as exc: return jsonify({"error": exc.error_text}), 400 return jsonify({"success": True})