def test_put_department_wrong_json(self, mock_abort): """Api should return information about department.""" with app.test_request_context(json=self.wrong_json): Department.put(1) mock_abort.assert_called_once_with(404, message=self.wrong_json_msg)
def test_put_department_not_valid(self, mock_abort): """Api should return information about department.""" with app.test_request_context(json=self.post_invalid_data): Department.put(1) mock_abort.assert_called_once_with(404, message=self.not_valid_json_msg)
def test_get_department_not_exist(self, mock_get_department, mock_abort): """Api should return information about department.""" mock_get_department.return_value = None Department.get(1) mock_abort.assert_called_once_with( 404, message="No such department with ID=1")
def test_put_department_fail(self, mock_update, mock_abort): """Api should return information about department.""" with app.test_request_context(json=self.post_valid_data): mock_update.return_value = False Department.put(1) mock_abort.assert_called_once_with(404, message=self.update_fail_msg)
def test_get_department_wrong_id_case2(self, mock_get_department, mock_abort): """Api should return error message if id have wrong format.""" mock_get_department.return_value = None Department.get(1.0) mock_abort.assert_called_once_with( 404, message="No such department with ID=1.0")
def test_put_department_success(self, mock_update): """Api should return information about department.""" with app.test_request_context(json=self.post_valid_data): mock_update.return_value = True response = Department.put(1) self.assertEqual(response.status_code, 201) self.assertEqual(response.json['message'], self.update_success_msg)
def test_get_department(self, mock_get_department): """Api should return information about department.""" mock_get_department.return_value = self.valid_test_data[0] response = Department.get(1) self.assertEqual(response.status_code, 200) self.assertEqual(response.json['department_id'], self.valid_test_data[0]['department_id']) self.assertEqual(response.json['manager'], self.valid_test_data[0]['manager']) self.assertEqual(response.json['date_of_creation'], self.valid_test_data[0]['date_of_creation']) self.assertEqual(response.json['employees'], self.valid_test_data[0]['employees']) self.assertEqual(response.json['department_avg_salary'], self.valid_test_data[0]['department_avg_salary']) self.assertEqual(response.json['name'], self.valid_test_data[0]['name'])
def test_get_department_wrong_id_case1(self, mock_abort): """Api should return error message if id have wrong format.""" Department.get('one') mock_abort.assert_called_once_with( 404, message="No such department with ID=one")