Пример #1
0
    def test_returns_classic_path_when_given_model_is_product(self):
        # given
        product_object = Product()
        product_object.id = 123

        # when
        thumb_path = build_thumb_path(product_object, 0)

        # then
        assert thumb_path == "products/PM"
Пример #2
0
    def test_returns_path_with_index_if_above_0(self):
        # given
        product_object = Product()
        product_object.id = 123

        # when
        thumb_path = build_thumb_path(product_object, 3)

        # then
        assert thumb_path == "products/PM_3"
Пример #3
0
    def test_get_products_compatible_status(self):
        # Given
        products = []
        products.append(Product(isGcuCompatible=True))
        products.append(Product(isGcuCompatible=True))

        # Then
        assert _get_products_compatible_status(products) == {
            "status": "compatible_products",
            "text": "Oui",
        }

        products[0].isGcuCompatible = False
        assert _get_products_compatible_status(products) == {
            "status": "partially_incompatible_products",
            "text": "Partiellement",
        }

        products[1].isGcuCompatible = False
        assert _get_products_compatible_status(products) == {
            "status": "incompatible_products",
            "text": "Non",
        }
Пример #4
0
    def test_build_new_offers_from_stock_details(self, db_session):
        # Given
        stock_details = [
            {
                "offers_fnac_reference": "offer_ref1",
            },
            {
                "available_quantity": 17,
                "offers_fnac_reference": "offer_ref_2",
                "price": 28.989,
                "products_fnac_reference": "product_ref",
                "stocks_fnac_reference": "stock_ref",
            },
        ]

        existing_offers_by_fnac_reference = {"offer_ref1"}
        venue = VenueFactory(bookingEmail="booking_email")
        product = Product(id=456,
                          name="product_name",
                          description="product_desc",
                          extraData="extra",
                          type="product_type")
        products_by_fnac_reference = {"product_ref": product}

        # When
        new_offers = synchronize_fnac_stocks._build_new_offers_from_stock_details(
            stock_details, existing_offers_by_fnac_reference,
            products_by_fnac_reference, venue)

        # Then
        assert new_offers == [
            Offer(
                bookingEmail="booking_email",
                description="product_desc",
                extraData="extra",
                idAtProviders="offer_ref_2",
                name="product_name",
                productId=456,
                venueId=venue.id,
                type="product_type",
            )
        ]
Пример #5
0
 def test_with_index_above_0(self):
     obj = Product(id=123)
     assert obj.get_thumb_storage_id(3) == "products/PM_3"
Пример #6
0
 def test_with_product(self):
     obj = Product(id=123)
     assert obj.get_thumb_storage_id(0) == "products/PM"
Пример #7
0
    def test_get_stocks_to_upsert(self):
        # Given
        spec = [
            StockDetail(  # existing, will update
                offers_provider_reference="offer_ref1",
                available_quantity=15,
                price=15.78,
                products_provider_reference="product_ref1",
                stocks_provider_reference="stock_ref1",
                venue_reference="venue_ref1",
            ),
            StockDetail(  # new, will be added
                available_quantity=17,
                offers_provider_reference="offer_ref2",
                price=28.989,
                products_provider_reference="product_ref2",
                stocks_provider_reference="stock_ref2",
                venue_reference="venue_ref2",
            ),
            StockDetail(  # no quantity, must be ignored
                available_quantity=0,
                offers_provider_reference="offer_ref3",
                price=28.989,
                products_provider_reference="product_ref3",
                stocks_provider_reference="stock_ref3",
                venue_reference="venue_ref3",
            ),
            StockDetail(  # existing, will update but set product's price
                offers_provider_reference="offer_ref4",
                available_quantity=15,
                price=None,
                products_provider_reference="product_ref4",
                stocks_provider_reference="stock_ref4",
                venue_reference="venue_ref4",
            ),
        ]

        stocks_by_provider_reference = {
            "stock_ref1": {"id": 1, "booking_quantity": 3, "price": 18.0, "quantity": 2},
            "stock_ref4": {"id": 2, "booking_quantity": 3, "price": 18.0, "quantity": 2},
        }
        offers_by_provider_reference = {"offer_ref1": 123, "offer_ref2": 134, "offer_ref4": 123}
        products_by_provider_reference = {
            "product_ref1": Product(extraData={"prix_livre": 7.01}),
            "product_ref2": Product(extraData={"prix_livre": 9.02}),
            "product_ref3": Product(extraData={"prix_livre": 11.03}),
            "product_ref4": Product(extraData={"prix_livre": 7.01}),
        }
        provider_id = 1

        # When
        update_stock_mapping, new_stocks, offer_ids = api._get_stocks_to_upsert(
            spec,
            stocks_by_provider_reference,
            offers_by_provider_reference,
            products_by_provider_reference,
            provider_id,
        )

        assert update_stock_mapping == [
            {
                "id": 1,
                "quantity": 15 + 3,
                "price": 15.78,
                "rawProviderQuantity": 15,
                "lastProviderId": 1,
            },
            {
                "id": 2,
                "quantity": 15 + 3,
                "price": 7.01,
                "rawProviderQuantity": 15,
                "lastProviderId": 1,
            },
        ]

        new_stock = new_stocks[0]
        assert new_stock.quantity == 17
        assert new_stock.bookingLimitDatetime is None
        assert new_stock.offerId == 134
        assert new_stock.price == 28.989
        assert new_stock.idAtProviders == "stock_ref2"
        assert new_stock.lastProviderId == 1

        assert offer_ids == set([123, 134])
Пример #8
0
    def test_build_new_offers_from_stock_details(self, db_session):
        # Given
        spec = [
            StockDetail(  # known offer, must be ignored
                available_quantity=1,
                offers_provider_reference="offer_ref1",
                venue_reference="venue_ref1",
                products_provider_reference="isbn_product_ref",
                stocks_provider_reference="stock_ref",
                price=28.989,
            ),
            StockDetail(  # new one, will be created
                available_quantity=17,
                offers_provider_reference="offer_ref_2",
                price=28.989,
                products_provider_reference="isbn_product_ref",
                stocks_provider_reference="stock_ref",
                venue_reference="venue_ref2",
            ),
            # no quantity, must be ignored
            StockDetail(
                available_quantity=0,
                offers_provider_reference="offer_ref_3",
                price=28.989,
                products_provider_reference="isbn_product_ref",
                stocks_provider_reference="stock_ref",
                venue_reference="venue_ref3",
            ),
        ]

        existing_offers_by_provider_reference = {"offer_ref1": 1}
        existing_offers_by_venue_reference = {"venue_ref1": 1}
        provider = offerers_factories.APIProviderFactory(apiUrl="https://provider_url", authToken="fake_token")
        venue = VenueFactory(bookingEmail="booking_email", withdrawalDetails="My withdrawal details")
        product = Product(
            id=456,
            name="product_name",
            description="product_desc",
            extraData="extra",
            subcategoryId=subcategories.LIVRE_PAPIER.id,
        )
        products_by_provider_reference = {"isbn_product_ref": product}

        # When
        new_offers = api._build_new_offers_from_stock_details(
            spec,
            existing_offers_by_provider_reference,
            products_by_provider_reference,
            existing_offers_by_venue_reference,
            venue,
            provider_id=provider.id,
        )

        # Then
        assert new_offers == [
            Offer(
                bookingEmail="booking_email",
                description="product_desc",
                extraData="extra",
                idAtProviders="offer_ref_2",
                lastProviderId=provider.id,
                name="product_name",
                productId=456,
                venueId=venue.id,
                subcategoryId=subcategories.LIVRE_PAPIER.id,
                withdrawalDetails=venue.withdrawalDetails,
            ),
        ]
        new_offer = new_offers[0]
        assert new_offer.bookingEmail == "booking_email"
        assert new_offer.description == "product_desc"
        assert new_offer.extraData == "extra"
        assert new_offer.idAtProviders == "offer_ref_2"
        assert new_offer.idAtProvider == "isbn_product_ref"
        assert new_offer.lastProviderId == provider.id
        assert new_offer.name == "product_name"
        assert new_offer.productId == 456
        assert new_offer.venueId == venue.id
        assert new_offer.subcategoryId == subcategories.LIVRE_PAPIER.id
        assert new_offer.withdrawalDetails == venue.withdrawalDetails