Exemple #1
0
 def test_delete_ref_presence(self):
     test_entity_id = random.randint(1, MAX_ENTITY_NUM)
     test_entity_ref_id = Operator.get_by_id(Employee,
                                             test_entity_id).department_id
     Operator.remove(Employee, test_entity_id)
     self.assertIsNotNone(Operator.get_by_id(Department,
                                             test_entity_ref_id))
Exemple #2
0
 def test_update(self):
     test_entity_new = Employee.random()
     test_entity_new.id = random.randint(1, MAX_ENTITY_NUM)
     Operator.update(Employee, marsh(test_entity_new, EmployeeSchema))
     self.assertEqual(
         marsh(test_entity_new, EmployeeSchema),
         marsh(Operator.get_by_id(Employee, test_entity_new.id),
               EmployeeSchema))
Exemple #3
0
    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)
Exemple #4
0
    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)
Exemple #5
0
    def test_update(self):
        test_entity_new = Department.random()
        test_entity_new.id = random.randint(1, MAX_ENTITY_NUM)

        self.assertTrue(
            Operator.update(Department,
                            marsh(vars(test_entity_new), DepartmentSchema)))
Exemple #6
0
 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)
Exemple #7
0
    def get(self, id_):
        """Gets a department from the database by the id.

        Returns:
            Retreived department using marshal or
            aborts with 404 if department was not present.
        """

        entity = Operator.get_by_id(Department, id_)
        return entity if entity else abort(404)
Exemple #8
0
    def get(self, id_):
        """Gets an employee from the database by the id.

        Returns:
            Retreived employee using marshal or
            aborts with 404 code.
        """

        entity = Operator.get_by_id(Employee, id_)
        return entity if entity else abort(404)
Exemple #9
0
    def post(self):
        """Adds a department to the database.

        Returns:
            Department's id using marshal or
            aborts with 404.
        """

        try:
            raw_data = lomarsh(request.form, DepartmentSchema)
            raw_data['id'] = None
            return Operator.insert(Department(**raw_data))
        except IntegrityError:
            abort(400)
Exemple #10
0
    def post(self):
        """Adds an employee to the database.

        Returns:
            Employee's id using marshal or
            aborts with code 400.
        """

        try:
            raw_data = lomarsh(request.form, EmployeeSchema)
            raw_data['id'] = None
            return Operator.insert(Employee(**raw_data))
        except (IntegrityError, ValidationError):
            abort(400)
Exemple #11
0
    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))))
Exemple #12
0
    def put(self, id_):
        """Updates an employee from the database by the id.

        Returns:
            True (if the operation was successful)
            or False using marshal or aborts
            with 400 code.
        """

        try:
            raw_data = lomarsh(request.form, EmployeeSchema)
            raw_data['id'] = id_
            return Operator.update(Employee, raw_data)
        except (IntegrityError, InternalError, ValidationError):
            abort(400)
Exemple #13
0
    def put(self, id_):
        """Updates a department from the database by the id.

        Returns:
            True (if the operation was successful)
            or False using marshal or aborts with
            code 400.
        """

        try:
            raw_data = lomarsh(request.form, DepartmentSchema)
            raw_data['id'] = id_
            return Operator.update(Department, raw_data)
        except (IntegrityError, ValidationError):
            abort(400)
Exemple #14
0
 def test_insert(self):
     test_entity = Department.random()
     test_entity_id = Operator.insert(test_entity)
     self.assertEqual(test_entity,
                      Operator.get_by_id(Department, test_entity_id))
Exemple #15
0
 def test_delete_refs_presence(self):
     test_entity_id = Operator.get_by_id(
         Employee, random.randint(1, MAX_ENTITY_NUM)).department_id
     Operator.remove(Department, test_entity_id)
     self.assertFalse(
         Employee.query.filter_by(department_id=test_entity_id).all())
Exemple #16
0
 def test_get(self):
     test_entity_id = random.randint(1, MAX_ENTITY_NUM)
     self.assertIsNotNone(Operator.get_by_id(Employee, test_entity_id))
Exemple #17
0
 def test_get_all(self):
     self.assertEqual(MAX_ENTITY_NUM, len(Operator.get_all(Employee)))
Exemple #18
0
 def test_insert(self):
     test_entity = Employee.random()
     test_entity_id = Operator.insert(test_entity)
     self.assertEqual(test_entity,
                      Operator.get_by_id(Employee, test_entity_id))
Exemple #19
0
 def test_get_all(self):
     self.assertEqual(MAX_ENTITY_NUM, len(Operator.get_all(Department)))
Exemple #20
0
 def test_delete_instance_presence(self):
     test_entity_id = random.randint(1, MAX_ENTITY_NUM)
     Operator.remove(Department, test_entity_id)
     self.assertIsNone(Operator.get_by_id(Department, test_entity_id))