def test_should_not_create_product_when_school_related_product(
        self, get_lines_from_thing_file, get_files_to_process_from_titelive_ftp, app
    ):
        # Given
        files_list = list()
        files_list.append("Quotidien30.tit")

        get_files_to_process_from_titelive_ftp.return_value = files_list

        DATA_LINE_PARTS = BASE_DATA_LINE_PARTS[:]
        DATA_LINE_PARTS[2] = "livre scolaire"
        DATA_LINE_PARTS[4] = "2704"
        DATA_LINE_PARTS[27] = "Littérature scolaire"
        DATA_LINE_PARTS[40] = ""

        data_line = "~".join(DATA_LINE_PARTS)

        get_lines_from_thing_file.return_value = iter([data_line])

        activate_provider("TiteLiveThings")
        titelive_things = TiteLiveThings()

        # When
        titelive_things.updateObjects()

        # Then
        assert Product.query.count() == 0
Beispiel #2
0
        def when_venue_has_no_allocine_id(self, app):
            # Given
            user = create_user(email="*****@*****.**")
            offerer = create_offerer()
            venue = create_venue(offerer)
            repository.save(user, venue)

            titelive_stocks = activate_provider("TiteLiveStocks")
            activate_provider("AllocineStocks")

            # When
            response = (TestClient(app.test_client()).with_auth(
                email="*****@*****.**").get(f"/providers/{humanize(venue.id)}"))

            # Then
            assert response.status_code == 200
            response_json = response.json
            assert response_json == [{
                "enabledForPro": True,
                "id": humanize(titelive_stocks.id),
                "isActive": True,
                "localClass": "TiteLiveStocks",
                "name": "TiteLive Stocks (Epagine / Place des libraires.com)",
                "requireProviderIdentifier": True,
            }]
    def test_update_1_thing_from_one_data_line_in_one_file(
        self, get_lines_from_thing_file, get_files_to_process_from_titelive_ftp, app
    ):
        # Given
        files_list = list()
        files_list.append("Quotidien30.tit")

        get_files_to_process_from_titelive_ftp.return_value = files_list

        data_line = "~".join(BASE_DATA_LINE_PARTS)

        get_lines_from_thing_file.return_value = iter([data_line])

        titelive_things_provider = get_provider_by_local_class("TiteLiveThings")

        product = create_product_with_thing_subcategory(
            id_at_providers="9782895026310",
            thing_name="Toto à la playa",
            date_modified_at_last_provider=datetime(2001, 1, 1),
            last_provider_id=titelive_things_provider.id,
        )
        activate_provider("TiteLiveThings")
        repository.save(product)
        titelive_things = TiteLiveThings()

        # When
        titelive_things.updateObjects()

        # Then
        updated_product = Product.query.first()
        assert updated_product.name == "nouvelles du Chili"
        assert updated_product.extraData.get("bookFormat") == BookFormat.BEAUX_LIVRES.value
    def test_should_not_create_product_when_product_is_paper_press(
        self, get_lines_from_thing_file, get_files_to_process_from_titelive_ftp, app
    ):
        # Given
        files_list = list()
        files_list.append("Quotidien30.tit")

        get_files_to_process_from_titelive_ftp.return_value = files_list

        DATA_LINE_PARTS = BASE_DATA_LINE_PARTS[:]
        DATA_LINE_PARTS[1] = "9136205982"
        DATA_LINE_PARTS[13] = "R"
        DATA_LINE_PARTS[26] = "2,10"

        data_line_1 = "~".join(DATA_LINE_PARTS)

        DATA_LINE_PARTS = BASE_DATA_LINE_PARTS[:]
        DATA_LINE_PARTS[26] = "2,10"

        data_line_2 = "~".join(DATA_LINE_PARTS)

        get_lines_from_thing_file.return_value = iter([data_line_1, data_line_2])

        activate_provider("TiteLiveThings")
        titelive_things = TiteLiveThings()

        # When
        titelive_things.updateObjects()
        products = Product.query.all()
        product = products[0]

        # Then
        assert len(products) == 1
        assert product.extraData["isbn"] == "9782895026310"
    def test_does_not_create_thing_when_too_many_columns_in_data_line(
        self, get_lines_from_thing_file, get_files_to_process_from_titelive_ftp, app
    ):
        # Given
        files_list = list()
        files_list.append("Quotidien30.tit")

        get_files_to_process_from_titelive_ftp.return_value = files_list

        DATA_LINE_PARTS = BASE_DATA_LINE_PARTS[:]
        DATA_LINE_PARTS[13] = "LE"
        DATA_LINE_PARTS[27] = "Littérature scolaire"
        DATA_LINE_PARTS[39] = "1"
        DATA_LINE_PARTS[40] = "0"

        data_line = "~".join(DATA_LINE_PARTS)

        get_lines_from_thing_file.return_value = iter([data_line])

        activate_provider("TiteLiveThings")
        titelive_things = TiteLiveThings()

        # When
        titelive_things.updateObjects()

        # Then
        assert Product.query.count() == 0
Beispiel #6
0
def save_allocine_sandbox() -> None:

    sirene = Sirene()

    create_industrial_admin_users()

    user = create_user(
        first_name="Didier",
        last_name="Champion",
        public_name="Didier Champion",
        email="*****@*****.**",
        is_beneficiary=False,
    )

    offerer = create_offerer(
        address="145, rue Chaplin",
        city="Paris 17",
        name="Le Royal - Cinéma d'essai",
        postal_code="75017",
        siren=sirene.siren,
    )

    user_offerer = create_user_offerer(
        offerer=offerer,
        user=user,
    )

    venue = create_venue(
        offerer,
        address=offerer.address,
        booking_email="*****@*****.**",
        city=offerer.city,
        comment="Salle de cinéma",
        name=offerer.name + " - Salle 1",
        postal_code=offerer.postalCode,
        siret=sirene.siret,
    )

    activate_provider("AllocineStocks")
    provider = get_provider_by_local_class("AllocineStocks")

    venue_provider = create_venue_provider(venue,
                                           provider=provider,
                                           is_active=True)

    repository.save(user, offerer, user_offerer, venue, provider,
                    venue_provider)

    offer = create_offer_with_event_product(
        venue,
        event_type=EventType.CINEMA,
        last_provider_id=provider.id,
        id_at_providers="TW92aWU6MjQ4MTAy%34007977100028-VF",
        last_provider=provider,
    )

    repository.save(offer)
    def test_does_not_create_thing_when_no_files_found(self, get_files_to_process_from_titelive_ftp, app):
        # Given
        files_list = list()
        get_files_to_process_from_titelive_ftp.return_value = files_list

        activate_provider("TiteLiveThings")
        titelive_things = TiteLiveThings()

        # When
        titelive_things.updateObjects()

        # Then
        assert Product.query.count() == 0
Beispiel #8
0
    def test_should_return_only_venue_provider_for_specified_provider(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        titelive_provider = activate_provider("TiteLiveStocks")
        allocine_provider = activate_provider("AllocineStocks")
        venue_provider_titelive = create_venue_provider(venue, titelive_provider)
        venue_provider_allocine = create_venue_provider(venue, allocine_provider)
        repository.save(venue_provider_titelive, venue_provider_allocine)

        # When
        venue_providers = get_venue_providers_to_sync(titelive_provider.id)

        # Then
        assert venue_providers == [venue_provider_titelive]
    def should_not_connect_venue_when_venue_has_no_siret(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer, siret=None, is_virtual=True)
        provider = activate_provider("LibrairesStocks")

        repository.save(venue)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        provider_type = LibrairesStocks

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # when
        with pytest.raises(ApiErrors) as error:
            connect_venue_to_provider(provider_type, stock_repository,
                                      venue_provider_payload, self.find_by_id)

        # then
        assert error.value.errors["provider"] == [
            "L’importation d’offres avec LesLibraires n’est pas disponible sans SIRET associé au lieu. Ajoutez un SIRET pour pouvoir importer les offres."
        ]
    def when_add_allocine_stocks_provider_with_no_price(self, app):
        # Given
        venue = offer_factories.VenueFactory(
            managingOfferer__siren="775671464")
        user = user_factories.AdminFactory()
        AllocinePivotFactory(siret=venue.siret)

        provider = activate_provider("AllocineStocks")

        venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.post("/venueProviders",
                                     json=venue_provider_data)

        # Then
        assert response.status_code == 400
        assert response.json["price"] == [
            "Il est obligatoire de saisir un prix."
        ]
        assert VenueProvider.query.count() == 0
    def when_add_allocine_pivot_is_missing(self, app):
        # Given
        venue = offer_factories.VenueFactory(
            managingOfferer__siren="775671464")
        user = user_factories.AdminFactory()
        provider = activate_provider("AllocineStocks")

        venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.post("/venueProviders",
                                     json=venue_provider_data)

        # Then
        assert response.status_code == 404
        assert response.json == {
            "allocine": [
                "Ce lieu n'est pas autorisé à être synchronisé avec Allociné. Veuillez contacter le support si vous souhaitez le faire."
            ]
        }
        assert VenueProvider.query.count() == 0
        def when_venue_provider_is_successfully_created(
            self, stubbed_find_by_id, stubbed_check, mock_synchronize_venue_provider, app
        ):
            # Given
            user = create_user(is_admin=True, is_beneficiary=False)
            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            repository.save(venue, user)

            stubbed_find_by_id.return_value = venue

            provider = activate_provider("LibrairesStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)
            stubbed_check.return_value = True

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 201
            venue_provider = VenueProvider.query.one()
            assert venue_provider.venueId == venue.id
            assert venue_provider.providerId == provider.id
            assert venue_provider.venueIdAtOfferProvider == "12345678912345"
            assert "id" in response.json
            venue_provider_id = response.json["id"]
            mock_synchronize_venue_provider.assert_called_once_with(dehumanize(venue_provider_id))
        def should_inject_the_appropriate_repository_to_the_usecase(
            self, mocked_connect_venue_to_provider, stubbed_find_by_id, stubbed_check, app
        ):
            # Given
            user = create_user(is_admin=True, is_beneficiary=False)
            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("LibrairesStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)
            stubbed_check.return_value = True

            # When
            auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            mocked_connect_venue_to_provider.assert_called_once_with(
                LibrairesStocks,
                api_libraires_stocks,
                {"providerId": humanize(provider.id), "venueId": humanize(venue.id)},
                stubbed_find_by_id,
            )
        def when_provider_api_not_available(self, stubbed_find_by_id, stubbed_check, app):
            # Given
            user = create_user(is_admin=True, is_beneficiary=False)
            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("LibrairesStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            errors = ApiErrors()
            errors.status_code = 422
            errors.add_error(
                "provider",
                "L’importation d’offres avec LesLibraires n’est pas disponible " "pour le SIRET 12345678912345",
            )
            stubbed_check.side_effect = [errors]

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 422
            assert response.json["provider"] == [
                "L’importation d’offres avec LesLibraires n’est pas disponible pour le SIRET 12345678912345"
            ]
            assert VenueProvider.query.count() == 0
        def test_fnac_stock_provider_create_one_stock_and_one_offer_with_wanted_attributes(
            self, mock_fnac_api_response, app
        ):
            # Given
            mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 10, "price": 16.5}])

            offerer = create_offerer()
            venue = create_venue(offerer, siret="77567146400110")

            fnac_stocks_provider = activate_provider("FnacStocks")
            venue_provider = create_venue_provider(
                venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="77567146400110"
            )
            product = create_product_with_thing_type(id_at_providers="9780199536986")
            repository.save(product, venue_provider)

            fnac_stocks = FnacStocks(venue_provider)

            # When
            fnac_stocks.updateObjects()

            # Then
            offer = Offer.query.first()
            stock = Stock.query.first()

            assert offer.type == product.type
            assert offer.description == product.description
            assert offer.venue is not None
            assert offer.bookingEmail == venue.bookingEmail
            assert offer.extraData == product.extraData

            assert stock.price == 16.5
            assert stock.quantity == 10
            assert stock.bookingLimitDatetime is None
Beispiel #16
0
    def test_query_venue_provider_load_allocine_venue_provider_attributes_when_connected_to_allocine(
            self, app):
        offerer = create_offerer()
        venue = create_venue(offerer)

        provider_allocine = activate_provider("AllocineStocks")
        provider = create_provider(local_class="TestLocalProvider")

        venue_provider = create_venue_provider(venue, provider)

        allocine_venue_provider = create_allocine_venue_provider(
            venue, provider_allocine, is_duo=True)

        repository.save(venue_provider, allocine_venue_provider)

        assert VenueProvider.query.count() == 2
        assert AllocineVenueProvider.query.count() == 1
        created_venue_provider = VenueProvider.query.filter(
            VenueProvider.providerId == provider.id).first()
        assert isinstance(created_venue_provider, VenueProvider)

        created_allocine_venue_provider = VenueProvider.query.filter(
            VenueProvider.providerId == provider_allocine.id).first()
        assert isinstance(created_allocine_venue_provider,
                          AllocineVenueProvider)
        def test_fnac_stock_provider_available_stock_is_sum_of_updated_available_and_bookings(
            self, mock_fnac_api_response, app
        ):
            # Given
            mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 5, "price": 0}])

            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            fnac_stocks_provider = activate_provider("FnacStocks")
            venue_provider = create_venue_provider(
                venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345"
            )
            product = create_product_with_thing_type(id_at_providers="9780199536986")

            offer = create_offer_with_thing_product(
                venue, product=product, id_at_providers="9780199536986@12345678912345"
            )

            stock = create_stock(id_at_providers="9780199536986@12345678912345", offer=offer, price=0, quantity=20)

            booking = create_booking(user=create_user(), quantity=1, stock=stock)

            repository.save(venue_provider, booking)

            mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 66, "price": 0}])

            fnac_stocks = FnacStocks(venue_provider)

            # When
            fnac_stocks.updateObjects()

            # Then
            stock = Stock.query.one()
            assert stock.quantity == 67
    def should_connect_to_allocine(
        self,
        app,
    ):
        # Given
        user = user_factories.AdminFactory()
        venue = offer_factories.VenueFactory(siret="12345678912345")
        AllocinePivotFactory(siret=venue.siret)

        provider = activate_provider("AllocineStocks")

        venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "price": "33.33"
        }

        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)

        # When
        auth_request.post("/venueProviders", json=venue_provider_data)

        # Then
        assert len(venue.venueProviders) == 1
        assert venue.venueProviders[0].provider == provider
    def should_not_connect_venue_when_synchronization_is_not_allowed(
            self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer, siret="12345678912345")
        provider = activate_provider("LibrairesStocks")

        repository.save(venue)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        stock_repository.can_be_synchronized.return_value = False
        provider_class = LibrairesStocks

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # when
        with pytest.raises(ApiErrors) as error:
            print(
                connect_venue_to_provider(provider_class, stock_repository,
                                          venue_provider_payload,
                                          self.find_by_id))

        # then
        assert error.value.errors["provider"] == [
            "L’importation d’offres avec LesLibraires n’est pas disponible pour le SIRET 12345678912345"
        ]
    def should_connect_venue_when_synchronization_is_allowed(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        provider = activate_provider("PraxielStocks")

        repository.save(venue)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        stock_repository.can_be_synchronized.return_value = True
        provider_type = PraxielStocks

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # When
        connect_venue_to_provider(provider_type, stock_repository,
                                  venue_provider_payload, self.find_by_id)

        # Then
        praxiel_venue_provider = VenueProvider.query.one()
        assert praxiel_venue_provider.venue == venue
    def when_add_allocine_stocks_provider_with_default_settings_at_import(
            self, app):
        # Given
        venue = offer_factories.VenueFactory(
            managingOfferer__siren="775671464")
        user = user_factories.AdminFactory()
        AllocinePivotFactory(siret=venue.siret)

        provider = activate_provider("AllocineStocks")

        venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "price": "9.99",
            "quantity": 50,
            "isDuo": True,
        }

        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.post("/venueProviders",
                                     json=venue_provider_data)

        # Then
        assert response.status_code == 201
        assert response.json["isDuo"]
        assert response.json["price"] == 9.99
        assert response.json["quantity"] == 50
    def when_add_allocine_stocks_provider_with_price_but_no_isDuo_config(
            self, app):
        # Given
        venue = offer_factories.VenueFactory(
            managingOfferer__siren="775671464")
        user = user_factories.AdminFactory()
        AllocinePivotFactory(siret=venue.siret)

        provider = activate_provider("AllocineStocks")

        venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "price": "9.99"
        }

        auth_request = TestClient(
            app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.post("/venueProviders",
                                     json=venue_provider_data)

        # Then
        assert response.status_code == 201
        json = response.json
        assert "_sa_polymorphic_on" not in json
        venue_provider = VenueProvider.query.one()
        assert json["venueId"] == humanize(venue_provider.venueId)
    def test_should_delete_product_when_it_changes_to_paper_press_product(
        self, get_lines_from_thing_file, get_files_to_process_from_titelive_ftp, app
    ):
        # Given
        files_list = list()
        files_list.append("Quotidien30.tit")

        DATA_LINE_PARTS = BASE_DATA_LINE_PARTS[:]
        DATA_LINE_PARTS[13] = "R"
        DATA_LINE_PARTS[26] = "2,10"
        data_line = "~".join(DATA_LINE_PARTS)

        get_files_to_process_from_titelive_ftp.return_value = files_list

        get_lines_from_thing_file.return_value = iter([data_line])

        titelive_provider = activate_provider("TiteLiveThings")
        repository.save(titelive_provider)
        product = create_product_with_thing_subcategory(
            id_at_providers="9782895026310",
            thing_name="Presse papier",
            date_modified_at_last_provider=datetime(2001, 1, 1),
            last_provider_id=titelive_provider.id,
        )
        repository.save(product)

        titelive_things = TiteLiveThings()

        # When
        titelive_things.updateObjects()

        # Then
        assert Product.query.count() == 0
Beispiel #24
0
    def should_connect_venue_to_allocine_provider(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        provider = activate_provider("AllocineStocks")
        allocine_pivot = create_allocine_pivot(siret=venue.siret)

        repository.save(venue, allocine_pivot)

        self.find_by_id.return_value = venue
        self.get_theaterid_for_venue.return_value = allocine_pivot.theaterId

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "price": "9.99",
            "isDuo": True,
            "quantity": 50,
        }

        # When
        connect_venue_to_allocine(venue_provider_payload, self.find_by_id,
                                  self.get_theaterid_for_venue)

        # Then
        allocine_venue_provider = AllocineVenueProvider.query.one()
        venue_provider_price_rule = AllocineVenueProviderPriceRule.query.one()

        assert allocine_venue_provider.venue == venue
        assert allocine_venue_provider.isDuo
        assert allocine_venue_provider.quantity == 50
        assert venue_provider_price_rule.price == Decimal("9.99")
        def test_fnac_stocks_create_2_stocks_and_2_offers_even_if_existing_offer_on_same_product(
            self, mock_fnac_api_response, app
        ):
            # Given
            mock_fnac_api_response.return_value = iter(
                [
                    {"ref": "9780199536986", "available": 5, "price": 16},
                    {"ref": "1550199555555", "available": 4, "price": 18},
                ]
            )

            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")

            fnac_stocks_provider = activate_provider("FnacStocks")
            venue_provider = create_venue_provider(
                venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345"
            )
            product_1 = create_product_with_thing_type(id_at_providers="9780199536986")
            product_2 = create_product_with_thing_type(id_at_providers="1550199555555")
            offer = create_offer_with_thing_product(venue, product=product_2, id_at_providers="everything_but_fnac_id")

            repository.save(offer, product_1, product_2, venue_provider)

            fnac_stocks = FnacStocks(venue_provider)

            # When
            fnac_stocks.updateObjects()

            # Then
            assert Stock.query.count() == 2
            assert Offer.query.filter_by(lastProviderId=fnac_stocks_provider.id).count() == 2
            assert fnac_stocks.last_processed_isbn == "1550199555555"
        def when_add_allocine_stocks_provider_with_price_but_no_isDuo_config(
            self, stubbed_get_theaterid_for_venue, stubbed_find_by_id, app
        ):
            # Given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer)
            user = create_user(is_admin=True, is_beneficiary=False)
            allocine_pivot = create_allocine_pivot(siret=venue.siret)
            repository.save(venue, user, allocine_pivot)
            stubbed_find_by_id.return_value = venue
            stubbed_get_theaterid_for_venue.return_value = allocine_pivot.theaterId

            provider = activate_provider("AllocineStocks")

            venue_provider_data = {"providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "9.99"}

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 201
            json = response.json
            assert "_sa_polymorphic_on" not in json
            venue_provider = VenueProvider.query.one()
            assert json["venueId"] == humanize(venue_provider.venueId)
        def test_should_return_providable_infos_with_correct_data(self, mock_fnac_api_response, app):
            # Given
            mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 1, "price": 6.36}])

            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            fnac_provider = activate_provider("FnacStocks")
            venue_provider = create_venue_provider(
                venue, fnac_provider, venue_id_at_offer_provider=venue.siret, last_sync_date=datetime(2020, 2, 4)
            )
            product = create_product_with_thing_type(id_at_providers="9780199536986")

            repository.save(venue_provider, product)

            fnac_stocks_provider = FnacStocks(venue_provider)

            # When
            fnac_providable_infos = next(fnac_stocks_provider)

            # Then
            assert mock_fnac_api_response.call_args_list == [call("12345678912345", "", datetime(2020, 2, 4))]
            assert len(fnac_providable_infos) == 2

            offer_providable_info = fnac_providable_infos[0]
            stock_providable_info = fnac_providable_infos[1]

            assert offer_providable_info.type == Offer
            assert offer_providable_info.id_at_providers == "9780199536986@12345678912345"
            assert stock_providable_info.type == Stock
            assert stock_providable_info.id_at_providers == "9780199536986@12345678912345"
        def when_add_allocine_stocks_provider_with_default_settings_at_import(self, stubbed_find_by_id, app):
            # Given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer)
            user = create_user(is_admin=True, is_beneficiary=False)
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("AllocineStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
                "price": "9.99",
                "available": 50,
                "isDuo": True,
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 201
        def test_fnac_stock_provider_update_one_stock_and_update_matching_offer(self, mock_fnac_api_response, app):
            # Given
            mock_fnac_api_response.return_value = iter([{"ref": "9780199536986", "available": 10, "price": 16}])

            offerer = create_offerer()
            venue = create_venue(offerer)

            fnac_stocks_provider = activate_provider("FnacStocks")
            venue_provider = create_venue_provider(
                venue, fnac_stocks_provider, is_active=True, venue_id_at_offer_provider="12345678912345"
            )
            product = create_product_with_thing_type(id_at_providers="9780199536986")
            offer = create_offer_with_thing_product(
                venue, product=product, id_at_providers="9780199536986@12345678912345"
            )
            stock = create_stock(id_at_providers="9780199536986@12345678912345", offer=offer, quantity=20)

            repository.save(product, offer, stock)

            fnac_stocks = FnacStocks(venue_provider)

            # When
            fnac_stocks.updateObjects()

            # Then
            stock = Stock.query.one()
            assert stock.quantity == 10
            assert Offer.query.count() == 1
        def when_add_allocine_stocks_provider_with_wrong_format_price(self, stubbed_find_by_id, app):
            # Given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer)
            user = create_user(is_admin=True, is_beneficiary=False)
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("AllocineStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
                "price": "wrong_price",
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 400
            assert response.json["global"] == ["Le prix doit être un nombre décimal"]
            assert VenueProvider.query.count() == 0