-
Notifications
You must be signed in to change notification settings - Fork 40
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-34083)[API] fix: pro: draft offer: always check if EAN is used #15965
Open
jbaudet-pass
wants to merge
1
commit into
master
Choose a base branch
from
PC-34083/block_pending_offer_update_if_published_offer_with_same_ean_exists
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -219,6 +219,10 @@ def _create( | |||||||||||||
return super()._create(model_class, *args, **kwargs) | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
class DraftOfferFactory(OfferFactory): | ||||||||||||||
isActive = False | ||||||||||||||
|
||||||||||||||
Comment on lines
+222
to
+224
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. Je crois qu'il faut que tu rajoutes cela pour que ta factory soit complète.
Suggested change
|
||||||||||||||
|
||||||||||||||
class ArtistProductLinkFactory(BaseFactory): | ||||||||||||||
class Meta: | ||||||||||||||
model = artist_models.ArtistProductLink | ||||||||||||||
|
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
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.models.offer_mixin import OfferValidationStatus | ||
from pcapi.utils.date import format_into_utc_date | ||
|
||
|
||
|
@@ -52,7 +53,7 @@ def test_patch_draft_offer(self, client): | |
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( | ||
offer = offers_factories.DraftOfferFactory( | ||
name="Name", | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
|
@@ -674,6 +675,36 @@ def when_trying_to_patch_product(self, client): | |
assert response.status_code == 400 | ||
assert response.json["product_id"] == ["Vous ne pouvez pas changer cette information"] | ||
|
||
def test_cannot_edit_details_if_ean_is_already_used(self, client): | ||
ean = "0000000000001" | ||
email = "[email protected]" | ||
|
||
user_offerer = offerers_factories.UserOffererFactory(user__email=email) | ||
venue = offerers_factories.VenueFactory( | ||
managingOfferer=user_offerer.offerer, venueTypeCode=VenueTypeCode.RECORD_STORE | ||
) | ||
|
||
product = offers_factories.ProductFactory(subcategoryId=subcategories.LIVRE_PAPIER.id, extraData={"ean": ean}) | ||
offers_factories.OfferFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
product=product, | ||
validation=OfferValidationStatus.APPROVED, | ||
extraData={"ean": ean}, | ||
) | ||
|
||
offer = offers_factories.OfferFactory( | ||
venue=venue, isActive=False, validation=OfferValidationStatus.DRAFT, product=product, extraData={"ean": ean} | ||
) | ||
|
||
data = {"name": "some other name"} | ||
response = client.with_session_auth(email).patch(f"offers/draft/{offer.id}", json=data) | ||
|
||
assert response.status_code == 400 | ||
assert response.json == { | ||
"ean": ["Une offre avec cet EAN existe déjà. Vous pouvez la retrouver dans l’onglet Offres."] | ||
} | ||
|
||
|
||
@pytest.mark.usefixtures("db_session") | ||
class Returns403Test: | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
from pcapi.core.categories import subcategories_v2 as subcategories | ||
import pcapi.core.offerers.factories as offerers_factories | ||
from pcapi.core.offerers.schemas import VenueTypeCode | ||
import pcapi.core.offers.factories as offers_factories | ||
import pcapi.core.offers.models as offers_models | ||
from pcapi.core.testing import assert_num_queries | ||
|
@@ -242,3 +243,40 @@ def test_patch_publish_future_offer( | |
assert response.json["publication_date"] == ["Impossible de sélectionner une date de publication dans le passé"] | ||
offer = offers_models.Offer.query.get(stock.offerId) | ||
assert offer.validation == OfferValidationStatus.DRAFT | ||
|
||
def test_cannot_publish_offer_if_ean_is_already_used( | ||
self, | ||
client, | ||
): | ||
ean = "0000000000001" | ||
email = "[email protected]" | ||
|
||
user_offerer = offerers_factories.UserOffererFactory(user__email=email) | ||
venue = offerers_factories.VenueFactory( | ||
managingOfferer=user_offerer.offerer, venueTypeCode=VenueTypeCode.RECORD_STORE | ||
) | ||
|
||
product = offers_factories.ProductFactory(subcategoryId=subcategories.LIVRE_PAPIER.id, extraData={"ean": ean}) | ||
offers_factories.OfferFactory( | ||
subcategoryId=subcategories.LIVRE_PAPIER.id, | ||
venue=venue, | ||
product=product, | ||
validation=OfferValidationStatus.APPROVED, | ||
extraData={"ean": ean}, | ||
) | ||
|
||
offer = offers_factories.StockFactory( | ||
offer__venue=venue, | ||
offer__isActive=False, | ||
offer__validation=OfferValidationStatus.DRAFT, | ||
offer__product=product, | ||
offer__extraData={"ean": ean}, | ||
).offer | ||
|
||
client = client.with_session_auth(email) | ||
response = client.patch("/offers/publish", json={"id": offer.id}) | ||
|
||
assert response.status_code == 400 | ||
assert response.json == { | ||
"ean": ["Une offre avec cet EAN existe déjà. Vous pouvez la retrouver dans l’onglet Offres."] | ||
} |
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.
Pour l'update je pense que tu peux enlever cette partie. Effectivement dans certain cas le check ne sera pas parfait (si on n'a pas changé les
"extraData"
et que pourtant entre temps une offre a été publiée avec l'ean qui était dans l'extraData existant) mais ce n'est pas si grave.Le plus important c'est de bloquer la publication de l'offre.