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-33248)[API] feat: Venue with siret or open to public are permanent when created, only when FF WIP_IS_OPEN_TO_PUBLIC is activated #16196

Merged
merged 1 commit into from
Feb 6, 2025
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
3 changes: 3 additions & 0 deletions api/src/pcapi/core/offerers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from pcapi.models import db
from pcapi.models import feature
from pcapi.models import pc_object
from pcapi.models.feature import FeatureToggle
from pcapi.models.validation_status_mixin import ValidationStatus
from pcapi.repository import is_managed_transaction
from pcapi.repository import mark_transaction_as_invalid
Expand Down Expand Up @@ -507,6 +508,8 @@ def create_venue(venue_data: venues_serialize.PostVenueBodyModel, author: users_

if venue.siret:
link_venue_to_pricing_point(venue, pricing_point_id=venue.id)
if FeatureToggle.WIP_IS_OPEN_TO_PUBLIC.is_active() and (venue.siret or venue.isOpenToPublic):
venue.isPermanent = True

on_commit(
functools.partial(search.async_index_venue_ids, [venue.id], reason=search.IndexationReason.VENUE_CREATION)
Expand Down
2 changes: 2 additions & 0 deletions api/src/pcapi/core/providers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pcapi.core.providers.repository as providers_repository
from pcapi.core.users import models as users_models
from pcapi.models import db
from pcapi.models.feature import FeatureToggle
from pcapi.repository import on_commit
from pcapi.repository import repository
from pcapi.routes.serialization.venue_provider_serialize import PostVenueProviderBody
Expand Down Expand Up @@ -66,6 +67,7 @@ def create_venue_provider(
offerers_models.VenueTypeCode.MOVIE,
)
and not venue.isPermanent
and not FeatureToggle.WIP_IS_OPEN_TO_PUBLIC.is_active()
):
venue.isPermanent = True
db.session.add(venue)
Expand Down
47 changes: 47 additions & 0 deletions api/tests/core/offerers/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,53 @@ def test_basics(self):
assert action.offerer is None
assert action.venue == venue

@pytest.mark.features(WIP_IS_OPEN_TO_PUBLIC=True)
def test_venue_is_permanent_when_created_with_siret(self):
user_offerer = offerers_factories.UserOffererFactory()
data = venues_serialize.PostVenueBodyModel(**self.base_data(user_offerer.offerer))
offerers_api.create_venue(data, user_offerer.user)

venue = offerers_models.Venue.query.one()
assert venue.isPermanent is True

@pytest.mark.features(WIP_IS_OPEN_TO_PUBLIC=True)
def test_venue_is_permanent_when_created_open_to_public(self):
user_offerer = offerers_factories.UserOffererFactory()
init_data = self.base_data(user_offerer.offerer) | {
"siret": None,
"comment": "no siret",
"isOpenToPublic": True,
}
data = venues_serialize.PostVenueBodyModel(**init_data)
offerers_api.create_venue(data, user_offerer.user)

venue = offerers_models.Venue.query.one()
assert venue.isPermanent is True

@pytest.mark.features(WIP_IS_OPEN_TO_PUBLIC=True)
def test_venue_is_permanent_when_created_with_siret_and_open_to_public(self):
user_offerer = offerers_factories.UserOffererFactory()
init_data = self.base_data(user_offerer.offerer) | {"isOpenToPublic": True}
data = venues_serialize.PostVenueBodyModel(**init_data)
offerers_api.create_venue(data, user_offerer.user)

venue = offerers_models.Venue.query.one()
assert venue.isPermanent is True

@pytest.mark.features(WIP_IS_OPEN_TO_PUBLIC=True)
def test_venue_is_not_permanent_when_created_without_siret_nor_is_open_to_public(self):
user_offerer = offerers_factories.UserOffererFactory()
init_data = self.base_data(user_offerer.offerer) | {
"siret": None,
"comment": "no siret",
"isOpenToPublic": False,
}
data = venues_serialize.PostVenueBodyModel(**init_data)
offerers_api.create_venue(data, user_offerer.user)

venue = offerers_models.Venue.query.one()
assert venue.isPermanent is False

def test_venue_with_no_siret_has_no_pricing_point(self):
user_offerer = offerers_factories.UserOffererFactory()
data = self.base_data(user_offerer.offerer) | {"siret": None, "comment": "no siret"}
Expand Down
21 changes: 21 additions & 0 deletions api/tests/core/providers/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ def test_permanent_venue_marking(
reason=search.IndexationReason.VENUE_PROVIDER_CREATION,
)

@pytest.mark.features(WIP_IS_OPEN_TO_PUBLIC=True)
@pytest.mark.parametrize(
"venue_type",
(
offerers_models.VenueTypeCode.BOOKSTORE,
offerers_models.VenueTypeCode.MOVIE,
offerers_models.VenueTypeCode.DIGITAL,
),
)
def test_permanent_venue_marking_ff_wip_is_open_to_public_activated(self, venue_type):
venue = offerers_factories.VenueFactory(venueTypeCode=venue_type, isPermanent=False)
provider = providers_factories.ProviderFactory(
enabledForPro=True,
isActive=True,
localClass=None,
)
author = users_factories.UserFactory()
api.create_venue_provider(provider.id, venue.id, current_user=author)

assert venue.isPermanent is False


def create_product(ean, **kwargs):
return offers_factories.ProductFactory(
Expand Down
Loading