Esempio n. 1
0
    def test_should_return_false_when_exception(self):
        # Given
        client = MagicMock()
        client.hexists = MagicMock()
        client.hexists.side_effect = redis.exceptions.RedisError

        # When
        result = check_offer_exists(client=client, offer_id=1)

        # Then
        assert result is False
def delete_expired_offers(client: Redis, offer_ids: List[int]) -> None:
    offer_ids_to_delete = []
    for offer_id in offer_ids:
        offer_exists = check_offer_exists(client=client, offer_id=offer_id)

        if offer_exists:
            offer_ids_to_delete.append(offer_id)

    if len(offer_ids_to_delete) > 0:
        _process_deleting(client=client,
                          offer_ids_to_delete=offer_ids_to_delete)
Esempio n. 3
0
    def test_should_return_false_when_offer_not_exists(self):
        # Given
        client = MagicMock()
        client.hexists = MagicMock()
        client.hexists.return_value = False

        # When
        result = check_offer_exists(client=client, offer_id=1)

        # Then
        client.hexists.assert_called_once_with("indexed_offers", 1)
        assert result is False
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!")