def test_put_location_fail(self, mock_update, mock_abort): """Api should return information about location.""" with app.test_request_context(json=self.post_valid_data): mock_update.return_value = False Location.put(1) mock_abort.assert_called_once_with(404, message=self.update_fail_msg)
def test_get_location(self, mock_get_location): """Api should return information about location.""" mock_get_location.return_value = self.valid_test_data[0] response = Location.get(1) self.assertEqual(response.status_code, 200) self.assertEqual(response.json['id'], self.valid_test_data[0]['id']) self.assertEqual(response.json['name'], self.valid_test_data[0]['name'])
def test_put_location_success(self, mock_update): """Api should return information about location.""" with app.test_request_context(json=self.post_valid_data): mock_update.return_value = True response = Location.put(1) self.assertEqual(response.status_code, 201) self.assertEqual(response.json['message'], self.update_success_msg)
def test_get_location_not_exist(self, mock_get_location, mock_abort): """Api should return information about location.""" mock_get_location.return_value = None Location.get(1) mock_abort.assert_called_once_with(404, message="No such location with ID=1")
def test_get_location_wrong_id_case2(self, mock_abort): """Api should return information about location.""" Location.get(-1) mock_abort.assert_called_once_with(404, message="No such location with ID=-1")
def test_put_location_wrong_json(self, mock_abort): """Api should return information about location.""" with app.test_request_context(json=self.wrong_json): Location.put(1) mock_abort.assert_called_once_with(404, message=self.wrong_json_msg)
def test_put_location_not_valid(self, mock_abort): """Api should return information about location.""" with app.test_request_context(json=self.post_invalid_data): Location.put(1) mock_abort.assert_called_once_with(404, message=self.not_valid_json_msg)