Example #1
0
    def test_does_not_allow_beginning_datetime_on_thing_offer_on_creation_and_edition(
            self, mock_update_confirmation_dates):
        # Given
        offer = factories.ThingOfferFactory()
        beginning_date = datetime.utcnow() + timedelta(days=4)
        existing_stock = factories.StockFactory(offer=offer, price=10)
        created_stock_data = StockCreationBodyModel(
            price=-1,
            beginningDatetime=beginning_date,
            bookingLimitDatetime=beginning_date)
        edited_stock_data = StockEditionBodyModel(
            id=existing_stock.id,
            price=0,
            beginningDatetime=beginning_date,
            bookingLimitDatetime=beginning_date)

        # When
        with pytest.raises(api_errors.ApiErrors) as error:
            api.upsert_stocks(
                offer_id=offer.id,
                stock_data_list=[created_stock_data, edited_stock_data])

        # Then
        assert error.value.errors == {
            "global": [
                "Impossible de mettre une date de début si l'offre ne porte pas sur un événement"
            ],
        }
Example #2
0
    def test_upsert_multiple_stocks(self, mocked_add_offer_id,
                                    mock_update_confirmation_dates):
        # Given
        offer = factories.ThingOfferFactory()
        existing_stock = factories.StockFactory(offer=offer, price=10)
        created_stock_data = StockCreationBodyModel(price=10, quantity=7)
        edited_stock_data = StockEditionBodyModel(id=existing_stock.id,
                                                  price=5,
                                                  quantity=7)

        # When
        stocks_upserted = api.upsert_stocks(
            offer_id=offer.id,
            stock_data_list=[created_stock_data, edited_stock_data])

        # Then
        created_stock = Stock.query.filter_by(id=stocks_upserted[0].id).first()
        assert created_stock.offer == offer
        assert created_stock.price == 10
        assert created_stock.quantity == 7
        edited_stock = Stock.query.filter_by(id=existing_stock.id).first()
        assert edited_stock.price == 5
        assert edited_stock.quantity == 7
        mocked_add_offer_id.assert_called_once_with(client=app.redis_client,
                                                    offer_id=offer.id)
Example #3
0
    def test_do_not_sync_algolia_if_feature_is_disabled(
            self, mocked_add_offer_id, mock_update_confirmation_dates):
        # Given
        offer = factories.ThingOfferFactory()
        created_stock_data = StockCreationBodyModel(price=10)

        # When
        api.upsert_stocks(offer_id=offer.id,
                          stock_data_list=[created_stock_data])

        # Then
        mocked_add_offer_id.assert_not_called()
Example #4
0
    def test_does_not_allow_upsert_stocks_on_a_synchronized_offer(
            self, mock_update_confirmation_dates):
        # Given
        offer = factories.ThingOfferFactory(
            lastProvider=offerers_factories.ProviderFactory(
                localClass="TiteLiveStocks"))
        created_stock_data = StockCreationBodyModel(price=10)

        # When
        with pytest.raises(api_errors.ApiErrors) as error:
            api.upsert_stocks(offer_id=offer.id,
                              stock_data_list=[created_stock_data])

        # Then
        assert error.value.errors == {
            "global": ["Les offres importées ne sont pas modifiables"]
        }
Example #5
0
    def test_does_not_allow_missing_dates_for_an_event_offer_on_creation_and_edition(
            self, mock_update_confirmation_dates):
        # Given
        offer = factories.EventOfferFactory()
        created_stock_data = StockCreationBodyModel(price=10,
                                                    beginningDatetime=None,
                                                    bookingLimitDatetime=None)

        # When
        with pytest.raises(api_errors.ApiErrors) as error:
            api.upsert_stocks(offer_id=offer.id,
                              stock_data_list=[created_stock_data])

        # Then
        assert error.value.errors == {
            "beginningDatetime": ["Ce paramètre est obligatoire"]
        }
Example #6
0
    def test_does_not_allow_invalid_price_on_creation_and_edition(
            self, mock_update_confirmation_dates):
        # Given
        offer = factories.ThingOfferFactory()
        existing_stock = factories.StockFactory(offer=offer, price=10)
        created_stock_data = StockCreationBodyModel(price=-1)
        edited_stock_data = StockEditionBodyModel(id=existing_stock.id,
                                                  price=-3)

        # When
        with pytest.raises(api_errors.ApiErrors) as error:
            api.upsert_stocks(
                offer_id=offer.id,
                stock_data_list=[created_stock_data, edited_stock_data])

        # Then
        assert error.value.errors == {
            "price": ["Le prix doit être positif"],
        }
Example #7
0
    def test_does_not_allow_booking_limit_after_beginning_for_an_event_offer_on_creation_and_edition(
            self, mock_update_confirmation_dates):
        # Given
        offer = factories.EventOfferFactory()
        beginning_date = datetime.utcnow() + timedelta(days=4)
        booking_limit = beginning_date + timedelta(days=4)
        created_stock_data = StockCreationBodyModel(
            price=10,
            beginningDatetime=beginning_date,
            bookingLimitDatetime=booking_limit)

        # When
        with pytest.raises(api_errors.ApiErrors) as error:
            api.upsert_stocks(offer_id=offer.id,
                              stock_data_list=[created_stock_data])

        # Then
        assert error.value.errors == {
            "bookingLimitDatetime": [
                "La date limite de réservation pour cette offre est postérieure à la date de début de l'évènement"
            ]
        }