Пример #1
0
    def test_get_employee_not_exist(self, mock_get_employee, mock_abort):
        """Api should return information about employee."""
        mock_get_employee.return_value = None
        Employee.get(1)

        mock_abort.assert_called_once_with(
            404, message="No such employee with ID=1")
Пример #2
0
    def test_put_employee_not_valid(self, mock_abort):
        """Api should return information about employee."""
        with app.test_request_context(json=self.post_invalid_data):
            Employee.put(1)

            mock_abort.assert_called_once_with(404,
                                               message=self.not_valid_json_msg)
Пример #3
0
    def test_get_employee_wrong_id_case2(self, mock_get_employee, mock_abort):
        """Api should return error message if id have wrong format."""
        mock_get_employee.return_value = None
        Employee.get(1.0)

        mock_abort.assert_called_once_with(
            404, message="No such employee with ID=1.0")
Пример #4
0
    def test_put_employee_fail(self, mock_update, mock_abort):
        """Api should return information about employee."""
        with app.test_request_context(json=self.post_valid_data):
            mock_update.return_value = False
            Employee.put(1)

            mock_abort.assert_called_once_with(404,
                                               message=self.update_fail_msg)
Пример #5
0
    def test_put_employee_success(self, mock_update):
        """Api should return information about employee."""
        with app.test_request_context(json=self.post_valid_data):
            mock_update.return_value = True
            response = Employee.put(1)

            self.assertEqual(response.status_code, 201)
            self.assertEqual(response.json['message'], self.update_success_msg)
Пример #6
0
    def test_get_employee(self, mock_get_employee):
        """Api should return information about employee."""
        mock_get_employee.return_value = self.valid_test_data[0]
        response = Employee.get(1)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json['name'],
                         self.valid_test_data[0]['name'])
        self.assertEqual(response.json['surname'],
                         self.valid_test_data[0]['surname'])
        self.assertEqual(response.json['date_of_birth'],
                         self.valid_test_data[0]['date_of_birth'])
        self.assertEqual(response.json['salary'],
                         self.valid_test_data[0]['salary'])
        self.assertEqual(response.json['email'],
                         self.valid_test_data[0]['email'])
        self.assertEqual(response.json['phone'],
                         self.valid_test_data[0]['phone'])
        self.assertEqual(response.json['date_of_joining'],
                         self.valid_test_data[0]['date_of_joining'])
        self.assertEqual(response.json['department'],
                         self.valid_test_data[0]['department'])
        self.assertEqual(response.json['location'],
                         self.valid_test_data[0]['location'])
        self.assertEqual(response.json['work_address'],
                         self.valid_test_data[0]['work_address'])
        self.assertEqual(response.json['key_skill'],
                         self.valid_test_data[0]['key_skill'])
        self.assertEqual(response.json['permission'],
                         self.valid_test_data[0]['permission'])
        self.assertEqual(response.json['department_id'],
                         self.valid_test_data[0]['department_id'])
        self.assertEqual(response.json['employee_id'],
                         self.valid_test_data[0]['employee_id'])
        self.assertEqual(response.json['location_id'],
                         self.valid_test_data[0]['location_id'])
        self.assertEqual(response.json['address_id'],
                         self.valid_test_data[0]['address_id'])
        self.assertEqual(response.json['skill_id'],
                         self.valid_test_data[0]['skill_id'])
        self.assertEqual(response.json['permission_id'],
                         self.valid_test_data[0]['permission_id'])
Пример #7
0
    def test_get_employee_wrong_id_case3(self, mock_abort):
        """Api should return error message if id have wrong format."""
        Employee.get(-1)

        mock_abort.assert_called_once_with(
            404, message="No such employee with ID=-1")