-
Notifications
You must be signed in to change notification settings - Fork 37
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-31878)[API]fix: Mise à jour des extraData d'offres sur les conditional_fields seulement #14194
Merged
pcharlet-pass
merged 1 commit into
master
from
pcharlet/pc-31878-patch-offer-extra-data
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,32 @@ def test_patch_draft_offer_without_product(self, client): | |
assert updated_offer.description == "New description" | ||
assert not updated_offer.product | ||
|
||
def test_patch_draft_offer_with_form_required_fields_should_not_update_existing_extra_data(self, client): | ||
def test_patch_draft_with_extra_data(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
offer = offers_factories.EventOfferFactory( | ||
name="Film", | ||
venue=venue, | ||
subcategoryId=subcategories.SEANCE_CINE.id, | ||
isDuo=False, | ||
description="description", | ||
extraData=None, | ||
) | ||
|
||
data = { | ||
"name": "Film", | ||
"description": "description", | ||
"subcategoryId": subcategories.SEANCE_CINE.id, | ||
"extraData": {"stageDirector": "Greta Gerwig"}, | ||
} | ||
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 | ||
|
||
updated_offer = Offer.query.get(offer.id) | ||
assert updated_offer.extraData == {"stageDirector": "Greta Gerwig"} | ||
|
||
def test_patch_draft_offer_with_empty_extra_data(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VirtualVenueFactory(managingOfferer=user_offerer.offerer) | ||
ems_provider = get_provider_by_local_class("EMSStocks") | ||
|
@@ -118,7 +143,7 @@ def test_patch_draft_offer_with_form_required_fields_should_not_update_existing_ | |
lastProviderId=cinema_provider_pivot.provider.id, | ||
isDuo=False, | ||
description="description", | ||
extraData={"stageDirector": "Greta Gerwig"}, | ||
extraData=None, | ||
) | ||
|
||
data = { | ||
|
@@ -132,7 +157,7 @@ def test_patch_draft_offer_with_form_required_fields_should_not_update_existing_ | |
"showType": "", | ||
"showSubType": "", | ||
"speaker": "", | ||
"stageDirector": "Greta Gerwig", | ||
"stageDirector": "", | ||
"visa": "", | ||
}, | ||
} | ||
|
@@ -141,22 +166,48 @@ def test_patch_draft_offer_with_form_required_fields_should_not_update_existing_ | |
assert response.json["id"] == offer.id | ||
|
||
updated_offer = Offer.query.get(offer.id) | ||
assert updated_offer.extraData == {"stageDirector": "Greta Gerwig"} | ||
assert updated_offer.extraData == { | ||
"author": "", | ||
"gtl_id": "", | ||
"performer": "", | ||
"showType": "", | ||
"showSubType": "", | ||
"speaker": "", | ||
"stageDirector": "", | ||
"visa": "", | ||
} | ||
|
||
def test_patch_draft_offer_with_form_required_fields_should_not_create_extra_data(self, client): | ||
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.VirtualVenueFactory(managingOfferer=user_offerer.offerer) | ||
ems_provider = get_provider_by_local_class("EMSStocks") | ||
venue_provider = providers_factories.VenueProviderFactory(provider=ems_provider, venue=venue) | ||
cinema_provider_pivot = providers_factories.CinemaProviderPivotFactory(venue=venue_provider.venue) | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
offer = offers_factories.EventOfferFactory( | ||
name="Film", | ||
venue=venue_provider.venue, | ||
venue=venue, | ||
subcategoryId=subcategories.SEANCE_CINE.id, | ||
lastProviderId=cinema_provider_pivot.provider.id, | ||
isDuo=False, | ||
description="description", | ||
extraData=None, | ||
extraData={ | ||
"cast": ["Joan Baez", "Joe Cocker", "David Crosby"], | ||
"eidr": "10.5240/ADBD-3CAA-43A0-7BF0-86E2-K", | ||
"type": "FEATURE_FILM", | ||
"visa": "37205", | ||
"title": "Woodstock", | ||
"genres": ["DOCUMENTARY", "HISTORICAL", "MUSIC"], | ||
"credits": [ | ||
{"person": {"lastName": "Wadleigh", "firstName": "Michael"}, "position": {"name": "DIRECTOR"}} | ||
], | ||
"runtime": 185, | ||
"theater": {"allocine_room_id": "W0135", "allocine_movie_id": 2634}, | ||
"backlink": "https://www.allocine.fr/film/fichefilm_gen_cfilm=2634.html", | ||
"synopsis": "Le plus important rassemblement de la musique pop de ces vingt derni\u00e8res ann\u00e9es. Des groupes qui ont marqu\u00e9 leur \u00e9poque et une jeunesse qui a marqu\u00e9 la sienne.", | ||
"companies": [{"name": "Wadleigh-Maurice", "activity": "Production"}], | ||
"countries": ["USA"], | ||
"posterUrl": "https://fr.web.img2.acsta.net/pictures/14/06/20/12/25/387023.jpg", | ||
"allocineId": 2634, | ||
"originalTitle": "Woodstock", | ||
"stageDirector": "Michael Wadleigh", | ||
"productionYear": 1970, | ||
}, | ||
) | ||
|
||
data = { | ||
|
@@ -170,16 +221,59 @@ def test_patch_draft_offer_with_form_required_fields_should_not_create_extra_dat | |
"showType": "", | ||
"showSubType": "", | ||
"speaker": "", | ||
"stageDirector": "", | ||
"stageDirector": "Greta Gerwig", | ||
"visa": "", | ||
"cast": ["Joan Baez", "Joe Cocker", "David Crosby"], | ||
"eidr": "10.5240/ADBD-3CAA-43A0-7BF0-86E2-K", | ||
"type": "FEATURE_FILM", | ||
"title": "Woodstock", | ||
"genres": ["DOCUMENTARY", "HISTORICAL", "MUSIC"], | ||
"credits": [ | ||
{"person": {"lastName": "Wadleigh", "firstName": "Michael"}, "position": {"name": "DIRECTOR"}} | ||
], | ||
"runtime": 185, | ||
"theater": {"allocine_room_id": "W0135", "allocine_movie_id": 2634}, | ||
"backlink": "https://www.allocine.fr/film/fichefilm_gen_cfilm=2634.html", | ||
"synopsis": "Le plus important rassemblement de la musique pop de ces vingt derni\u00e8res ann\u00e9es. Des groupes qui ont marqu\u00e9 leur \u00e9poque et une jeunesse qui a marqu\u00e9 la sienne.", | ||
"companies": [{"name": "Wadleigh-Maurice", "activity": "Production"}], | ||
"countries": ["USA"], | ||
"posterUrl": "https://fr.web.img2.acsta.net/pictures/14/06/20/12/25/387023.jpg", | ||
"allocineId": 2634, | ||
"originalTitle": "Woodstock", | ||
"productionYear": 1970, | ||
}, | ||
} | ||
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 | ||
|
||
updated_offer = Offer.query.get(offer.id) | ||
assert updated_offer.extraData == {} | ||
assert updated_offer.extraData == { | ||
"cast": ["Joan Baez", "Joe Cocker", "David Crosby"], | ||
"eidr": "10.5240/ADBD-3CAA-43A0-7BF0-86E2-K", | ||
"type": "FEATURE_FILM", | ||
"visa": "", | ||
"title": "Woodstock", | ||
"genres": ["DOCUMENTARY", "HISTORICAL", "MUSIC"], | ||
"credits": [{"person": {"lastName": "Wadleigh", "firstName": "Michael"}, "position": {"name": "DIRECTOR"}}], | ||
"runtime": 185, | ||
"theater": {"allocine_room_id": "W0135", "allocine_movie_id": 2634}, | ||
"backlink": "https://www.allocine.fr/film/fichefilm_gen_cfilm=2634.html", | ||
"synopsis": "Le plus important rassemblement de la musique pop de ces vingt derni\u00e8res ann\u00e9es. Des groupes qui ont marqu\u00e9 leur \u00e9poque et une jeunesse qui a marqu\u00e9 la sienne.", | ||
"companies": [{"name": "Wadleigh-Maurice", "activity": "Production"}], | ||
"countries": ["USA"], | ||
"posterUrl": "https://fr.web.img2.acsta.net/pictures/14/06/20/12/25/387023.jpg", | ||
"allocineId": 2634, | ||
"originalTitle": "Woodstock", | ||
"stageDirector": "Greta Gerwig", | ||
"productionYear": 1970, | ||
"author": "", | ||
"gtl_id": "", | ||
"performer": "", | ||
"showType": "", | ||
"showSubType": "", | ||
"speaker": "", | ||
} | ||
|
||
|
||
@pytest.mark.usefixtures("db_session") | ||
|
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
from pcapi.core.offers.models import Offer | ||
from pcapi.core.offers.models import OfferValidationStatus | ||
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 | ||
import pcapi.core.users.factories as users_factories | ||
from pcapi.utils.date import format_into_utc_date | ||
|
||
|
@@ -53,6 +55,97 @@ 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_provider_extra_data(self, client): | ||
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]") | ||
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer) | ||
ems_provider = get_provider_by_local_class("EMSStocks") | ||
venue_provider = providers_factories.VenueProviderFactory(provider=ems_provider, venue=venue) | ||
allocine_provider = providers_factories.AllocineProviderFactory(venue=venue_provider.venue) | ||
offer = offers_factories.OfferFactory( | ||
name="Film", | ||
venue=venue, | ||
lastProvider=allocine_provider, | ||
subcategoryId=subcategories.SEANCE_CINE.id, | ||
isDuo=False, | ||
description="description", | ||
extraData={ | ||
"cast": ["Joan Baez", "Joe Cocker", "David Crosby"], | ||
"eidr": "10.5240/ADBD-3CAA-43A0-7BF0-86E2-K", | ||
"type": "FEATURE_FILM", | ||
"visa": "37205", | ||
"title": "Woodstock", | ||
"genres": ["DOCUMENTARY", "HISTORICAL", "MUSIC"], | ||
"credits": [ | ||
{"person": {"lastName": "Wadleigh", "firstName": "Michael"}, "position": {"name": "DIRECTOR"}} | ||
], | ||
"runtime": 185, | ||
"theater": {"allocine_room_id": "W0135", "allocine_movie_id": 2634}, | ||
"backlink": "https://www.allocine.fr/film/fichefilm_gen_cfilm=2634.html", | ||
"synopsis": "Le plus important rassemblement de la musique pop de ces vingt derni\u00e8res ann\u00e9es. Des groupes qui ont marqu\u00e9 leur \u00e9poque et une jeunesse qui a marqu\u00e9 la sienne.", | ||
"companies": [{"name": "Wadleigh-Maurice", "activity": "Production"}], | ||
"countries": ["USA"], | ||
"posterUrl": "https://fr.web.img2.acsta.net/pictures/14/06/20/12/25/387023.jpg", | ||
"allocineId": 2634, | ||
"originalTitle": "Woodstock", | ||
"stageDirector": "Michael Wadleigh", | ||
"productionYear": 1970, | ||
}, | ||
) | ||
|
||
data = { | ||
"name": "New name", | ||
"externalTicketOfficeUrl": "http://example.net", | ||
"extraData": { | ||
"cast": ["Joan Baez", "Joe Cocker", "David Crosby"], | ||
"eidr": "10.5240/ADBD-3CAA-43A0-7BF0-86E2-K", | ||
"type": "FEATURE_FILM", | ||
"visa": "37205", | ||
"title": "Woodstock", | ||
"genres": ["DOCUMENTARY", "HISTORICAL", "MUSIC"], | ||
"credits": [ | ||
{"person": {"lastName": "Wadleigh", "firstName": "Michael"}, "position": {"name": "DIRECTOR"}} | ||
], | ||
"runtime": 185, | ||
"theater": {"allocine_room_id": "W0135", "allocine_movie_id": 2634}, | ||
"backlink": "https://www.allocine.fr/film/fichefilm_gen_cfilm=2634.html", | ||
"synopsis": "Le plus important rassemblement de la musique pop de ces vingt derni\u00e8res ann\u00e9es. Des groupes qui ont marqu\u00e9 leur \u00e9poque et une jeunesse qui a marqu\u00e9 la sienne.", | ||
"companies": [{"name": "Wadleigh-Maurice", "activity": "Production"}], | ||
"countries": ["USA"], | ||
"posterUrl": "https://fr.web.img2.acsta.net/pictures/14/06/20/12/25/387023.jpg", | ||
"allocineId": 2634, | ||
"originalTitle": "Woodstock", | ||
"stageDirector": "Michael Wadleigh", | ||
"productionYear": 1970, | ||
}, | ||
} | ||
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.name == "New name" | ||
assert updated_offer.extraData == { | ||
"cast": ["Joan Baez", "Joe Cocker", "David Crosby"], | ||
"eidr": "10.5240/ADBD-3CAA-43A0-7BF0-86E2-K", | ||
"type": "FEATURE_FILM", | ||
"visa": "37205", | ||
"title": "Woodstock", | ||
"genres": ["DOCUMENTARY", "HISTORICAL", "MUSIC"], | ||
"credits": [{"person": {"lastName": "Wadleigh", "firstName": "Michael"}, "position": {"name": "DIRECTOR"}}], | ||
"runtime": 185, | ||
"theater": {"allocine_room_id": "W0135", "allocine_movie_id": 2634}, | ||
"backlink": "https://www.allocine.fr/film/fichefilm_gen_cfilm=2634.html", | ||
"synopsis": "Le plus important rassemblement de la musique pop de ces vingt derni\u00e8res ann\u00e9es. Des groupes qui ont marqu\u00e9 leur \u00e9poque et une jeunesse qui a marqu\u00e9 la sienne.", | ||
"companies": [{"name": "Wadleigh-Maurice", "activity": "Production"}], | ||
"countries": ["USA"], | ||
"posterUrl": "https://fr.web.img2.acsta.net/pictures/14/06/20/12/25/387023.jpg", | ||
"allocineId": 2634, | ||
"originalTitle": "Woodstock", | ||
"stageDirector": "Michael Wadleigh", | ||
"productionYear": 1970, | ||
} | ||
|
||
@pytest.mark.parametrize( | ||
"label, offer_has_oa, address_update_exist", | ||
[ | ||
|
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 |
---|---|---|
|
@@ -147,6 +147,7 @@ def test_update_extra_data_partially(self, client): | |
assert event_offer.extraData == { | ||
"author": "Maurice", | ||
"performer": "Pink Pâtisserie", | ||
"stageDirector": "Robert", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert de ce test modifié dans cette PR et qui n'aurait pas dû l'être |
||
} | ||
|
||
def test_patch_all_fields(self, 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note pour la review: test sans intérêt , aucune erreur raised et comportement nominal d'update des extra data