Skip to content

Commit

Permalink
Allow 204 No Content response (#4834)
Browse files Browse the repository at this point in the history
Co-authored-by: Kelsey Thomas <101993653+Kelsey-Ethyca@users.noreply.github.com>
  • Loading branch information
galvana and Kelsey-Ethyca committed May 2, 2024
1 parent 8c899c2 commit 8165baf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/fides/api/service/connectors/saas_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from loguru import logger
from requests import Response
from sqlalchemy.orm import Session
from starlette.status import HTTP_204_NO_CONTENT

from fides.api.common_exceptions import (
FidesopsException,
Expand Down Expand Up @@ -604,6 +605,9 @@ def _unwrap_response_data(saas_request: SaaSRequest, response: Response) -> Any:
"""
Unwrap given Response using data_path in the given SaasRequest
"""
if response.status_code == HTTP_204_NO_CONTENT:
return {}

try:
return (
pydash.get(response.json(), saas_request.data_path)
Expand Down
54 changes: 53 additions & 1 deletion tests/ops/service/connectors/test_saas_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from requests import Response
from sqlalchemy.orm import Session
from starlette.status import HTTP_200_OK, HTTP_404_NOT_FOUND
from starlette.status import HTTP_200_OK, HTTP_204_NO_CONTENT, HTTP_404_NOT_FOUND

from fides.api.common_exceptions import SkippingConsentPropagation
from fides.api.graph.execution import ExecutionNode
Expand Down Expand Up @@ -129,6 +129,15 @@ def test_unwrap_response_data_no_data_path(self):
unwrapped = SaaSConnector._unwrap_response_data(fake_request, fake_response)
assert response_body == unwrapped

def test_unwrap_response_no_content(self):
fake_request: SaaSRequest = SaaSRequest(
path="test/path", method=HTTPMethod.GET, data_path="user"
)
fake_response: Response = Response()
fake_response.status_code = HTTP_204_NO_CONTENT

assert SaaSConnector._unwrap_response_data(fake_request, fake_response) == {}

def test_delete_only_endpoint(
self, saas_example_config, saas_example_connection_config
):
Expand Down Expand Up @@ -196,6 +205,49 @@ def test_input_values(
{"fidesops_grouped_inputs": [], "conversation_id": ["456"]},
) == [{"id": "123", "from_email": "test@example.com"}]

@mock.patch("fides.api.service.connectors.saas_connector.AuthenticatedClient.send")
def test_no_content_response(
self, mock_send: Mock, saas_example_config, saas_example_connection_config
):
"""
Verifies that no rows are returned if the status code is 204 No Content
"""

# mock the 204 No Content response
mock_response = Response()
mock_response.status_code = HTTP_204_NO_CONTENT
mock_send.return_value = mock_response

saas_config = SaaSConfig(**saas_example_config)
graph = saas_config.get_graph(saas_example_connection_config.secrets)
node = Node(
graph,
next(
collection
for collection in graph.collections
if collection.name == "messages"
),
)
traversal_node = TraversalNode(node)
request_task = traversal_node.to_mock_request_task()
execution_node = ExecutionNode(request_task)

connector: SaaSConnector = get_connector(saas_example_connection_config)

privacy_request = PrivacyRequest(id="123")
privacy_request.cache_identity(Identity(email="test@example.com"))

assert (
connector.retrieve_data(
execution_node,
Policy(),
privacy_request,
request_task,
{"fidesops_grouped_inputs": [], "conversation_id": ["456"]},
)
== []
)

def test_missing_input_values(
self, saas_example_config, saas_example_connection_config
):
Expand Down

0 comments on commit 8165baf

Please sign in to comment.