-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-31878)[API]fix: Update offer extra data allowed only if offer is …
…not product base and FF WIP_EAN_CREATION id disabled
- Loading branch information
1 parent
e689ef9
commit eab5788
Showing
14 changed files
with
166 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,36 +45,26 @@ def test_patch_draft_offer(self, client): | |
assert updated_offer.description == "New description" | ||
assert not updated_offer.product | ||
|
||
@override_features(WIP_EAN_CREATION=False) | ||
def test_patch_draft_offer_with_ean(self, client): | ||
@override_features(WIP_EAN_CREATION=True) | ||
def test_patch_draft_offer_without_product_with_new_ean_should_succeed(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
offer = offers_factories.OfferFactory( | ||
name="Name", | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
description="description", | ||
url="http://example.com/offer", | ||
extraData={"ean": "1111111111111"}, | ||
) | ||
|
||
data = { | ||
"name": "New name", | ||
"description": "New description", | ||
"subcategoryId": subcategories.LIVRE_PAPIER.id, | ||
"extraData": {"gtl_id": "07000000", "ean": "1234567891234"}, | ||
} | ||
response = client.with_session_auth("[email protected]").patch(f"/offers/draft/{offer.id}", json=data) | ||
data = {"extraData": {"ean": "2222222222222"}} | ||
response = client.with_session_auth("[email protected]").patch(f"offers/draft/{offer.id}", json=data) | ||
|
||
assert response.status_code == 200 | ||
assert response.json["id"] == offer.id | ||
assert response.json["venue"]["id"] == offer.venue.id | ||
assert response.json["productId"] == None | ||
|
||
updated_offer = Offer.query.get(offer.id) | ||
assert updated_offer.name == "New name" | ||
assert updated_offer.subcategoryId == subcategories.LIVRE_PAPIER.id | ||
assert updated_offer.description == "New description" | ||
assert updated_offer.extraData["ean"] == "1234567891234" | ||
assert not updated_offer.product | ||
assert updated_offer.extraData["ean"] == "2222222222222" | ||
|
||
@override_features(WIP_EAN_CREATION=True) | ||
def test_patch_draft_offer_without_product(self, client): | ||
|
@@ -177,6 +167,29 @@ def test_patch_draft_offer_with_empty_extra_data(self, client): | |
"visa": "", | ||
} | ||
|
||
@override_features(WIP_EAN_CREATION=False) | ||
def test_patch_draft_offer_with_product_with_same_extra_data_should_succeed(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
product = offers_factories.ProductFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, extraData={"gtl_id": "07000000", "ean": "1111111111111"} | ||
) | ||
offer = offers_factories.OfferFactory( | ||
name="Name", | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
description="description", | ||
url="http://example.com/offer", | ||
extraData={"author": "1111111111111"}, | ||
product=product, | ||
) | ||
|
||
data = { | ||
"extraData": {"author": "1111111111112"}, | ||
} | ||
response = client.with_session_auth("[email protected]").patch(f"/offers/draft/{offer.id}", json=data) | ||
assert response.status_code == 200 | ||
|
||
def test_patch_draft_offer_with_existing_extra_data_with_new_extra_data(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
|
@@ -315,23 +328,28 @@ def when_trying_to_patch_forbidden_attributes(self, client): | |
assert key in response.json | ||
|
||
@override_features(WIP_EAN_CREATION=True) | ||
def when_trying_to_patch_ean(self, client): | ||
def when_trying_to_patch_offer_with_product_with_new_ean(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory( | ||
managingOfferer=user_offerer.offerer, venueTypeCode=VenueTypeCode.RECORD_STORE | ||
) | ||
product = offers_factories.ProductFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, extraData={"ean": "1111111111111"} | ||
) | ||
offer = offers_factories.OfferFactory( | ||
name="Name", | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
description="description", | ||
extraData={"ean": "1111111111111"}, | ||
product=product, | ||
) | ||
|
||
data = {"extraData": {"ean": "1234567891234"}} | ||
data = {"extraData": {"ean": "2222222222222"}} | ||
response = client.with_session_auth("[email protected]").patch(f"offers/draft/{offer.id}", json=data) | ||
|
||
assert response.status_code == 400 | ||
assert response.json["ean"] == ["Vous ne pouvez pas changer cette information"] | ||
assert response.json["global"] == ["Les extraData des offres avec produit ne sont pas modifialbles"] | ||
|
||
def when_trying_to_patch_product(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
from pcapi.core.offers.models import WithdrawalTypeEnum | ||
import pcapi.core.providers.factories as providers_factories | ||
from pcapi.core.providers.repository import get_provider_by_local_class | ||
from pcapi.core.testing import override_features | ||
import pcapi.core.users.factories as users_factories | ||
from pcapi.utils.date import format_into_utc_date | ||
|
||
|
@@ -55,6 +56,58 @@ def test_patch_offer(self, client): | |
assert updated_offer.subcategoryId == subcategories.ABO_PLATEFORME_VIDEO.id | ||
assert not updated_offer.product | ||
|
||
def test_patch_offer_with_extra_data_should_not_remove_extra_data(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
offer = offers_factories.OfferFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
extraData={"gtl_id": "01010101", "author": "Kewis Larol"}, | ||
) | ||
|
||
data = { | ||
"name": "New name", | ||
"mentalDisabilityCompliant": True, | ||
} | ||
response = client.with_session_auth("[email protected]").patch(f"/offers/{offer.id}", json=data) | ||
|
||
assert response.status_code == 200 | ||
assert response.json["id"] == offer.id | ||
assert response.json["venue"]["id"] == offer.venue.id | ||
|
||
updated_offer = Offer.query.get(offer.id) | ||
assert updated_offer.extraData["gtl_id"] == "01010101" | ||
assert updated_offer.extraData["author"] == "Kewis Larol" | ||
assert updated_offer.mentalDisabilityCompliant | ||
assert updated_offer.subcategoryId == subcategories.LIVRE_PAPIER.id | ||
assert not updated_offer.product | ||
|
||
@override_features(WIP_EAN_CREATION=True) | ||
def test_patch_offer_with_product_with_same_ean(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VirtualVenueFactory(managingOfferer=user_offerer.offerer) | ||
product = offers_factories.ProductFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, extraData={"ean": "1111111111111"} | ||
) | ||
offer = offers_factories.OfferFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
name="New name", | ||
url="[email protected]", | ||
description="description", | ||
extraData={"ean": "1111111111111"}, | ||
product=product, | ||
) | ||
|
||
data = {"extraData": {"ean": "1111111111111"}} | ||
response = client.with_session_auth("[email protected]").patch(f"/offers/{offer.id}", json=data) | ||
|
||
assert response.status_code == 200 | ||
assert response.json["id"] == offer.id | ||
|
||
updated_offer = Offer.query.get(offer.id) | ||
assert updated_offer.extraData == {"ean": "1111111111111"} | ||
|
||
def test_patch_offer_with_provider_extra_data(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
|
@@ -579,6 +632,29 @@ def test_booking_contact_is_checked_when_changed(self, client): | |
"Une offre qui a un ticket retirable doit avoir l'email du contact de réservation" | ||
] | ||
|
||
@override_features(WIP_EAN_CREATION=True) | ||
def should_fail_when_trying_to_update_offer_with_product_with_new_ean(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
product = offers_factories.ProductFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, extraData={"ean": "1111111111111"} | ||
) | ||
offer = offers_factories.OfferFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
name="New name", | ||
url="[email protected]", | ||
description="description", | ||
extraData={"ean": "1111111111111"}, | ||
product=product, | ||
) | ||
|
||
data = {"extraData": {"ean": "2222222222222"}} | ||
response = client.with_session_auth("[email protected]").patch(f"/offers/{offer.id}", json=data) | ||
|
||
assert response.status_code == 400 | ||
assert response.json["global"] == ["Les extraData des offres avec produit ne sont pas modifialbles"] | ||
|
||
|
||
class Returns403Test: | ||
def when_user_is_not_attached_to_offerer(self, app, client): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.