Skip to content

Commit

Permalink
(PC-31951)[API] fix: [to squash with previous] have a more realistic …
Browse files Browse the repository at this point in the history
…sandbox
  • Loading branch information
R0ntheo committed Sep 20, 2024
1 parent a868056 commit 1829011
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 471 deletions.
10 changes: 2 additions & 8 deletions api/src/pcapi/sandboxes/scripts/creators/industrial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_eac_data import create_eac_data
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_occurrences import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_offers import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_products import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_event_stocks import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_incidents import create_industrial_incidents
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_individual_offerers import (
Expand All @@ -41,7 +40,6 @@
create_industrial_search_indexed_objects,
)
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_thing_offers import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_thing_products import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_thing_stocks import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_venues import *
from pcapi.sandboxes.scripts.creators.industrial.create_industrial_venues_with_timezone import (
Expand Down Expand Up @@ -79,13 +77,9 @@ def save_industrial_sandbox() -> None:

venues_by_name = create_industrial_venues(offerers_by_name)

event_products_by_name = create_industrial_event_products()
event_offers_by_name = create_industrial_event_offers(offerers_by_name)

thing_products_by_name = create_industrial_thing_products()

event_offers_by_name = create_industrial_event_offers(event_products_by_name, offerers_by_name)

thing_offers_by_name = create_industrial_thing_offers(thing_products_by_name, offerers_by_name, venues_by_name)
thing_offers_by_name = create_industrial_thing_offers(offerers_by_name, venues_by_name)

create_industrial_draft_offers(offerers_by_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create_industrial_event_occurrences(
price_categories: dict[decimal.Decimal, offers_models.PriceCategory] = {}
for index, beginning_datetime in enumerate(EVENT_OCCURRENCE_BEGINNING_DATETIMES, start=1):
name = "{} / {} / {} ".format(
event_offer_with_occurrences.product.name if event_offer_with_occurrences.product else "",
event_offer_with_occurrences.name,
event_offer_with_occurrences.venue.name,
beginning_datetime.strftime(date_utils.DATE_ISO_FORMAT),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging

from pcapi.core.categories import subcategories_v2
import pcapi.core.offerers.models as offerers_models
import pcapi.core.offers.factories as offers_factories
import pcapi.core.offers.models as offers_models
from pcapi.repository import repository
from pcapi.sandboxes.scripts.mocks.event_mocks import MOCK_NAMES


logger = logging.getLogger(__name__)
Expand All @@ -14,7 +16,6 @@


def create_industrial_event_offers(
events_by_name: dict[str, offers_models.Product],
offerers_by_name: dict[str, offerers_models.Offerer],
) -> dict[str, offers_models.Offer]:
logger.info("create_industrial_event_offers")
Expand All @@ -24,7 +25,7 @@ def create_industrial_event_offers(
event_index = 0
offer_index = 0

event_items = list(events_by_name.items())
event_subcategories = [s for s in subcategories_v2.ALL_SUBCATEGORIES if s.is_event and s.is_offline_only]

for offerer in offerers_by_name.values():
event_venues = [venue for venue in offerer.managedVenues if not venue.isVirtual]
Expand All @@ -35,9 +36,10 @@ def create_industrial_event_offers(
event_venue = event_venues[0]

for venue_event_index in range(0, EVENTS_PER_OFFERER_WITH_PHYSICAL_VENUE):
rest_event_index = (venue_event_index + event_index) % len(event_items)

(event_name, event) = event_items[rest_event_index]
event_subcategory_index = (venue_event_index + event_index) % len(event_subcategories)
event_subcategory = event_subcategories[event_subcategory_index]
mock_index = (venue_event_index + event_index) % len(MOCK_NAMES)
event_name = MOCK_NAMES[mock_index]

name = "{} / {}".format(event_name, event_venue.name)
if offer_index % DEACTIVATED_OFFERS_PICK_MODULO == 0:
Expand All @@ -50,8 +52,10 @@ def create_industrial_event_offers(
is_duo = True
event_offers_by_name[name] = offers_factories.OfferFactory(
venue=event_venue,
product=event,
extraData=event.extraData,
subcategoryId=event_subcategory.id,
extraData=offers_factories.build_extra_data_from_subcategory(
event_subcategory.id, set_all_fields=False
),
isActive=is_active,
isDuo=is_duo,
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging

from pcapi.core.categories import subcategories_v2
import pcapi.core.offerers.models as offerers_models
import pcapi.core.offers.factories as offers_factories
import pcapi.core.offers.models as offers_models
from pcapi.repository import repository
from pcapi.sandboxes.scripts.mocks.thing_mocks import MOCK_NAMES


logger = logging.getLogger(__name__)
Expand All @@ -14,18 +16,18 @@


def create_industrial_thing_offers(
thing_products_by_name: dict[str, offers_models.Product],
offerers_by_name: dict[str, offerers_models.Offerer],
venues_by_name: dict[str, offerers_models.Venue],
) -> dict[str, offers_models.Offer]:
logger.info("create_industrial_thing_offers")

thing_offers_by_name: dict[str, offers_models.Offer] = {}

thing_subcategories = [s for s in subcategories_v2.ALL_SUBCATEGORIES if not s.is_event]

id_at_provider = 1234
thing_index = 0
offer_index = 0
thing_items = list(thing_products_by_name.items())
for offerer in offerers_by_name.values():
virtual_venue = [venue for venue in offerer.managedVenues if venue.isVirtual][0]

Expand All @@ -34,17 +36,20 @@ def create_industrial_thing_offers(

for venue_thing_index in range(0, THINGS_PER_OFFERER):
thing_venue = None
while thing_venue is None:
rest_thing_index = (venue_thing_index + thing_index) % len(thing_items)
(thing_name, thing_product) = thing_items[rest_thing_index]
if thing_product.subcategory.is_offline_only:
thing_venue = physical_venue
elif thing_product.subcategory.is_online_only:
thing_venue = virtual_venue
else:
thing_venue = physical_venue

thing_index += 1
subcategory_index = (venue_thing_index + thing_index) % len(thing_subcategories)
subcategory = thing_subcategories[subcategory_index]
thing_name_index = (venue_thing_index + thing_index) % len(MOCK_NAMES)
thing_name = MOCK_NAMES[thing_name_index]

if subcategory.is_offline_only:
thing_venue = physical_venue
elif subcategory.is_online_only:
thing_venue = virtual_venue
else:
thing_venue = physical_venue

if thing_venue is None:
continue

name = "{} / {}".format(thing_name, thing_venue.name)
if offer_index % DEACTIVATED_OFFERS_PICK_MODULO == 0:
Expand All @@ -53,11 +58,11 @@ def create_industrial_thing_offers(
is_active = True
thing_offers_by_name[name] = offers_factories.OfferFactory(
venue=thing_venue,
subcategoryId=thing_product.subcategoryId,
subcategoryId=subcategory.id,
isActive=is_active,
url="http://example.com" if thing_product.subcategory.is_online_only else None,
url="http://example.com" if subcategory.is_online_only else None,
idAtProvider=str(id_at_provider),
extraData=thing_product.extraData,
extraData=offers_factories.build_extra_data_from_subcategory(subcategory.id, set_all_fields=False),
)
offer_index += 1
id_at_provider += 1
Expand Down
Loading

0 comments on commit 1829011

Please sign in to comment.