From 98663d3191fbd68d51a56017d4132329f7627dd2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 00:52:06 -0800 Subject: [PATCH] Bump fastapi[all] from 0.82.0 to 0.89.1 (#2246) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Thomas Co-authored-by: Thomas Co-authored-by: Adam Sachs --- .github/workflows/backend_checks.yml | 6 +-- noxfiles/test_setup_nox.py | 6 +-- requirements.txt | 2 +- .../api/v1/endpoints/connection_endpoints.py | 1 + .../ops/api/v1/endpoints/user_endpoints.py | 1 + .../service/connectors/fides/fides_client.py | 42 +++++++++------- .../ops/service/connectors/fides_connector.py | 7 +++ src/fides/cli/utils.py | 9 +++- src/fides/lib/oauth/schemas/oauth.py | 4 +- tests/ctl/cli/test_utils.py | 33 ++++--------- tests/ctl/conftest.py | 14 ++++-- tests/fixtures/application_fixtures.py | 4 ++ .../api/v1/endpoints/test_config_endpoints.py | 3 +- .../test_consent_request_endpoints.py | 6 ++- .../api/v1/endpoints/test_oauth_endpoints.py | 2 +- .../test_privacy_request_endpoints.py | 6 ++- .../endpoints/test_saas_config_endpoints.py | 2 +- tests/ops/integration_test_config.toml | 1 + .../connectors/fides/test_fides_client.py | 49 +++++++------------ .../connectors/test_fides_connector.py | 4 +- 20 files changed, 105 insertions(+), 97 deletions(-) diff --git a/.github/workflows/backend_checks.yml b/.github/workflows/backend_checks.yml index 445f95ea66..23f114c1d6 100644 --- a/.github/workflows/backend_checks.yml +++ b/.github/workflows/backend_checks.yml @@ -195,7 +195,7 @@ jobs: matrix: python_version: ["3.8.14", "3.9.14", "3.10.7"] runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 20 # In PRs run with the "unsafe" label, or run on a "push" event to main if: contains(github.event.pull_request.labels.*.name, 'run unsafe ci checks') || github.event_name == 'push' steps: @@ -232,7 +232,7 @@ jobs: matrix: python_version: ["3.8.14", "3.9.14", "3.10.7"] runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 20 # In PRs run with the "unsafe" label, or run on a "push" event to main if: contains(github.event.pull_request.labels.*.name, 'run unsafe ci checks') || github.event_name == 'push' steps: @@ -263,7 +263,7 @@ jobs: External-SaaS-Connectors: needs: Build runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 20 # In PRs run with the "unsafe" label, or run on a "push" event to main if: contains(github.event.pull_request.labels.*.name, 'run unsafe ci checks') || github.event_name == 'push' permissions: diff --git a/noxfiles/test_setup_nox.py b/noxfiles/test_setup_nox.py index 8024d23b64..7c6b8126e7 100644 --- a/noxfiles/test_setup_nox.py +++ b/noxfiles/test_setup_nox.py @@ -39,10 +39,11 @@ def pytest_ctl(session: Session, mark: str, coverage_arg: str) -> None: "-f", INTEGRATION_COMPOSE_FILE, "up", - "-d", + "--wait", IMAGE_NAME, ) session.run(*start_command, external=True) + session.run(*LOGIN, external=True) run_command = ( "docker", "exec", @@ -60,7 +61,6 @@ def pytest_ctl(session: Session, mark: str, coverage_arg: str) -> None: "OKTA_CLIENT_TOKEN", "-e", "BIGQUERY_CONFIG", - "--rm", CI_ARGS_EXEC, CONTAINER_NAME, "pytest", @@ -123,7 +123,6 @@ def pytest_ops(session: Session, mark: str, coverage_arg: str) -> None: "BIGQUERY_KEYFILE_CREDS", "-e", "BIGQUERY_DATASET", - "--rm", CI_ARGS_EXEC, CONTAINER_NAME, "pytest", @@ -154,7 +153,6 @@ def pytest_ops(session: Session, mark: str, coverage_arg: str) -> None: "VAULT_NAMESPACE", "-e", "VAULT_TOKEN", - "--rm", CI_ARGS_EXEC, CONTAINER_NAME, "pytest", diff --git a/requirements.txt b/requirements.txt index e65bd1de2d..65fa05f035 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ colorama>=0.4.3 cryptography==38.0.3 dask==2022.9.2 deepdiff==5.8.1 -fastapi[all]==0.82.0 +fastapi[all]==0.89.1 fastapi-caching[redis]==0.3.0 fastapi-pagination[sqlalchemy]~= 0.10.0 fideslang==1.3.3 diff --git a/src/fides/api/ops/api/v1/endpoints/connection_endpoints.py b/src/fides/api/ops/api/v1/endpoints/connection_endpoints.py index 71f4556eb4..8a2ffd1a20 100644 --- a/src/fides/api/ops/api/v1/endpoints/connection_endpoints.py +++ b/src/fides/api/ops/api/v1/endpoints/connection_endpoints.py @@ -210,6 +210,7 @@ def patch_connections( CONNECTION_BY_KEY, dependencies=[Security(verify_oauth_client, scopes=[CONNECTION_DELETE])], status_code=HTTP_204_NO_CONTENT, + response_model=None, ) def delete_connection( connection_key: FidesKey, *, db: Session = Depends(deps.get_db) diff --git a/src/fides/api/ops/api/v1/endpoints/user_endpoints.py b/src/fides/api/ops/api/v1/endpoints/user_endpoints.py index 600e493ebe..4de49a50cf 100644 --- a/src/fides/api/ops/api/v1/endpoints/user_endpoints.py +++ b/src/fides/api/ops/api/v1/endpoints/user_endpoints.py @@ -121,6 +121,7 @@ def update_user_password( urls.USER_FORCE_PASSWORD_RESET, dependencies=[Security(verify_oauth_client, scopes=[USER_PASSWORD_RESET])], status_code=HTTP_200_OK, + response_model=UserResponse, ) def force_update_password( *, diff --git a/src/fides/api/ops/service/connectors/fides/fides_client.py b/src/fides/api/ops/service/connectors/fides/fides_client.py index f45dbca240..db214c6a4e 100644 --- a/src/fides/api/ops/service/connectors/fides/fides_client.py +++ b/src/fides/api/ops/service/connectors/fides/fides_client.py @@ -2,10 +2,9 @@ from typing import Any, Dict, List, Optional -import requests -from httpx import AsyncClient +import httpx +from httpx import AsyncClient, Client, HTTPStatusError, Request, RequestError, Timeout from loguru import logger -from requests import PreparedRequest, Request, RequestException, Session from fides.api.ctl.utils.errors import FidesError from fides.api.ops.api.v1 import urn_registry as urls @@ -32,7 +31,7 @@ class FidesClient: """ - A helper client class to broker communications between Fides servers. + A helper client to broker communications between Fides servers. """ def __init__( @@ -40,8 +39,12 @@ def __init__( uri: str, username: str, password: str, + connection_read_timeout: float = 30.0, ): - self.session = Session() + # Enable setting a custom `read` timeout + # to account for privacy request executions + self.session = Client(timeout=Timeout(5.0, read=connection_read_timeout)) + self.uri = uri self.username = username self.password = password @@ -55,14 +58,14 @@ def login(self) -> None: self.username, ) try: - response = requests.post( + response = httpx.post( f"{self.uri}{urls.V1_URL_PREFIX}{urls.LOGIN}", json=ul.dict() ) - except RequestException as e: + except RequestError as e: logger.error("Error logging in on remote Fides {}: {}", self.uri, str(e)) raise e - if response.ok: + if response.is_success: self.token = response.json()["token_data"]["access_token"] logger.info( "Successfully logged in to remote fides {} with username '{}'", @@ -81,21 +84,21 @@ def authenticated_request( query_params: Optional[Dict[str, Any]] = {}, data: Optional[Any] = None, json: Optional[Any] = None, - ) -> PreparedRequest: + ) -> Request: if not self.token: raise FidesError( f"Unable to create authenticated request. No token for Fides connector for server {self.uri}" ) - req: PreparedRequest = Request( + req: Request = self.session.build_request( method=method, url=f"{self.uri}{path}", headers=headers, params=query_params, data=data, json=json, - ).prepare() + ) req.headers["Authorization"] = f"Bearer {self.token}" return req @@ -117,15 +120,17 @@ def create_privacy_request( external_id, self.uri, ) - request: PreparedRequest = self.authenticated_request( + request: Request = self.authenticated_request( method="POST", path=urls.V1_URL_PREFIX + urls.PRIVACY_REQUEST_AUTHENTICATED, json=[pr.dict()], ) response = self.session.send(request) - if not response.ok: + + if not response.is_success: logger.error("Error creating privacy request on remote Fides {}", self.uri) response.raise_for_status() + if response.json()["failed"]: # TODO better handle errored state here? raise FidesError( @@ -199,7 +204,7 @@ async def poll_for_request_completion( f"Privacy request [{privacy_request_id}] on remote Fides {self.uri} is in an unknown state. Look at the remote Fides for more information." ) - def request_status(self, privacy_request_id: str = None) -> List[Dict[str, Any]]: + def request_status(self, privacy_request_id: str = "") -> List[Dict[str, Any]]: """ Return privacy request object that tracks its status """ @@ -215,15 +220,16 @@ def request_status(self, privacy_request_id: str = None) -> List[Dict[str, Any]] self.uri, ) - request: PreparedRequest = self.authenticated_request( + request: Request = self.authenticated_request( method="GET", path=urls.V1_URL_PREFIX + urls.PRIVACY_REQUESTS, query_params={"request_id": privacy_request_id} if privacy_request_id else None, ) - response = self.session.send(request, timeout=5) - if not response.ok: + response = self.session.send(request) + + if not response.is_success: logger.error( "Error retrieving status of privacy request [{}] on remote Fides {}", privacy_request_id, @@ -266,7 +272,7 @@ def retrieve_request_results( headers={"Authorization": f"Bearer {self.token}"}, ) response = self.session.send(request) - except requests.exceptions.HTTPError as e: + except HTTPStatusError as e: logger.error( "Error retrieving data from child server for privacy request {}: {}", privacy_request_id, diff --git a/src/fides/api/ops/service/connectors/fides_connector.py b/src/fides/api/ops/service/connectors/fides_connector.py index c0c7529248..d07f0d7540 100644 --- a/src/fides/api/ops/service/connectors/fides_connector.py +++ b/src/fides/api/ops/service/connectors/fides_connector.py @@ -48,11 +48,18 @@ def query_config(self, node: TraversalNode) -> QueryConfig[Any]: def create_client(self) -> FidesClient: """Returns a client used to connect to a Fides instance""" config = FidesConnectorSchema(**self.configuration.secrets or {}) + + # use polling_timeout here to provide a base read timeout + # on the HTTP client underlying the FidesClient, since even + # in non-polling context, we may hit a blocking HTTP call + # e.g., in privacy request creation we can block until completion client = FidesClient( uri=config.uri, username=config.username, password=config.password, + connection_read_timeout=self.polling_timeout, ) + client.login() return client diff --git a/src/fides/cli/utils.py b/src/fides/cli/utils.py index 5c7ec76e7a..89882daaac 100644 --- a/src/fides/cli/utils.py +++ b/src/fides/cli/utils.py @@ -72,6 +72,12 @@ def check_server_health(server_url: str, verbose: bool = True) -> requests.Respo return health_response +def compare_application_versions(server_version: str, cli_version: str) -> bool: + """Normalize and compare application versions.""" + normalize_version = lambda v: str(v).replace(".dirty", "", 1) + return normalize_version(server_version) == normalize_version(cli_version) + + def check_server(cli_version: str, server_url: str, quiet: bool = False) -> None: """Runs a health check and a version check against the server.""" @@ -82,8 +88,7 @@ def check_server(cli_version: str, server_url: str, quiet: bool = False) -> None raise SystemExit(1) server_version = health_response.json()["version"] - normalize_version = lambda v: str(v).replace(".dirty", "", 1) - if normalize_version(server_version) == normalize_version(cli_version): + if compare_application_versions(server_version, cli_version): if not quiet: echo_green( "Server is reachable and the client/server application versions match." diff --git a/src/fides/lib/oauth/schemas/oauth.py b/src/fides/lib/oauth/schemas/oauth.py index 7275195109..97b86a5bae 100644 --- a/src/fides/lib/oauth/schemas/oauth.py +++ b/src/fides/lib/oauth/schemas/oauth.py @@ -44,7 +44,9 @@ def __init__( ) async def __call__(self, request: Request) -> Optional[str]: - authorization: str = request.headers.get("Authorization") + authorization: Optional[str] = request.headers.get("Authorization") + if not authorization: + raise InvalidAuthorizationSchemeError() scheme, param = get_authorization_scheme_param(authorization) if not authorization or scheme.lower() != "bearer": if self.auto_error: diff --git a/tests/ctl/cli/test_utils.py b/tests/ctl/cli/test_utils.py index 2ac38eae08..0f9081c8d2 100644 --- a/tests/ctl/cli/test_utils.py +++ b/tests/ctl/cli/test_utils.py @@ -4,10 +4,9 @@ import click import pytest -from requests_mock import Mocker import fides.cli.utils as utils -from fides.core.config import FidesConfig, get_config +from fides.core.config import FidesConfig from tests.ctl.conftest import orig_requests_get @@ -24,42 +23,30 @@ def test_check_server_bad_ping(test_client, monkeypatch) -> None: @pytest.mark.unit @pytest.mark.parametrize( - "server_version, cli_version, expected_output, quiet", + "server_version, cli_version, expected_result", [ - ("1.6.0+7.ge953df5", "1.6.0+7.ge953df5", "application versions match", False), - ("1.6.0+7.ge953df5", "1.6.0+9.ge953df5", "Mismatched versions!", False), + ("1.6.0+7.ge953df5", "1.6.0+7.ge953df5", True), + ("1.6.0+7.ge953df5", "1.6.0+9.ge953df5", False), ( "1.6.0+7.ge953df5", "1.6.0+7.ge953df5.dirty", - "application versions match", - False, + True, ), ( "1.6.0+7.ge953df5.dirty", "1.6.0+7.ge953df5", - "application versions match", - False, + True, ), - ("1.6.0+7.ge953df5", "1.6.0+7.ge953df5.dirty", None, True), ], ) def test_check_server_version_comparisons( - requests_mock: Mocker, - capsys: pytest.CaptureFixture, server_version: str, cli_version: str, - expected_output: str, - quiet: bool, + expected_result: str, ) -> None: - """Check that comparing versions works""" - fake_url = "http://fake_address:8080" - requests_mock.get(f"{fake_url}/health", json={"version": server_version}) - utils.check_server(cli_version, "http://fake_address:8080", quiet=quiet) - captured = capsys.readouterr() - if expected_output is None: - assert captured.out == "" - else: - assert expected_output in captured.out + """Check that version comparison works.""" + actual_result = utils.compare_application_versions(server_version, cli_version) + assert expected_result == actual_result @pytest.mark.unit diff --git a/tests/ctl/conftest.py b/tests/ctl/conftest.py index 7e86e7e0d3..be9f36eb5e 100644 --- a/tests/ctl/conftest.py +++ b/tests/ctl/conftest.py @@ -19,7 +19,10 @@ @pytest.fixture(scope="session") def monkeysession(): - """monkeypatch fixture at the session level instead of the function level""" + """ + Monkeypatch at the session level instead of the function level. + Automatically undoes the monkeypatching when the session finishes. + """ mpatch = MonkeyPatch() yield mpatch mpatch.undo() @@ -27,10 +30,11 @@ def monkeysession(): @pytest.fixture(autouse=True, scope="session") def monkeypatch_requests(test_client, monkeysession) -> None: - """The requests library makes requests against the running webserver - which talks to the application db. This monkeypatching operation - makes `requests` calls from src/fides/core/api.py in a test - context talk to the test db instead""" + """ + Some places within the application, for example `fides.core.api`, use the `requests` + library to interact with the webserver. This fixture patches those `requests` calls + so that all of those tests instead interact with the test instance. + """ monkeysession.setattr(requests, "get", test_client.get) monkeysession.setattr(requests, "post", test_client.post) monkeysession.setattr(requests, "put", test_client.put) diff --git a/tests/fixtures/application_fixtures.py b/tests/fixtures/application_fixtures.py index 083f5f5cab..3faa6bd326 100644 --- a/tests/fixtures/application_fixtures.py +++ b/tests/fixtures/application_fixtures.py @@ -126,6 +126,9 @@ "uri": pydash.get(integration_config, "fides_example.uri"), "username": pydash.get(integration_config, "fides_example.username"), "password": pydash.get(integration_config, "fides_example.password"), + "polling_timeout": pydash.get( + integration_config, "fides_example.polling_timeout" + ), }, } @@ -1604,6 +1607,7 @@ def test_fides_client( fides_connector_example_secrets["uri"], fides_connector_example_secrets["username"], fides_connector_example_secrets["password"], + fides_connector_example_secrets["polling_timeout"] ) diff --git a/tests/ops/api/v1/endpoints/test_config_endpoints.py b/tests/ops/api/v1/endpoints/test_config_endpoints.py index e76cdf29e7..018c7d04c0 100644 --- a/tests/ops/api/v1/endpoints/test_config_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_config_endpoints.py @@ -329,7 +329,8 @@ def test_get_application_config( # then we test that we can GET them auth_header = generate_auth_header([scopes.CONFIG_READ]) - response = api_client.get( + response = api_client.request( + "GET", url, headers=auth_header, params={"api_set": True}, diff --git a/tests/ops/api/v1/endpoints/test_consent_request_endpoints.py b/tests/ops/api/v1/endpoints/test_consent_request_endpoints.py index 094918993b..c691d9530c 100644 --- a/tests/ops/api/v1/endpoints/test_consent_request_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_consent_request_endpoints.py @@ -375,7 +375,8 @@ class TestGetConsentUnverified: def test_consent_unverified_no_consent_request_id(self, api_client): data = {"code": "12345"} - response = api_client.get( + response = api_client.request( + "GET", f"{V1_URL_PREFIX}{CONSENT_REQUEST_PREFERENCES_WITH_ID.format(consent_request_id='non_existent_consent_id')}", json=data, ) @@ -388,7 +389,8 @@ def test_consent_unverified_no_consent_request_id(self, api_client): def test_consent_unverified_verification_error(self, api_client): data = {"code": "12345"} - response = api_client.get( + response = api_client.request( + "GET", f"{V1_URL_PREFIX}{CONSENT_REQUEST_PREFERENCES_WITH_ID.format(consent_request_id='non_existent_consent_id')}", json=data, ) diff --git a/tests/ops/api/v1/endpoints/test_oauth_endpoints.py b/tests/ops/api/v1/endpoints/test_oauth_endpoints.py index dc815b4987..192bc30bd7 100644 --- a/tests/ops/api/v1/endpoints/test_oauth_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_oauth_endpoints.py @@ -501,7 +501,7 @@ def test_callback_for_valid_state( response = api_client.get( callback_url, params={"code": "abc", "state": "new_request"} ) - assert response.ok + response.raise_for_status() get_access_token_mock.assert_called_once() authentication_request.delete(db) diff --git a/tests/ops/api/v1/endpoints/test_privacy_request_endpoints.py b/tests/ops/api/v1/endpoints/test_privacy_request_endpoints.py index 611d651156..8e64bed76a 100644 --- a/tests/ops/api/v1/endpoints/test_privacy_request_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_privacy_request_endpoints.py @@ -1532,7 +1532,8 @@ def test_sort_privacy_request_by_due_date( api_client.post(url, json=data) auth_header = generate_auth_header(scopes=[PRIVACY_REQUEST_READ]) - resp = api_client.get( + resp = api_client.request( + "GET", f"{url}?sort_direction=asc&sort_field=due_date", json=data, headers=auth_header, @@ -1542,7 +1543,8 @@ def test_sort_privacy_request_by_due_date( for i, request in enumerate(asc_response_data): assert request["days_left"] == days_left_values[i] - resp = api_client.get( + resp = api_client.request( + "GET", f"{url}?sort_direction=desc&sort_field=due_date", json=data, headers=auth_header, diff --git a/tests/ops/api/v1/endpoints/test_saas_config_endpoints.py b/tests/ops/api/v1/endpoints/test_saas_config_endpoints.py index 03630a7c91..06a4b785ca 100644 --- a/tests/ops/api/v1/endpoints/test_saas_config_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_saas_config_endpoints.py @@ -450,5 +450,5 @@ def test_get_authorize_url( authorization_url_mock.return_value = authorization_url auth_header = generate_auth_header([CONNECTION_AUTHORIZE]) response = api_client.get(authorize_url, headers=auth_header) - assert response.ok + response.raise_for_status() assert response.text == f'"{authorization_url}"' diff --git a/tests/ops/integration_test_config.toml b/tests/ops/integration_test_config.toml index a2112f7120..e34d6a1f52 100644 --- a/tests/ops/integration_test_config.toml +++ b/tests/ops/integration_test_config.toml @@ -57,3 +57,4 @@ port=5432 uri="http://fides:8080" username="root_user" password="Testpassword1!" +polling_timeout=1800 diff --git a/tests/ops/service/connectors/fides/test_fides_client.py b/tests/ops/service/connectors/fides/test_fides_client.py index 5ab79ec58a..cd74561635 100644 --- a/tests/ops/service/connectors/fides/test_fides_client.py +++ b/tests/ops/service/connectors/fides/test_fides_client.py @@ -2,8 +2,7 @@ from unittest import mock import pytest -from httpx import AsyncClient -from requests import HTTPError, Session +from httpx import AsyncClient, Client, HTTPStatusError from fides.api.ctl.utils.errors import FidesError from fides.api.ops.models.privacy_request import PrivacyRequest, PrivacyRequestStatus @@ -17,8 +16,8 @@ class MockResponse: A class to mock Fides API responses """ - def __init__(self, ok, json_data): - self.ok = ok + def __init__(self, is_success, json_data): + self.is_success = is_success self.json_data = json_data def json(self): @@ -43,7 +42,7 @@ class TestFidesClientUnit: """ @mock.patch( - "requests.post", + "httpx.post", side_effect=[ MockResponse(True, {"token_data": {"access_token": SAMPLE_TOKEN}}) ], @@ -69,7 +68,7 @@ def test_authenticated_request(self, mock_login, test_fides_client: FidesClient) ) assert request.method == "GET" assert request.url == test_fides_client.uri + "/testpath" - assert len(request.headers) == 2 + assert len(request.headers) == 7 assert "another_header" in request.headers assert request.headers["another_header"] == "header_value" assert "Authorization" in request.headers @@ -88,7 +87,7 @@ def test_authenticated_request_not_logged_in(self, test_fides_client: FidesClien assert "No token" in str(exc) @mock.patch( - "requests.post", + "httpx.post", side_effect=[ MockResponse(True, {"token_data": {"access_token": SAMPLE_TOKEN}}) ], @@ -112,22 +111,6 @@ def test_authenticated_request_parameters( == test_fides_client.uri + "/testpath?param1=value1¶m2=value2" ) - # test form data passed as tuples - request = test_fides_client.authenticated_request( - "POST", - path="/testpath", - query_params={"param1": "value1", "param2": "value2"}, - data=[("key1", "value1"), ("key2", "value2")], - ) - assert "Authorization" in request.headers - assert request.headers["Authorization"] == f"Bearer {SAMPLE_TOKEN}" - assert request.method == "POST" - assert ( - request.url - == test_fides_client.uri + "/testpath?param1=value1¶m2=value2" - ) - assert request.body == "key1=value1&key2=value2" - # test form data passed as dict request = test_fides_client.authenticated_request( "POST", @@ -142,7 +125,8 @@ def test_authenticated_request_parameters( request.url == test_fides_client.uri + "/testpath?param1=value1¶m2=value2" ) - assert request.body == "key1=value1&key2=value2" + request.read() + assert request.content == b"key1=value1&key2=value2" # test body passed as string literal request = test_fides_client.authenticated_request( @@ -158,7 +142,8 @@ def test_authenticated_request_parameters( request.url == test_fides_client.uri + "/testpath?param1=value1¶m2=value2" ) - assert request.body == "testbody" + request.read() + assert request.content == b"testbody" # test json body passed as a dict request = test_fides_client.authenticated_request( @@ -174,7 +159,8 @@ def test_authenticated_request_parameters( request.url == test_fides_client.uri + "/testpath?param1=value1¶m2=value2" ) - assert request.body == b'{"field1": "value1"}' + request.read() + assert request.content == b'{"field1": "value1"}' # test json body passed as a list request = test_fides_client.authenticated_request( @@ -190,7 +176,8 @@ def test_authenticated_request_parameters( request.url == test_fides_client.uri + "/testpath?param1=value1¶m2=value2" ) - assert request.body == b'[{"field1": "value1"}]' + request.read() + assert request.content == b'[{"field1": "value1"}]' @pytest.mark.asyncio def test_poll_for_completion( @@ -301,7 +288,7 @@ def test_login_bad_credentials( # so that we don't call `create_client()`, which performs # login as part of initialization - with pytest.raises(HTTPError): + with pytest.raises(HTTPStatusError): test_fides_client_bad_credentials.login() assert test_fides_client_bad_credentials.token is None @@ -317,7 +304,7 @@ def test_create_privacy_request( Test that properly configured fides client can create and execute a valid access privacy request Inspired by `test_privacy_request_endpoints.TestCreatePrivacyRequest` """ - monkeypatch.setattr(Session, "send", api_client.send) + monkeypatch.setattr(Client, "send", api_client.send) pr_id = authenticated_fides_client.create_privacy_request( external_id="test_external_id", @@ -339,14 +326,14 @@ def test_request_status_no_privacy_request( privacy request ID specified. This acts as a basic test to validate we can successfully hit authenticated endpoints. """ - monkeypatch.setattr(Session, "send", api_client.send) + monkeypatch.setattr(Client, "send", api_client.send) statuses = authenticated_fides_client.request_status() assert len(statuses) == 0 def test_request_status_privacy_request( self, authenticated_fides_client: FidesClient, policy, monkeypatch, api_client ): - monkeypatch.setattr(Session, "send", api_client.send) + monkeypatch.setattr(Client, "send", api_client.send) pr_id = authenticated_fides_client.create_privacy_request( external_id="test_external_id", diff --git a/tests/ops/service/connectors/test_fides_connector.py b/tests/ops/service/connectors/test_fides_connector.py index a56bc96624..92277ec05d 100644 --- a/tests/ops/service/connectors/test_fides_connector.py +++ b/tests/ops/service/connectors/test_fides_connector.py @@ -2,7 +2,7 @@ from typing import Tuple import pytest -from requests import Session +from httpx import Client from fides.api.ops.graph.traversal import TraversalNode from fides.api.ops.models.connectionconfig import ConnectionConfig, ConnectionTestStatus @@ -128,7 +128,7 @@ def test_retrieve_data( # Monkey patch both Session.send and the httpx.AsyncClient. Both of these will just # make requests to the running webserver which is connected to the application db, # but we need them to talk to the test db in pytest - monkeypatch.setattr(Session, "send", api_client.send) + monkeypatch.setattr(Client, "send", api_client.send) monkeypatch.setattr( request_service, "get_async_client", lambda: async_api_client )