Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions graphene_linked_events/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
get_keyword_set_by_id,
json2obj,
json_object_hook,
retrieve_linked_events_data,
)
from occurrences.event_api_services import prepare_published_event_data
from occurrences.models import PalvelutarjotinEvent, VenueCustomData
Expand Down Expand Up @@ -491,15 +492,11 @@ def _test_events_p_event_relations(events_json):

@staticmethod
def resolve_event(parent, info, **kwargs):
response = api_client.retrieve(
"event",
kwargs.pop("id"),
params=kwargs,
is_event_staff=getattr(info.context.user, "is_event_staff", False),
event_id = kwargs.pop("id")
is_event_staff = getattr(info.context.user, "is_event_staff", False)
return retrieve_linked_events_data(
"event", event_id, params=kwargs, is_event_staff=is_event_staff
)
response.raise_for_status()
obj = json2obj(format_response(response))
return obj

@staticmethod
def resolve_events(parent, info, **kwargs): # noqa: C901
Expand Down Expand Up @@ -620,9 +617,7 @@ def resolve_place(parent, info, **kwargs):
place_id = kwargs["id"]
if not place_id:
return None
response = api_client.retrieve("place", place_id)
response.raise_for_status()
return json2obj(format_response(response))
return retrieve_linked_events_data("place", place_id)

@staticmethod
def resolve_places(parent, info, **kwargs):
Expand Down
52 changes: 50 additions & 2 deletions graphene_linked_events/tests/__snapshots__/test_api.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,30 @@
}),
})
# ---
# name: test_get_event_gone
dict({
'data': dict({
'event': None,
}),
'errors': list([
dict({
'extensions': dict({
'code': 'OBJECT_DOES_NOT_EXIST_ERROR',
}),
'locations': list([
dict({
'column': 3,
'line': 3,
}),
]),
'message': 'The resource is no longer available in the API (gone).',
'path': list([
'event',
]),
}),
]),
})
# ---
# name: test_get_event_not_found
dict({
'data': dict({
Expand All @@ -402,15 +426,15 @@
'errors': list([
dict({
'extensions': dict({
'code': 'GENERAL_ERROR',
'code': 'OBJECT_DOES_NOT_EXIST_ERROR',
}),
'locations': list([
dict({
'column': 3,
'line': 3,
}),
]),
'message': 'A mocked generic HTTP error',
'message': 'Could not find the event from the API.',
'path': list([
'event',
]),
Expand Down Expand Up @@ -915,6 +939,30 @@
}),
})
# ---
# name: test_get_place_gone
dict({
'data': dict({
'place': None,
}),
'errors': list([
dict({
'extensions': dict({
'code': 'OBJECT_DOES_NOT_EXIST_ERROR',
}),
'locations': list([
dict({
'column': 3,
'line': 3,
}),
]),
'message': 'The resource is no longer available in the API (gone).',
'path': list([
'place',
]),
}),
]),
})
# ---
# name: test_get_places
dict({
'data': dict({
Expand Down
42 changes: 41 additions & 1 deletion graphene_linked_events/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,24 @@ def mock_data(*args, **kwargs):
snapshot.assert_match(executed)


def test_get_event_gone(api_client, snapshot, monkeypatch):
"""Test that 410 (Gone) status code is handled as ObjectDoesNotExistError."""

def _get_mock_function(event_data, keyword_data, status_code=410):
def mock_data(*args, **kwargs):
return MockResponse(status_code=status_code, json_data={})

return mock_data

monkeypatch.setattr(
graphene_linked_events.rest_client.LinkedEventsApiClient,
"retrieve",
_get_mock_function(EVENT_DATA, KEYWORD_SET_DATA),
)
executed = api_client.execute(GET_EVENT_QUERY)
snapshot.assert_match(executed)


def test_get_places(api_client, snapshot, mock_get_places_data):
executed = api_client.execute(GET_PLACES_QUERY)
snapshot.assert_match(executed)
Expand All @@ -750,6 +768,24 @@ def test_get_place(api_client, snapshot, mock_get_place_data):
snapshot.assert_match(executed)


def test_get_place_gone(api_client, snapshot, monkeypatch):
"""Test that 410 (Gone) status code is handled as ObjectDoesNotExistError for places."""

def _get_mock_function(place_data, status_code=410):
def mock_data(*args, **kwargs):
return MockResponse(status_code=status_code, json_data={})

return mock_data

monkeypatch.setattr(
graphene_linked_events.rest_client.LinkedEventsApiClient,
"retrieve",
_get_mock_function({}),
)
executed = api_client.execute(GET_PLACE_QUERY)
snapshot.assert_match(executed)


def test_get_keywords(api_client, snapshot, mock_get_keywords_data):
executed = api_client.execute(GET_KEYWORDS_QUERY)
snapshot.assert_match(executed)
Expand Down Expand Up @@ -2243,7 +2279,11 @@ def mock_retrieve_with_mixed_results(

@pytest.mark.parametrize(
"status_code,error_cls",
[(400, ApiBadRequestError), (404, ObjectDoesNotExistError)],
[
(400, ApiBadRequestError),
(404, ObjectDoesNotExistError),
(410, ObjectDoesNotExistError),
],
)
def test_linkedevents_api_retrieve_errors(status_code, error_cls):
with patch.object(
Expand Down
5 changes: 5 additions & 0 deletions graphene_linked_events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def retrieve_linked_events_data(
if response.status_code == 404:
raise ObjectDoesNotExistError("Could not find the event from the API.")

if response.status_code == 410:
raise ObjectDoesNotExistError(
"The resource is no longer available in the API (gone)."
)

# Raise any other errors
response.raise_for_status()

Expand Down