Skip to content

Commit

Permalink
(PC-31942)[API] fix: when offerer has only virtual venue and offer is…
Browse files Browse the repository at this point in the history
… digital, offer venue is virtual
  • Loading branch information
ogeber committed Sep 19, 2024
1 parent 25ae1a5 commit 395a06c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions api/src/pcapi/core/offers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ def _get_coherent_venue_with_subcategory(
# FIXME: ogeber 30.08.2024 - This wont be useful when
# virtual venues will be removed
subcategory = subcategories.ALL_SUBCATEGORIES_DICT[offer_subcategory_id]
if venue.isVirtual:
if not subcategory.is_online_only and venue.isVirtual:
raise exceptions.OfferVenueShouldNotBeVirtual()
if not subcategory.is_online_only and not venue.isVirtual:
if (subcategory.is_online_only and venue.isVirtual) or (not subcategory.is_online_only and not venue.isVirtual):
return venue
# venue is physical and offer is digital : we look for virtual venue
virtual_venue = offerers_repository.find_virtual_venue_by_offerer_id(venue.managingOffererId)
if not virtual_venue:
raise exceptions.OffererVirtualVenueNotFound()
Expand Down
3 changes: 2 additions & 1 deletion api/src/pcapi/core/offers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def __init__(self) -> None:


class OfferVenueShouldNotBeVirtual(Exception):
pass
def __init__(self) -> None:
super().__init__("Une offre physique ne peut être associée à un lieu numérique")


class BookingsHaveOtherPricingPoint(MoveOfferBaseException):
Expand Down
16 changes: 9 additions & 7 deletions api/tests/core/offers/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ def test_create_draft_offer_from_scratch(self):
assert models.Offer.query.count() == 1

@override_features(WIP_SUGGESTED_SUBCATEGORIES=False)
def test_create_draft_offer_with_virtual_venue(self):
def test_create_draft_digitaloffer_with_virtual_venue(self):
venue = offerers_factories.VirtualVenueFactory()
body = offers_schemas.PostDraftOfferBodyModel(
name="La Poudre",
Expand All @@ -1098,15 +1098,17 @@ def test_create_draft_offer_with_virtual_venue(self):
assert offer.visualDisabilityCompliant == None

@override_features(WIP_SUGGESTED_SUBCATEGORIES=True)
def test_create_draft_offer_with_virtual_venue_with_subcategory_suggestion_must_fail(self):
venue = offerers_factories.VirtualVenueFactory()
def test_create_draft_physical_offer_on_virtual_venue_must_fail(self):
physical_venue = offerers_factories.VirtualVenueFactory()
virtual_venue = offerers_factories.VirtualVenueFactory(managingOffererId=physical_venue.managingOffererId)

body = offers_schemas.PostDraftOfferBodyModel(
name="La Poudre",
subcategoryId=subcategories.PODCAST.id,
venueId=venue.id,
name="La Marguerite et le Maître",
subcategoryId=subcategories.LIVRE_PAPIER.id,
venueId=virtual_venue.id,
)
with pytest.raises(exceptions.OfferVenueShouldNotBeVirtual):
api.create_draft_offer(body, venue=venue)
api.create_draft_offer(body, venue=virtual_venue)

def test_create_draft_offer_with_accessibility_provider(self):
# when venue is synchronized with acceslibre, create draft offer should
Expand Down

0 comments on commit 395a06c

Please sign in to comment.