def get(self): """Returns filtered list of departments from the db using marshal.""" try: search_params = lomarsh(request.args, DepartmentSearchSchema) return Operator.get_all( Department, search_expr=self._get_search_expr(search_params)) except ValidationError: abort(400)
def delete(self, id_): """Deletes a department from the database by the id. Returns: All the departments from the db using marshal or aborts with 404 code. """ if Operator.remove(Department, id_): return Operator.get_all(Department) abort(404)
def delete(self, id_): """Deletes an employee from the database by the id. Returns: All the employees from the db using marshal or aborts with 404 code. """ if Operator.remove(Employee, id_): return Operator.get_all(Employee) abort(404)
def random(cls): """Generates a random instance of the class. Returns: An instance of the class with randomly generated attributes. """ fake = Faker() fake.add_provider(date_time) return Employee(name=fake.name(), birthdate=fake.date_between(start_date='-50y', end_date='-18y'), salary=fake.random_int(MIN_SALARY, MAX_SALARY, step=1), department_id=fake.random_element(elements=tuple( d.id for d in Operator.get_all(Department))))
def test_get_all(self): self.assertEqual(MAX_ENTITY_NUM, len(Operator.get_all(Employee)))
def test_get_all(self): self.assertEqual(MAX_ENTITY_NUM, len(Operator.get_all(Department)))