コード例 #1
0
def test_delete(app):
    department_to_delete = DepartmentServices.get_by_id(1)
    DepartmentServices.delete(department_to_delete)
    departments = DepartmentServices.get_all()
    employees = EmployeeServices.get_all()
    assert department_to_delete not in departments
    assert len(departments) == 1
    # to check if cascade delete happened
    assert len(employees) == 3
コード例 #2
0
 def get(self, emp_id=None):
     """
     This method is called when GET request is sent to
     "/api/v1/employees/[<int:id>]" url.
     :return: if "id" not specified the list of all employees in json format,
     status code 200. If id specified -  the employee with the specified id
     serialized to json. If invalid id - error message and status code 404.
     """
     if not emp_id:
         employees = EmployeeServices.get_all()
         return self.employee_schema.dump(employees, many=True), 200
     employee = EmployeeServices.get_by_id(emp_id)
     if not employee:
         return {"message": f"Employee with id {emp_id} not found"}, 404
     return self.employee_schema.dump(employee), 200