Ejemplo n.º 1
0
    def test_create_several_thumbs_when_thumb_index_is_4_and_current_thumbCount_is_0(self):
        # Given
        provider = offerers_factories.AllocineProviderFactory(localClass="TestLocalProviderWithThumbIndexAt4")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
        )
        local_provider = provider_test_utils.TestLocalProviderWithThumbIndexAt4()

        # When
        local_provider._handle_thumb(product)
        repository.save(product)

        # Then
        assert local_provider.checkedThumbs == 1
        assert local_provider.updatedThumbs == 0
        assert local_provider.createdThumbs == 4
        assert product.thumbCount == 4
Ejemplo n.º 2
0
    def test_should_iterate_from_current_thumbCount_to_thumbIndex_when_thumbCount_is_0(self, app):
        # Given
        provider = offerers_factories.AllocineProviderFactory(localClass="TestLocalProviderWithThumb")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
            thumbCount=0,
        )
        local_provider = provider_test_utils.TestLocalProviderWithThumb()
        thumb = local_provider.get_object_thumb()

        # When
        thumb_index = 4
        _save_same_thumb_from_thumb_count_to_index(product, thumb_index, thumb)
        repository.save(product)

        # Then
        assert product.thumbCount == 4
Ejemplo n.º 3
0
    def test_returns_object_with_expected_attributes(self):
        # Given
        provider = offerers_factories.AllocineProviderFactory(localClass="TestLocalProvider")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            name="Old product name",
            subcategoryId=subcategories.ACHAT_INSTRUMENT.id,
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
        )
        local_provider = provider_test_utils.TestLocalProvider()

        # When
        local_provider._handle_update(product, providable_info)

        # Then
        product = Product.query.one()
        assert product.name == "New Product"
        assert product.subcategoryId == subcategories.LIVRE_PAPIER.id
Ejemplo n.º 4
0
    def test_call_save_thumb_should_increase_thumbCount_by_1(self):
        # Given
        provider = offerers_factories.AllocineProviderFactory(localClass="TestLocalProviderWithThumb")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
        )
        local_provider = provider_test_utils.TestLocalProviderWithThumb()

        # When
        local_provider._handle_thumb(product)
        repository.save(product)

        # Then
        assert local_provider.checkedThumbs == 1
        assert local_provider.updatedThumbs == 0
        assert local_provider.createdThumbs == 1
        assert product.thumbCount == 1
Ejemplo n.º 5
0
    def test_should_only_replace_image_at_specific_thumb_index_when_thumbCount_is_superior_to_thumbIndex(
            self):
        provider = offerers_factories.ProviderFactory(
            localClass="TestLocalProviderWithThumb")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
            thumbCount=4,
        )
        local_provider = provider_test_utils.TestLocalProviderWithThumb()
        thumb = local_provider.get_object_thumb()

        # When
        thumb_index = 1
        _save_same_thumb_from_thumb_count_to_index(product, thumb_index, thumb)
        repository.save(product)

        # Then
        assert product.thumbCount == 4
Ejemplo n.º 6
0
    def test_returns_object_with_expected_attributes(self):
        # Given
        provider = offerers_factories.ProviderFactory(
            localClass="TestLocalProvider")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            name="Old product name",
            type=str(ThingType.INSTRUMENT),
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
        )
        local_provider = provider_test_utils.TestLocalProvider()

        # When
        local_provider._handle_update(product, providable_info)

        # Then
        product = Product.query.one()
        assert product.name == "New Product"
        assert product.type == str(ThingType.LIVRE_EDITION)
Ejemplo n.º 7
0
    def test_does_not_update_existing_object_when_date_is_older_than_last_modified_date(self, next_function):
        # Given
        provider = offerers_factories.AllocineProviderFactory(localClass="TestLocalProvider")
        providable_info = create_providable_info(date_modified=datetime(2018, 1, 1))
        product = offers_factories.ThingProductFactory(
            dateModifiedAtLastProvider=datetime(2020, 1, 1),
            lastProvider=provider,
            idAtProviders=providable_info.id_at_providers,
            name="Old product name",
            subcategoryId=subcategories.ACHAT_INSTRUMENT.id,
        )
        local_provider = provider_test_utils.TestLocalProvider()
        next_function.side_effect = [[providable_info]]

        # When
        local_provider.updateObjects()

        # Then
        product = Product.query.one()
        assert product.name == "Old product name"
        assert product.dateModifiedAtLastProvider == datetime(2020, 1, 1)
    def test_should_return_payment_to_retry_if_bank_information_linked_to_offerer_and_current_status_is_not_processable(
        self, app
    ):
        # Given
        user_offerer = offers_factories.UserOffererFactory()
        product = offers_factories.ThingProductFactory(name="Lire un livre", isNational=True)
        venue = offers_factories.VenueFactory(
            managingOfferer=user_offerer.offerer, postalCode="34000", departementCode="34"
        )
        offer = offers_factories.ThingOfferFactory(product=product, venue=venue)
        stock = offers_factories.ThingStockFactory(offer=offer, price=0)
        booking = bookings_factories.UsedIndividualBookingFactory(stock=stock)
        not_processable_payment = factories.PaymentFactory(booking=booking, amount=10)
        factories.PaymentStatusFactory(payment=not_processable_payment, status=TransactionStatus.NOT_PROCESSABLE)
        offers_factories.BankInformationFactory(offerer=user_offerer.offerer)

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information()

        # Then
        assert not_processable_payment in payments_to_retry
Ejemplo n.º 9
0
    def test_raises_api_errors_exception_when_errors_occur_on_model(self):
        # Given
        provider = offerers_factories.AllocineProviderFactory(localClass="TestLocalProviderWithApiErrors")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            name="Old product name",
            subcategoryId=subcategories.ACHAT_INSTRUMENT.id,
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
        )
        local_provider = provider_test_utils.TestLocalProviderWithApiErrors()

        # When
        with pytest.raises(ApiErrors) as api_errors:
            local_provider._handle_update(product, providable_info)

        # Then
        assert api_errors.value.errors["url"] == [
            "Un produit de sous-catégorie ACHAT_INSTRUMENT ne peut pas être numérique"
        ]
        provider_event = LocalProviderEvent.query.one()
        assert provider_event.type == LocalProviderEventType.SyncError
    def test_should_not_return_payment_to_retry_if_bank_information_status_is_not_accepted(self, app):
        # Given
        user_offerer = offers_factories.UserOffererFactory()
        product = offers_factories.ThingProductFactory(name="Lire un livre", isNational=True)
        venue = offers_factories.VenueFactory(
            managingOfferer=user_offerer.offerer, postalCode="34000", departementCode="34"
        )
        offer = offers_factories.ThingOfferFactory(product=product, venue=venue)
        stock = offers_factories.ThingStockFactory(offer=offer, price=0)
        booking = bookings_factories.UsedIndividualBookingFactory(stock=stock)
        not_processable_payment = factories.PaymentFactory(
            booking=booking, amount=10, iban="CF13QSDFGH456789", bic="QSDFGH8Z555"
        )
        factories.PaymentStatusFactory(payment=not_processable_payment, status=TransactionStatus.NOT_PROCESSABLE)
        offers_factories.BankInformationFactory(
            offerer=user_offerer.offerer, iban=None, bic=None, status=BankInformationStatus.DRAFT
        )

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information()

        # Then
        assert payments_to_retry == []
Ejemplo n.º 11
0
    def test_raises_api_errors_exception_when_errors_occur_on_model(self):
        # Given
        provider = offerers_factories.ProviderFactory(
            localClass="TestLocalProviderWithApiErrors")
        providable_info = create_providable_info()
        product = offers_factories.ThingProductFactory(
            name="Old product name",
            type=str(ThingType.INSTRUMENT),
            idAtProviders=providable_info.id_at_providers,
            lastProvider=provider,
        )
        local_provider = provider_test_utils.TestLocalProviderWithApiErrors()

        # When
        with pytest.raises(ApiErrors) as api_errors:
            local_provider._handle_update(product, providable_info)

        # Then
        assert api_errors.value.errors["url"] == [
            "Une offre de type Jeux (support physique) ne peut pas être numérique"
        ]
        provider_event = LocalProviderEvent.query.one()
        assert provider_event.type == LocalProviderEventType.SyncError
Ejemplo n.º 12
0
    def test_updates_existing_object(self, next_function):
        # Given
        provider = offerers_factories.ProviderFactory(
            localClass="TestLocalProvider")
        providable_info = create_providable_info(
            date_modified=datetime(2018, 1, 1))
        product = offers_factories.ThingProductFactory(
            dateModifiedAtLastProvider=datetime(2000, 1, 1),
            lastProvider=provider,
            idAtProviders=providable_info.id_at_providers,
            name="Old product name",
            type=str(ThingType.INSTRUMENT),
        )
        local_provider = provider_test_utils.TestLocalProvider()
        next_function.side_effect = [[providable_info]]

        # When
        local_provider.updateObjects()

        # Then
        product = Product.query.one()
        assert product.name == "New Product"
        assert product.type == str(ThingType.LIVRE_EDITION)
        assert product.dateModifiedAtLastProvider == providable_info.date_modified_at_provider