Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-31894)[API] feat: remove description double writing #14209

Merged
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
1 change: 0 additions & 1 deletion api/src/pcapi/core/offers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def build_new_offer_from_product(
) -> models.Offer:
return models.Offer(
bookingEmail=venue.bookingEmail,
description=product.description, # type: ignore[call-arg]
extraData=product.extraData,
idAtProvider=id_at_provider,
lastProviderId=provider_id,
Expand Down
5 changes: 4 additions & 1 deletion api/src/pcapi/core/offers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,10 @@ def description(self) -> str | None:

@description.setter
def description(self, value: str | None) -> None:
self._description = value
if self.product:
self._description = None
else:
self._description = value

@property
def isEducational(self) -> bool:
Expand Down
1 change: 0 additions & 1 deletion api/src/pcapi/local_providers/allocine/allocine_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def fill_object_attributes(self, pc_object: Model) -> None:
def update_from_movie_information(self, offer: offers_models.Offer) -> None:
offer.name = self.product.name
offer.extraData = offer.extraData or offers_models.OfferExtraData()
offer.description = self.product.description
offer.durationMinutes = self.product.durationMinutes
offer.product = self.product
if self.product.extraData:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def update_from_movie_information(
offer.extraData = offer.extraData or offers_models.OfferExtraData()
if self.product:
offer.name = self.product.name
offer.description = self.product.description
offer.durationMinutes = self.product.durationMinutes
if self.product.extraData:
offer.extraData.update(self.product.extraData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def update_from_movie_information(self, offer: offers_models.Offer) -> None:
offer.extraData = offer.extraData or offers_models.OfferExtraData()
if self.product:
offer.name = self.product.name
offer.description = self.product.description
offer.durationMinutes = self.product.durationMinutes
if self.product.extraData:
offer.extraData.update(self.product.extraData)
Expand Down
7 changes: 7 additions & 0 deletions api/tests/core/providers/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import pcapi.core.providers.factories as providers_factories
from pcapi.core.users import factories as users_factories
from pcapi.local_providers.provider_api import synchronize_provider_api
from pcapi.models import db
from pcapi.routes.serialization.venue_provider_serialize import PostVenueProviderBody


Expand Down Expand Up @@ -212,6 +213,7 @@ def test_execution(self, mock_async_index_offer_ids):

# Test fill offers attributes
assert created_offer.bookingEmail == venue.bookingEmail
assert created_offer._description is None
assert created_offer.description == product.description
assert created_offer.extraData == product.extraData
assert created_offer.name == product.name
Expand Down Expand Up @@ -287,10 +289,15 @@ def test_build_new_offers_from_stock_details(self):
provider_id=provider.id,
)

# We need to commit to have the offer description property working
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question : même pas avec un flush() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, avec un flush j'ai offer.description = None

db.session.add_all([*new_offers, product])
db.session.commit()

# Then
assert len(new_offers) == 1
new_offer = new_offers[0]
assert new_offer.bookingEmail == "booking_email"
assert new_offer._description is None
assert new_offer.description == "product_desc"
assert new_offer.extraData == {"extra": "data"}
assert new_offer.idAtProvider == "ean_product_ref"
Expand Down
1 change: 1 addition & 0 deletions api/tests/local_providers/allocine_stocks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_should_create_one_offer_with_movie_info(self, mock_call_allocine_api, m
created_offer = offers_models.Offer.query.one()

assert created_offer.bookingEmail == "toto@example.com"
assert created_offer._description is None
assert (
created_offer.description
== "Alors que la Premi\u00e8re Guerre Mondiale a \u00e9clat\u00e9, et en r\u00e9ponse aux propos des intellectuels allemands de l'\u00e9poque, Sacha Guitry filme les grands artistes de l'\u00e9poque qui contribuent au rayonnement culturel de la France.\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def should_fill_offer_and_stock_informations_for_each_movie_based_on_product(sel
assert created_offers[0].product == self._get_product_by_allocine_id(270935)
assert created_offers[0].venue == venue_provider.venue
assert created_offers[0].offererAddressId == venue_provider.venue.offererAddressId
assert created_offers[0]._description is None
assert created_offers[0].description == "Description du produit allociné 3"
assert created_offers[0].durationMinutes == 333
assert created_offers[0].isDuo
Expand All @@ -164,6 +165,7 @@ def should_fill_offer_and_stock_informations_for_each_movie_based_on_product(sel
assert created_offers[1].name == "Produit allociné 4"
assert created_offers[1].product == self._get_product_by_allocine_id(269975)
assert created_offers[1].venue == venue_provider.venue
assert created_offers[1]._description is None
assert created_offers[1].description == "Description du produit allociné 4"
assert created_offers[1].durationMinutes == 444
assert created_offers[1].isDuo
Expand Down Expand Up @@ -231,6 +233,7 @@ def should_fill_offer_and_stocks_and_price_categories_based_on_product(self, req
assert created_offer.name == "Produit allociné 1"
assert created_offer.product == self._get_product_by_allocine_id(263242)
assert created_offer.venue == venue_provider.venue
assert created_offer._description is None
assert created_offer.description == "Description du produit allociné 1"
assert created_offer.durationMinutes == 111
assert created_offer.isDuo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def should_fill_offer_and_stock_informations_for_each_movie(self, mock_get_venue
assert created_offers[0].product
assert created_offers[0].venue == venue_provider.venue
assert created_offers[0].offererAddressId == venue_provider.venue.offererAddressId
assert created_offers[0]._description is None
assert created_offers[0].description == "Description du produit allociné 1"
assert created_offers[0].durationMinutes == 111
assert created_offers[0].isDuo
Expand Down
4 changes: 4 additions & 0 deletions api/tests/routes/pro/post_draft_offer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def test_created_offer_from_product_should_return_product_id(self, client):
assert response_dict["productId"] == product.id
assert response_dict["extraData"] == {"ean": "9782123456803"}
assert offer.product == product
assert offer._description is None
assert offer.description == product.description

def test_create_offer_other_than_CD_or_vinyl_without_EAN_code_should_succeed_for_record_store(self, client):
venue = offerers_factories.VenueFactory(venueTypeCode=VenueTypeCode.RECORD_STORE)
Expand Down Expand Up @@ -165,6 +167,8 @@ def test_create_offer_record_store_cd_or_vinyl_with_valid_ean_code(self, client)
assert response_dict["productId"] == offer.productId
assert response_dict["extraData"] == {"gtl_id": "07000000", "ean": "1234567891234"}
assert offer.product == product
assert offer.description == product.description
assert offer._description is None

def test_create_offer_on_venue_with_accessibility_informations(self, client):
venue = offerers_factories.VenueFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_valid_ean_with_stock(self, client):

created_offer = offers_models.Offer.query.one()
assert created_offer.bookingEmail == venue.bookingEmail
assert created_offer._description is None
assert created_offer.description == product.description
assert created_offer.extraData == product.extraData
assert created_offer.lastProvider.name == "Technical provider"
Expand Down
Loading