def process_eligible_offers(client: Redis, offer_ids: List[int], from_provider_update: bool = False) -> None: offers_to_add = [] offers_to_delete = [] pipeline = client.pipeline() offers = offer_queries.get_offers_by_ids(offer_ids) for offer in offers: offer_exists = check_offer_exists(client=client, offer_id=offer.id) if offer and offer.isBookable: if from_provider_update and offer_exists: offer_details = get_offer_details(client=client, offer_id=offer.id) if offer_details and is_eligible_for_reindexing( offer, offer_details): offers_to_add.append(build_object(offer=offer)) add_to_indexed_offers( pipeline=pipeline, offer_id=offer.id, offer_details=_build_offer_details_to_be_indexed( offer)) else: offers_to_add.append(build_object(offer=offer)) add_to_indexed_offers( pipeline=pipeline, offer_id=offer.id, offer_details=_build_offer_details_to_be_indexed(offer)) else: if offer_exists: offers_to_delete.append(offer.id) if len(offers_to_add) > 0: _process_adding(pipeline=pipeline, client=client, offer_ids=offer_ids, adding_objects=offers_to_add) if len(offers_to_delete) > 0: _process_deleting(client=client, offer_ids_to_delete=offers_to_delete) if not (offers_to_add or offers_to_delete): logger.info("[ALGOLIA] no objects were added nor deleted!")
def test_should_return_true_when_offer_name_has_changed(self, app): # Given offerer = create_offerer() venue = create_venue(offerer=offerer) offer = create_offer_with_thing_product( thing_name="super offre de dingue", venue=venue) stock = create_stock(offer=offer) repository.save(stock) # When is_offer_eligible = is_eligible_for_reindexing(offer=offer, offer_details={ "name": "super offre", "dateRange": [], "dates": [], "prices": [10.0] }) # Then assert is_offer_eligible
def test_should_return_false_when_stocks_beginning_datetime_have_not_changed( self, app): # Given offerer = create_offerer(is_active=True, validation_token=None) venue = create_venue(offerer=offerer, validation_token=None) offer = create_offer_with_event_product(event_name="super offre", venue=venue) stock = create_stock(beginning_datetime=datetime(2020, 1, 1), offer=offer) repository.save(stock) # When is_offer_eligible = is_eligible_for_reindexing( offer=offer, offer_details={ "name": "super offre", "dateRange": ["2020-01-01 00:00:00", "2020-01-02 00:00:00"], "dates": [1577836800.0], "prices": [10.0], }, ) # Then assert not is_offer_eligible
def test_should_return_true_when_stocks_prices_have_changed(self, app): # Given offerer = create_offerer() venue = create_venue(offerer=offerer) offer = create_offer_with_event_product(event_name="super offre", venue=venue) stock = create_stock(beginning_datetime=datetime(2020, 1, 1), offer=offer, price=10) repository.save(stock) # When is_offer_eligible = is_eligible_for_reindexing( offer=offer, offer_details={ "name": "super offre", "dateRange": ["2020-01-01 00:00:00", "2020-01-02 00:00:00"], "dates": [1577836800], "prices": [11.0], }, ) # Then assert is_offer_eligible