Skip to content

Commit

Permalink
(PC-34041)[API] feat: Add sandbox case
Browse files Browse the repository at this point in the history
  • Loading branch information
rprasquier-pass committed Feb 6, 2025
1 parent bfac382 commit 2121d3a
Showing 1 changed file with 171 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from pcapi.core.educational import models as educational_models
from pcapi.core.finance import factories as finance_factories
from pcapi.core.finance import models as finance_models
from pcapi.core.geography import factories as geography_factories
from pcapi.core.offerers import factories as offerers_factories
from pcapi.core.offerers import models as offerers_models
from pcapi.core.providers import models as providers_models
from pcapi.core.users import factories as user_factory
Expand All @@ -25,6 +27,74 @@
from .create_collective_api_provider import create_collective_api_provider


OfferVenue = typing.TypedDict(
"OfferVenue",
{
"addressType": educational_models.OfferAddressType,
"venueId": typing.NotRequired[int],
"otherAddress": typing.NotRequired[str],
},
)

LocationOption = typing.TypedDict(
"LocationOption",
{
"name": str,
"offerVenue": OfferVenue,
"interventionArea": typing.NotRequired[list[str]],
"locationType": educational_models.CollectiveLocationType,
"locationComment": typing.NotRequired[str],
},
)


def location_options(venue: offerers_models.Venue) -> list[LocationOption]:
return [
{
"name": "La culture chez l'acteur",
"offerVenue": {
"addressType": educational_models.OfferAddressType.OFFERER_VENUE,
"venueId": venue.id,
},
"locationType": educational_models.CollectiveLocationType.VENUE,
},
{
"name": "La culture dans l'école",
"offerVenue": {
"addressType": educational_models.OfferAddressType.SCHOOL,
},
"interventionArea": ["75", "92", "93", "94", "95"],
"locationType": educational_models.CollectiveLocationType.SCHOOL,
},
{
"name": "La culture dans un lieu précis",
"offerVenue": {
"addressType": educational_models.OfferAddressType.OFFERER_VENUE,
"otherAddress": "35 Bd de Sébastopol, 75001 Paris",
},
"locationType": educational_models.CollectiveLocationType.ADDRESS,
},
{
"name": "La culture dans un lieu flou",
"offerVenue": {
"addressType": educational_models.OfferAddressType.OFFERER_VENUE,
"otherAddress": "A coté de la mairie",
},
"interventionArea": ["75", "92", "93", "94", "95"],
"locationType": educational_models.CollectiveLocationType.TO_BE_DEFINED,
"locationComment": "A coté de la mairie",
},
{
"name": "La culture chez l'acteur qui n'existe pas",
"offerVenue": {
"addressType": educational_models.OfferAddressType.OFFERER_VENUE,
"venueId": 424242,
},
"locationType": educational_models.CollectiveLocationType.VENUE,
},
]


def create_offers(
offerers: list[offerers_models.Offerer], institutions: list[educational_models.EducationalInstitution]
) -> None:
Expand Down Expand Up @@ -106,13 +176,27 @@ def create_offers(
create_offers_booking_with_different_displayed_status(
institutions=institutions, domains=domains, venue=venue_pc_pro, provider=None
)
create_offer_templates_with_different_displayed_status(domains=domains, venue=venue_pc_pro)
create_offers_templates_with_different_displayed_status(domains=domains, venue=venue_pc_pro)

create_offers_booking_with_different_offer_venues(
institutions=institutions, domains=domains, venue=venue_pc_pro, provider=None
)
create_offers_booking_with_different_offer_venues(
institutions=institutions, domains=domains, venue=venue_pc_pro, provider=None, with_new_format=True
)

create_offers_templates_with_different_offer_venues(domains=domains, venue=venue_pc_pro)
create_offers_templates_with_different_offer_venues(domains=domains, venue=venue_pc_pro, with_new_format=True)

venue_public_api = next(v for v in offerer.managedVenues if "PUBLIC_API" in v.name)
create_offers_booking_with_different_displayed_status(
institutions=institutions, domains=domains, venue=venue_public_api, provider=provider
)

create_offers_booking_with_different_offer_venues(
institutions=institutions, domains=domains, venue=venue_public_api, provider=provider
)

search.index_all_collective_offers_and_templates()


Expand Down Expand Up @@ -597,7 +681,7 @@ def create_offers_booking_with_different_displayed_status(
)


def create_offer_templates_with_different_displayed_status(
def create_offers_templates_with_different_displayed_status(
*, domains: list[educational_models.EducationalDomain], venue: offerers_models.Venue
) -> None:
domains_iterator = cycle(domains)
Expand Down Expand Up @@ -643,6 +727,91 @@ def create_offer_templates_with_different_displayed_status(
)


def create_offers_booking_with_different_offer_venues(
*,
institutions: list[educational_models.EducationalInstitution],
domains: list[educational_models.EducationalDomain],
venue: offerers_models.Venue,
provider: providers_models.Provider | None,
with_new_format: bool = False,
) -> None:
domains_iterator = cycle(domains)
institution_iterator = cycle(institutions)

for location_option in location_options(venue):
name = location_option["name"]
offer_venue = location_option["offerVenue"]

collective_stock = educational_factories.CollectiveStockFactory(
collectiveOffer__name=f"{name}{' (avec OA)' if with_new_format else ''}{' (public api)' if provider is not None else ''}",
collectiveOffer__educational_domains=[next(domains_iterator)],
collectiveOffer__venue=venue,
collectiveOffer__bookingEmails=["toto@totoland.com"],
collectiveOffer__institution=next(institution_iterator),
collectiveOffer__formats=[EacFormat.PROJECTION_AUDIOVISUELLE],
collectiveOffer__provider=provider,
collectiveOffer__offerVenue=offer_venue,
collectiveOffer__interventionArea=location_option.get("interventionArea", []),
)

if with_new_format:
collective_offer = collective_stock.collectiveOffer
collective_offer.location_type = location_option.get("locationType")
collective_offer.location_comment = location_option.get("locationComment")

if location_option.get("locationType") == educational_models.CollectiveLocationType.ADDRESS:
address = geography_factories.AddressFactory(
street=offer_venue.get("otherAddress"),
)
offerer_address = offerers_factories.OffererAddressFactory(
label=location_option.get("name"), address=address
)
collective_offer.offererAddress = offerer_address
db.session.add(collective_offer)
elif location_option.get("locationType") == educational_models.CollectiveLocationType.VENUE:
collective_offer.offererAddressId = venue.offererAddressId
db.session.add(collective_offer)


def create_offers_templates_with_different_offer_venues(
*,
domains: list[educational_models.EducationalDomain],
venue: offerers_models.Venue,
with_new_format: bool = False,
) -> None:
domains_iterator = cycle(domains)

for location_option in location_options(venue):
name = location_option["name"]
offer_venue = location_option["offerVenue"]
collective_offer_template = educational_factories.CollectiveOfferTemplateFactory(
name=name,
venue=venue,
educational_domains=[next(domains_iterator)],
bookingEmails=["toto@totoland.com"],
formats=[EacFormat.PROJECTION_AUDIOVISUELLE],
offerVenue=offer_venue,
interventionArea=location_option.get("interventionArea", []),
)

if with_new_format:
collective_offer_template.location_type = location_option.get("locationType")
collective_offer_template.location_comment = location_option.get("locationComment")

if location_option.get("locationType") == educational_models.CollectiveLocationType.ADDRESS:
address = geography_factories.AddressFactory(
street=offer_venue.get("otherAddress"),
)
offerer_address = offerers_factories.OffererAddressFactory(
label=location_option.get("name"), address=address
)
collective_offer_template.offererAddress = offerer_address
db.session.add(collective_offer_template)
elif location_option.get("locationType") == educational_models.CollectiveLocationType.VENUE:
collective_offer_template.offererAddressId = venue.offererAddressId
db.session.add(collective_offer_template)


def create_booking_base_list(
*,
offerer: offerers_models.Offerer,
Expand Down

0 comments on commit 2121d3a

Please sign in to comment.