def create_product_with_thing_type( thing_name: str = "Test Book", thing_type: ThingType = ThingType.LIVRE_EDITION, author_name: str = "Test Author", is_national: bool = False, id_at_providers: str = None, idx: int = None, is_digital: bool = False, is_gcu_compatible: bool = True, is_offline_only: bool = False, date_modified_at_last_provider: datetime = None, last_provider_id: int = None, media_urls: Iterable[str] = ("test/urls", ), description: str = None, thumb_count: int = 1, url: str = None, owning_offerer: Offerer = None, extra_data: Dict = None, ) -> Product: product = Product() product.id = idx product.type = str(thing_type) product.name = thing_name product.description = description if extra_data: product.extraData = extra_data else: product.extraData = {"author": author_name} product.isNational = is_national if id_at_providers is None: id_at_providers = "".join(random.choices(string.digits, k=13)) product.dateModifiedAtLastProvider = date_modified_at_last_provider product.lastProviderId = last_provider_id product.idAtProviders = id_at_providers product.isGcuCompatible = is_gcu_compatible product.mediaUrls = media_urls product.thumbCount = thumb_count product.url = url product.owningOfferer = owning_offerer product.description = description if is_digital: product.url = "fake/url" if is_offline_only: product.type = str(ThingType.CINEMA_ABO) return product
def fill_object_attributes(self, product: Product): product.name = trim_with_elipsis(self.product_infos["titre"], 140) product.datePublished = read_things_date( self.product_infos["date_parution"]) product.type = self.product_type product.extraData = self.product_extra_data.copy() product.extraData.update(get_extra_data_from_infos(self.product_infos)) if self.product_infos["url_extrait_pdf"] != "": if product.mediaUrls is None: product.mediaUrls = [] product.mediaUrls.append(self.product_infos["url_extrait_pdf"])
def create_product_with_event_type( event_name: str = "Test event", event_type: EventType = EventType.SPECTACLE_VIVANT, description: str = None, duration_minutes: Optional[int] = 60, id_at_providers: str = None, is_national: bool = False, is_duo: bool = False, thumb_count: int = 0, ) -> Product: product = Product() product.name = event_name product.description = description product.durationMinutes = duration_minutes product.thumbCount = thumb_count product.idAtProviders = id_at_providers product.isNational = is_national product.isDuo = is_duo product.type = str(event_type) product.description = description return product
def fill_product_attributes(self, allocine_product: Product): allocine_product.name = self.movie_information["title"] allocine_product.type = str(EventType.CINEMA) allocine_product.thumbCount = 0 if "description" in self.movie_information: allocine_product.description = self.movie_information[ "description"] if "duration" in self.movie_information: allocine_product.durationMinutes = self.movie_information[ "duration"] if not allocine_product.extraData: allocine_product.extraData = {} if "visa" in self.movie_information: allocine_product.extraData["visa"] = self.movie_information["visa"] if "stageDirector" in self.movie_information: allocine_product.extraData[ "stageDirector"] = self.movie_information["stageDirector"] is_new_product_to_insert = allocine_product.id is None if is_new_product_to_insert: allocine_product.id = get_next_product_id_from_database() self.last_product_id = allocine_product.id