Skip to content

Commit

Permalink
Fix test_server_operation_post_not_json unit test
Browse files Browse the repository at this point in the history
That test was failing on GitHub Actions when using Python 3.7
+ Flask 2.2.5. For some reason Flask returns `HTTP 400 Bad Request`
instead of `415 Unsupported Media Types` on such environment.

This commit works around that issue by changing the expected
value if such a combination is found.

References: BAR-133.

Signed-off-by: Israel Barth Rubio <[email protected]>
  • Loading branch information
barthisrael committed Nov 23, 2023
1 parent f5f2344 commit 4d12a51
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pg_backup_api/pg_backup_api/tests/test_utility_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
# along with Postgres Backup API. If not, see <http://www.gnu.org/licenses/>.

"""Unit tests for the REST API endpoints."""
from distutils.version import StrictVersion
import json
import sys
from unittest.mock import Mock, MagicMock, patch

import flask
import pytest

from pg_backup_api.server_operation import (OperationServerConfigError,
Expand Down Expand Up @@ -252,8 +255,20 @@ def test_server_operation_post_not_json(self, client):

response = client.post(path, data={})

assert response.status_code == 415
assert b"Unsupported Media Type" in response.data
expected_status_code = 415
expected_data = b"Unsupported Media Type"
version = sys.version_info

# This is an issue which was detected while running tests through
# GitHub Actions when using Python 3.7 and Flask 2.2.5. We might want
# to remove this once we remove support for Python 3.7
if version.major <= 3 and version.minor <= 7 and \
StrictVersion(flask.__version__) <= StrictVersion("2.2.5"):
expected_status_code = 400
expected_data = b"Bad Request"

assert response.status_code == expected_status_code
assert expected_data in response.data

@patch("pg_backup_api.logic.utility_controller.OperationServer", Mock())
@patch("pg_backup_api.logic.utility_controller.get_server_by_name")
Expand Down

0 comments on commit 4d12a51

Please sign in to comment.