Skip to content

Commit

Permalink
(BSR)[API] feat: allocine api: showtimes: allow None language
Browse files Browse the repository at this point in the history
Allow None to be a showtime language... and remove it from the languages
list. It will avoid useless validation errors.
  • Loading branch information
jbaudet-pass committed Jul 15, 2024
1 parent a8cbd84 commit 9495baa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ class AllocineShowtime(pydantic.BaseModel):
def get_first_projection_mode(cls, projection: list[AllocineShowtimeProjection]) -> AllocineShowtimeProjection:
return projection[0]

@pydantic.field_validator("languages", mode="before")
def drop_none_values(cls, languages: list | None) -> list | None:
if languages:
return [l for l in languages if l is not None]
return languages


class AllocineMovieShowtime(pydantic.BaseModel):
movie: AllocineMovie
Expand Down
15 changes: 14 additions & 1 deletion api/tests/connectors/api_allocine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,20 @@ def test_should_drop_invalid_showtimes_and_move_on(self, requests_mock):
valid_edge = copy.deepcopy(payload["movieShowtimeList"]["edges"][0])
payload["movieShowtimeList"]["edges"].append(valid_edge)
# one and only movie becomes invalid because of one showtime language
payload["movieShowtimeList"]["edges"][0]["node"]["showtimes"][0]["languages"] = [None]
payload["movieShowtimeList"]["edges"][0]["node"]["showtimes"][0]["languages"] = ["invalid"]

requests_mock.get.return_value = MockedResponse(data=payload, status_code=200)
api_response = get_movies_showtimes_from_allocine("does not matter")

expected_result = copy.deepcopy(fixtures.MOVIE_SHOWTIME_LIST)
assert api_response == allocine_serializers.AllocineMovieShowtimeListResponse.model_validate(expected_result)

@patch("pcapi.connectors.api_allocine.requests")
def test_accept_showtimes_with_a_none_language(self, requests_mock):
payload = copy.deepcopy(fixtures.MOVIE_SHOWTIME_LIST)

# invalid language should be filtered and the edge kept
payload["movieShowtimeList"]["edges"][0]["node"]["showtimes"][0]["languages"].append(None)

requests_mock.get.return_value = MockedResponse(data=payload, status_code=200)
api_response = get_movies_showtimes_from_allocine("does not matter")
Expand Down

0 comments on commit 9495baa

Please sign in to comment.