def test_if_booking_on_outings_return_amount(self):
            # Given
            create_user(id=1)
            create_deposit(amount=500)
            create_offerer(id=10)
            create_product(id=1,
                           product_type="ThingType.MUSEES_PATRIMOINE_ABO")
            create_venue(id=15, offerer_id=10)
            create_offer(
                id=30,
                venue_id=15,
                product_type="ThingType.MUSEES_PATRIMOINE_ABO",
                product_id=1,
            )
            create_stock(id=20, offer_id=30)
            create_booking(user_id=1, amount=10, quantity=2, stock_id=20)

            # When
            query = _get_theoric_amount_spent_in_outings_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent_in_outings = pandas.read_sql(
                    query, connection, index_col="user_id")
            pandas.testing.assert_frame_equal(
                theoric_amount_spent_in_outings,
                pandas.DataFrame(
                    [20.0],
                    columns=["Dépenses sorties"],
                    index=Int64Index([1], name="user_id"),
                ),
            )
        def test_should_return_exact_number_of_non_cancelled_bookings(
                self, app):
            # Given
            create_user(id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1, product_type="ThingType.ACTIVATION")
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type="ThingType.ACTIVATION")
            create_stock(offer_id=1, id=1)
            create_product(id=2, product_type="ThingType.MUSIQUE")
            create_offer(venue_id=1,
                         product_id=2,
                         id=2,
                         product_type="ThingType.MUSIQUE")
            create_stock(offer_id=2, id=2)
            create_booking(id=1,
                           user_id=1,
                           quantity=1,
                           stock_id=2,
                           is_used=True)
            create_booking(id=2,
                           user_id=1,
                           quantity=1,
                           stock_id=2,
                           token="ABC321",
                           is_used=True)
            create_booking(
                id=3,
                user_id=1,
                quantity=3,
                stock_id=2,
                token="FAM321",
                is_cancelled=True,
            )
            create_booking(id=4,
                           user_id=1,
                           quantity=3,
                           stock_id=1,
                           token="CON321")
            expected_number_of_non_cancelled_bookings_per_venue = pandas.Series(
                data=[2],
                name="non_cancelled_bookings",
                index=Int64Index([1], name="venue_id"),
            )

            # When
            query = _get_number_of_non_cancelled_bookings_per_venue()

            # Then
            with ENGINE.connect() as connection:
                total_non_cancelled_bookings_per_venue = pandas.read_sql(
                    query, connection, index_col="venue_id")
            pandas.testing.assert_series_equal(
                total_non_cancelled_bookings_per_venue[
                    "non_cancelled_bookings"],
                expected_number_of_non_cancelled_bookings_per_venue,
            )
        def test_if_booking_is_not_used_return_zero(self):
            # Given
            create_user(id=45)
            create_offerer(id=1)
            create_venue(offerer_id=1)
            create_product(id=1)
            create_offer(venue_id=1, product_id=1, id=1)
            create_stock(offer_id=1, id=1)
            create_deposit(user_id=45)
            create_booking(
                user_id=45,
                stock_id=1,
                quantity=1,
                amount=10,
                is_cancelled=False,
                is_used=False,
            )

            # When
            query = _get_actual_amount_spent_query()

            # Then
            with ENGINE.connect() as connection:
                amount_spent = pandas.read_sql(query,
                                               connection,
                                               index_col="user_id")
            pandas.testing.assert_frame_equal(
                amount_spent,
                pandas.DataFrame(
                    [0.0],
                    columns=["Montant réél dépensé"],
                    index=Int64Index([45], name="user_id"),
                ),
            )
示例#4
0
        def test_should_return_the_number_of_bookings_not_cancelled(self):
            # Given
            create_user(id=1)
            create_user(id=2, email="*****@*****.**")
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1)
            create_offer(venue_id=1, product_id=1, id=1)
            create_stock(offer_id=1, id=1)
            create_booking(user_id=1, stock_id=1, id=1, token="123455")
            create_booking(user_id=2, stock_id=1, id=2, token="567UA0")
            create_booking(user_id=2,
                           stock_id=1,
                           id=3,
                           token="6YHA08",
                           is_cancelled=True)

            # When
            query = _get_number_of_bookings_not_cancelled_query()

            # Then
            with ENGINE.connect() as connection:
                number_of_bookings_not_cancelled = pandas.read_sql(
                    query, connection, index_col="offerer_id")
            assert (number_of_bookings_not_cancelled.loc[
                1, "Nombre de réservations non annulées"] == 2)
        def test_should_return_2_when_user_has_unused_activation_booking(self):
            # Given
            create_user(id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1)
            create_product(id=1, product_type="ThingType.ACTIVATION")
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type="ThingType.ACTIVATION")
            create_stock(offer_id=1)
            create_booking(user_id=1, stock_id=1, is_used=False)

            # When
            query = _get_experimentation_sessions_query()

            # Then
            with ENGINE.connect() as connection:
                experimentation_sessions = pandas.read_sql(query,
                                                           connection,
                                                           index_col="user_id")
            pandas.testing.assert_series_equal(
                experimentation_sessions["Vague d'expérimentation"],
                pandas.Series(
                    data=[2],
                    name="Vague d'expérimentation",
                    index=Int64Index([1], name="user_id"),
                ),
            )
        def test_if_booking_amount_10_and_quantity_2_return_20(self):
            # Given
            create_user(id=45)
            create_offerer(id=1)
            create_venue(offerer_id=1)
            create_product(id=1)
            create_offer(venue_id=1, product_id=1, id=1)
            create_stock(offer_id=1, id=1)
            create_deposit(user_id=45)
            create_booking(
                user_id=45,
                stock_id=1,
                quantity=2,
                amount=10,
                is_cancelled=False,
                is_used=True,
            )

            # When
            query = _get_theoric_amount_spent_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent = pandas.read_sql(query,
                                                       connection,
                                                       index_col="user_id")
            pandas.testing.assert_frame_equal(
                theoric_amount_spent,
                pandas.DataFrame(
                    [20.0],
                    columns=["Montant théorique dépensé"],
                    index=Int64Index([45], name="user_id"),
                ),
            )
        def test_if_booking_on_physical_good_type_but_has_url_return_0(self):
            # Given
            create_user(id=1)
            create_deposit(amount=500)
            create_offerer(id=10)
            create_product(id=1, product_type="ThingType.MUSIQUE")
            create_venue(id=15, offerer_id=10)
            create_offer(
                id=30,
                venue_id=15,
                product_type="ThingType.MUSIQUE",
                url="u.rl",
                product_id=1,
            )
            create_stock(id=20, offer_id=30)
            create_booking(user_id=1, amount=10, quantity=1, stock_id=20)

            # When
            query = _get_theoric_amount_spent_in_physical_goods_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent_in_physical = pandas.read_sql(
                    query, connection, index_col="user_id")
            pandas.testing.assert_frame_equal(
                theoric_amount_spent_in_physical,
                pandas.DataFrame(
                    [0.0],
                    columns=["Dépenses physiques"],
                    index=Int64Index([1], name="user_id"),
                ),
            )
        def test_if_activation_dates_is_today_return_seniority_of_zero_day(
                self):
            # Given
            create_user(id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1, product_type="ThingType.ACTIVATION")
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type="ThingType.ACTIVATION")
            create_stock(offer_id=1)
            create_booking(user_id=1,
                           stock_id=1,
                           is_used=True,
                           date_used="2020-01-22")

            # When
            query = _get_users_seniority_query()

            # Then
            with ENGINE.connect() as connection:
                user_seniority = pandas.read_sql(query,
                                                 connection,
                                                 index_col="user_id")
            pandas.testing.assert_frame_equal(
                user_seniority,
                pandas.DataFrame(
                    [0.0],
                    columns=["Ancienneté en jours"],
                    index=Int64Index([1], name="user_id"),
                ),
            )
        def test_should_return_how_many_time_first_booking(self):
            # Given
            create_user(id=1)
            create_deposit(amount=500)
            create_offerer(id=10)
            create_product(id=1,
                           product_type="ThingType.MUSEES_PATRIMOINE_ABO")
            create_venue(id=15, offerer_id=10)
            create_offer(
                id=30,
                venue_id=15,
                product_type="ThingType.MUSEES_PATRIMOINE_ABO",
                product_id=1,
            )
            create_stock(id=20, offer_id=30)
            create_booking(id=1,
                           user_id=1,
                           amount=10,
                           quantity=1,
                           stock_id=20,
                           is_used=True)
            create_booking(
                id=2,
                user_id=1,
                amount=10,
                quantity=1,
                stock_id=20,
                token="ABC321",
                is_used=True,
            )
            create_booking(
                id=3,
                user_id=1,
                amount=10,
                quantity=3,
                stock_id=20,
                token="FAM321",
                is_cancelled=True,
            )

            expected_first_booking_number = pandas.Series(
                index=pandas.Index(data=[30], name="offer_id"),
                data=[1],
                name="Nombre de premières réservations",
            )

            # When
            query = _get_count_first_booking_query()

            # Then
            with ENGINE.connect() as connection:
                count_first_booking = pandas.read_sql(query,
                                                      connection,
                                                      index_col="offer_id")
            pandas.testing.assert_series_equal(
                count_first_booking["Nombre de premières réservations"],
                expected_first_booking_number,
            )
        def test_should_return_exact_booking_amount(self, app):
            # Given
            create_user(id=1)
            create_deposit(user_id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1, product_type="ThingType.ACTIVATION")
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type="ThingType.ACTIVATION")
            create_stock(offer_id=1, id=1)
            create_product(id=2, product_type="ThingType.MUSIQUE")
            create_offer(venue_id=1,
                         product_id=2,
                         id=2,
                         product_type="ThingType.MUSIQUE")
            create_stock(offer_id=2, id=2)
            create_booking(id=1,
                           user_id=1,
                           quantity=1,
                           stock_id=2,
                           is_used=True)
            create_booking(
                id=2,
                user_id=1,
                quantity=1,
                amount=10,
                stock_id=2,
                token="ABC321",
                is_used=True,
            )
            create_booking(
                id=3,
                user_id=1,
                quantity=3,
                amount=5,
                stock_id=2,
                token="FAM321",
                is_cancelled=True,
            )
            expected_amount_per_booking = pandas.Series(
                data=[0.0, 10.0, 15.0],
                name="Montant de la réservation",
                index=Int64Index([1, 2, 3], name="booking_id"),
            )

            # When
            query = get_booking_amount()

            # Then
            with ENGINE.connect() as connection:
                booking_amount = pandas.read_sql(query,
                                                 connection,
                                                 index_col="booking_id")
            pandas.testing.assert_series_equal(
                booking_amount["Montant de la réservation"],
                expected_amount_per_booking)
示例#11
0
        def test_should_not_count_bookings_appearing_on_payment_if_payment_s_current_status_is_banned(
            self, ):
            # Given
            create_user(id=1)
            create_user(id=2, email="*****@*****.**")
            create_product(id=1)
            create_product(id=2)
            create_offerer(id=3)
            create_venue(
                offerer_id=3,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(venue_id=1, product_id=1, id=3)
            create_stock(offer_id=3, id=1)
            create_offer(venue_id=1, product_id=2, id=2)
            create_stock(offer_id=2, id=2)
            create_booking(user_id=1, stock_id=1, id=4, quantity=2)
            create_payment(booking_id=4, id=1)
            create_payment_status(payment_id=1,
                                  id=1,
                                  date="2019-01-01",
                                  status="PENDING")
            create_payment_status(payment_id=1,
                                  id=2,
                                  date="2019-01-02",
                                  status="BANNED")

            expected_stocks_booking_information = pandas.Series(
                index=pandas.Index(data=[1, 2], name="stock_id"),
                data=[0, 0],
                name="Nombre de réservations ayant un paiement",
            )

            # When
            query = _get_stocks_booking_information_query()

            # Then
            with ENGINE.connect() as connection:
                stocks_booking_information = pandas.read_sql(
                    query, connection, index_col="stock_id")
            pandas.testing.assert_series_equal(
                stocks_booking_information[
                    "Nombre de réservations ayant un paiement"],
                expected_stocks_booking_information,
            )

            # Then
            pandas.testing.assert_series_equal(
                stocks_booking_information[
                    "Nombre de réservations ayant un paiement"],
                expected_stocks_booking_information,
            )
        def test_if_user_is_beneficiary_is_false_return_empty_data_frame(self):
            # Given
            create_user(id=1, is_beneficiary=False)

            # When
            query = _get_theoric_amount_spent_in_physical_goods_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent_in_physical = pandas.read_sql(
                    query, connection, index_col="user_id")
            assert theoric_amount_spent_in_physical.empty
        def test_if_user_cannot_book_free_offer_return_empty_data_frame(self):
            # Given
            create_user(id=45, is_beneficiary=False)

            # When
            query = _get_theoric_amount_spent_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent = pandas.read_sql(query,
                                                       connection,
                                                       index_col="user_id")
            assert theoric_amount_spent.empty
        def test_should_return_an_empty_series_if_user_cannot_book_free_offers(
                self):
            # Given
            create_user(is_beneficiary=False)

            # When
            query = _get_experimentation_sessions_query()

            # Then
            with ENGINE.connect() as connection:
                experimentation_sessions = pandas.read_sql(query,
                                                           connection,
                                                           index_col="user_id")
            assert experimentation_sessions["Vague d'expérimentation"].empty
示例#15
0
        def test_should_return_column_with_total_number_of_bookings_cancelled_and_not(
            self, ):
            # Given
            create_user(id=1)
            create_user(id=2, email="*****@*****.**")
            create_product(id=1)
            create_product(id=2)
            create_offerer(id=3)
            create_venue(
                offerer_id=3,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(venue_id=1, product_id=1, id=3)
            create_stock(offer_id=3, id=1)
            create_offer(venue_id=1, product_id=2, id=2)
            create_stock(offer_id=2, id=2)
            create_booking(user_id=1,
                           stock_id=1,
                           id=4,
                           quantity=2,
                           is_cancelled=True)
            create_booking(user_id=2,
                           stock_id=2,
                           id=5,
                           quantity=1,
                           token="IS02JE")

            expected_stocks_booking_information = pandas.Series(
                index=pandas.Index(data=[1, 2], name="stock_id"),
                data=[2, 1],
                name="Nombre total de réservations",
            )

            # When
            query = _get_stocks_booking_information_query()

            # Then
            with ENGINE.connect() as connection:
                stocks_booking_information = pandas.read_sql(
                    query, connection, index_col="stock_id")
            pandas.testing.assert_series_equal(
                stocks_booking_information["Nombre total de réservations"],
                expected_stocks_booking_information,
            )
        def test_if_user_has_no_booking_return_0(self):
            # Given
            create_user(id=1)

            # When
            query = _get_theoric_amount_spent_in_outings_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent_in_outings = pandas.read_sql(
                    query, connection, index_col="user_id")
            pandas.testing.assert_frame_equal(
                theoric_amount_spent_in_outings,
                pandas.DataFrame(
                    [0.0],
                    columns=["Dépenses sorties"],
                    index=Int64Index([1], name="user_id"),
                ),
            )
        def test_if_user_has_not_booked_return_0(self):
            # Given
            create_user(id=45)

            # When
            query = _get_theoric_amount_spent_query()

            # Then
            with ENGINE.connect() as connection:
                theoric_amount_spent = pandas.read_sql(query,
                                                       connection,
                                                       index_col="user_id")
            pandas.testing.assert_frame_equal(
                theoric_amount_spent,
                pandas.DataFrame(
                    [0.0],
                    columns=["Montant théorique dépensé"],
                    index=Int64Index([45], name="user_id"),
                ),
            )
        def test_should_return_2_when_user_does_not_have_activation_booking(
                self):
            # Given
            create_user()

            # When
            query = _get_experimentation_sessions_query()

            # Then
            with ENGINE.connect() as connection:
                experimentation_sessions = pandas.read_sql(query,
                                                           connection,
                                                           index_col="user_id")
            pandas.testing.assert_series_equal(
                experimentation_sessions["Vague d'expérimentation"],
                pandas.Series(
                    data=[2],
                    name="Vague d'expérimentation",
                    index=Int64Index([1], name="user_id"),
                ),
            )
        def test_should_return_how_many_time_in_favorite_columns(self):
            # Given
            create_user(id=1)
            create_product(id=1)
            create_offerer(id=1)
            create_venue(
                offerer_id=1,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type="ThingType.LIVRE_EDITION")
            create_favorite(id=1, offer_id=1, user_id=1)

            expected_favorites_number = pandas.Series(
                index=pandas.Index(data=[1], name="offer_id"),
                data=[1],
                name="Nombre de fois où l'offre a été mise en favoris",
            )

            # When
            query = _get_count_favorites_query()

            # Then
            with ENGINE.connect() as connection:
                count_favorites = pandas.read_sql(query,
                                                  connection,
                                                  index_col="offer_id")
            pandas.testing.assert_series_equal(
                count_favorites[
                    "Nombre de fois où l'offre a été mise en favoris"],
                expected_favorites_number,
            )
        def test_should_return_physical_product_column_with_false_if_not_relevant_product_type(
            self, ):
            # Given
            create_user(id=1)
            create_product(id=1)
            create_offerer(id=1)
            create_venue(
                offerer_id=1,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type="ThingType.CINEMA_CARD")

            expected_is_physical_information = pandas.Series(
                index=pandas.Index(data=[1], name="offer_id"),
                data=[False],
                name="Bien physique",
            )

            # When
            query = _get_is_physical_information_query()

            # Then
            with ENGINE.connect() as connection:
                is_physical_information = pandas.read_sql(query,
                                                          connection,
                                                          index_col="offer_id")
            pandas.testing.assert_series_equal(
                is_physical_information["Bien physique"],
                expected_is_physical_information,
            )
示例#21
0
        def test_should_return_column_with_0_cancelled_bookings_if_no_booking(
                self):
            # Given
            create_user(id=1)
            create_user(id=2, email="*****@*****.**")
            create_product(id=1)
            create_product(id=2)
            create_offerer(id=3)
            create_venue(
                offerer_id=3,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(venue_id=1, product_id=1, id=3)
            create_stock(offer_id=3, id=1)

            expected_stocks_booking_information = pandas.Series(
                index=pandas.Index(data=[1], name="stock_id"),
                data=[0],
                name="Nombre de réservations annulées",
            )

            # When
            query = _get_stocks_booking_information_query()

            # Then
            with ENGINE.connect() as connection:
                stocks_booking_information = pandas.read_sql(
                    query, connection, index_col="stock_id")
            pandas.testing.assert_series_equal(
                stocks_booking_information["Nombre de réservations annulées"],
                expected_stocks_booking_information,
            )
        def test_should_return_outings_column_with_true_if_relevant_product_type(
                self, offer_type):
            # Given
            create_user(id=1)
            create_product(id=1)
            create_offerer(id=1)
            create_venue(
                offerer_id=1,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(venue_id=1,
                         product_id=1,
                         id=1,
                         product_type=offer_type)

            expected_is_outing_information = pandas.Series(
                index=pandas.Index(data=[1], name="offer_id"),
                data=[True],
                name="Sortie",
            )

            # When
            query = _get_is_outing_information_query()

            # Then
            with ENGINE.connect() as connection:
                is_outing_information = pandas.read_sql(query,
                                                        connection,
                                                        index_col="offer_id")
            pandas.testing.assert_series_equal(is_outing_information["Sortie"],
                                               expected_is_outing_information)
示例#23
0
        def test_should_return_the_creation_date_of_the_offer_s_first_booking(
                self):
            # Given
            create_user(id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1)
            create_product(id=1)
            create_offer(venue_id=1, product_id=1)
            create_stock(offer_id=1)
            first_booking_date = datetime(2019, 9, 20, 12, 0, 0)
            second_booking_date = datetime(2019, 9, 22, 12, 0, 0)
            create_booking(
                user_id=1,
                stock_id=1,
                id=1,
                date_created=first_booking_date,
                token="123456",
            )
            create_booking(
                user_id=1,
                stock_id=1,
                id=2,
                date_created=second_booking_date,
                token="AZERTY",
            )

            # When
            query = _get_first_booking_creation_dates_query()

            # Then
            with ENGINE.connect() as connection:
                first_booking_dates = pandas.read_sql(query,
                                                      connection,
                                                      index_col="offerer_id")
            assert (first_booking_dates.loc[1, "Date de première réservation"]
                    == first_booking_date)
        def test_should_create_enriched_offer_data_view_without_duplicates(
                self):
            # Given
            create_user(id=1)
            create_user(id=2, email="*****@*****.**")
            create_user(id=3, email="*****@*****.**")
            create_product(id=1, product_type="EventType.CINEMA")
            create_product(id=2, product_type="ThingType.LIVRE_EDITION")
            create_offerer(id=3)
            create_offerer(id=4, siren="234567890")
            create_venue(offerer_id=3, id=1, siret="12345678900026")
            create_venue(offerer_id=4, id=2, siret="23456789000067")
            create_offer(
                venue_id=1,
                product_id=1,
                id=3,
                product_type="EventType.CINEMA",
                name="Test",
            )
            create_offer(
                venue_id=2,
                product_id=2,
                id=4,
                product_type="ThingType.LIVRE_EDITION",
                name="RIP Dylan Rieder",
            )
            create_stock(
                offer_id=3,
                id=1,
                date_created="2019-11-01",
                quantity=10,
                booking_limit_datetime="2019-11-23",
                beginning_datetime="2019-11-24",
            )
            create_stock(offer_id=4,
                         id=2,
                         date_created="2019-10-01",
                         quantity=12)
            create_booking(user_id=1, stock_id=1, id=4, quantity=2)
            create_payment(booking_id=4, id=1)
            create_payment_status(payment_id=1,
                                  id=1,
                                  date="2019-01-01",
                                  status="PENDING")
            create_favorite(id=1, offer_id=3, user_id=1)
            create_favorite(id=2, offer_id=4, user_id=2)
            create_favorite(id=3, offer_id=3, user_id=3)

            expected_enriched_offer = pandas.DataFrame(
                index=pandas.Index(data=[3, 4], name="offer_id"),
                data={
                    "Identifiant de la structure": [3, 4],
                    "Nom de la structure": ["Test Offerer", "Test Offerer"],
                    "Identifiant du lieu": [1, 2],
                    "Nom du lieu": ["Test Venue", "Test Venue"],
                    "Département du lieu": ["93", "93"],
                    "Nom de l'offre": ["Test", "RIP Dylan Rieder"],
                    "Catégorie de l'offre": [
                        "EventType.CINEMA",
                        "ThingType.LIVRE_EDITION",
                    ],
                    "Date de création de l'offre": [
                        datetime(2019, 11, 20),
                        datetime(2019, 11, 20),
                    ],
                    "isDuo": [False, False],
                    "Offre numérique": [False, False],
                    "Bien physique": [False, True],
                    "Sortie": [True, False],
                    "Nombre de réservations": [2.0, 0.0],
                    "Nombre de réservations annulées": [0.0, 0.0],
                    "Nombre de réservations validées": [0.0, 0.0],
                    "Nombre de fois où l'offre a été mise en favoris":
                    [2.0, 1.0],
                    "Stock": [10.0, 12.0],
                    "offer_humanized_id": ["AM", "AQ"],
                    "Lien portail pro": [
                        "https://pro.passculture.beta.gouv.fr/offres/AM",
                        "https://pro.passculture.beta.gouv.fr/offres/AQ"
                    ],
                    "Lien WEBAPP": [
                        "https://app.passculture.beta.gouv.fr/offre/details/AM",
                        "https://app.passculture.beta.gouv.fr/offre/details/AQ"
                    ],
                    "Lien vers FlaskAdmin": [
                        "https://backend.passculture.beta.gouv.fr/pc/back-office/offersqlentity/edit/?id=3",
                        "https://backend.passculture.beta.gouv.fr/pc/back-office/offersqlentity/edit/?id=4"
                    ],
                    "Nombre de premières réservations": [1.0, np.nan]
                },
            )

            # When
            create_enriched_offer_data(ENGINE)

            # Then
            with ENGINE.connect() as connection:
                offer_details = pandas.read_sql_table("enriched_offer_data",
                                                      connection,
                                                      index_col="offer_id")
            pandas.testing.assert_frame_equal(offer_details,
                                              expected_enriched_offer)
        def test_should_return_real_revenue_per_venue(self, app):
            # Given
            create_user(id=1)
            create_deposit(id=1, user_id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1, product_type="ThingType.ACTIVATION")
            create_offer(
                venue_id=1,
                product_id=1,
                id=1,
                product_type="ThingType.ACTIVATION",
                date_created="2020-05-13",
            )
            create_stock(offer_id=1, id=1)
            create_product(id=2, product_type="ThingType.MUSIQUE")
            create_offer(
                venue_id=1,
                product_id=2,
                id=2,
                product_type="ThingType.MUSIQUE",
                date_created="2020-05-10",
            )
            create_offer(
                venue_id=1,
                product_id=2,
                id=3,
                product_type="ThingType.MUSIQUE",
                date_created="2020-05-11",
            )
            create_stock(offer_id=2, id=2, price=10)
            create_stock(offer_id=3, id=3, price=20)
            create_booking(id=1,
                           user_id=1,
                           quantity=1,
                           stock_id=2,
                           amount=10,
                           is_used=True)
            create_booking(
                id=2,
                user_id=1,
                quantity=1,
                stock_id=2,
                amount=10,
                token="ABC321",
                is_used=True,
            )
            create_booking(
                id=3,
                user_id=1,
                quantity=1,
                stock_id=2,
                amount=10,
                token="FAM321",
                is_cancelled=True,
            )
            create_booking(
                id=4,
                user_id=1,
                quantity=1,
                stock_id=1,
                token="CON321",
                is_cancelled=False,
            )
            create_booking(
                id=5,
                user_id=1,
                quantity=2,
                stock_id=3,
                amount=20,
                token="LAB123",
                is_cancelled=False,
            )
            expected_real_revenue_per_venue = pandas.Series(
                data=[20.0],
                name="real_revenue",
                index=Int64Index([1], name="venue_id"))
            # When
            query = _get_real_revenue_per_venue()

            # Then
            with ENGINE.connect() as connection:
                real_revenue_per_venue = pandas.read_sql(query,
                                                         connection,
                                                         index_col="venue_id")
            pandas.testing.assert_series_equal(
                expected_real_revenue_per_venue,
                real_revenue_per_venue["real_revenue"])
        def test_should_return_last_offer_creation_date(self, app):
            # Given
            create_user(id=1)
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1, product_type="ThingType.ACTIVATION")
            create_offer(
                venue_id=1,
                product_id=1,
                id=1,
                product_type="ThingType.ACTIVATION",
                date_created="2020-05-13",
            )
            create_stock(offer_id=1, id=1)
            create_product(id=2, product_type="ThingType.MUSIQUE")
            create_offer(
                venue_id=1,
                product_id=2,
                id=2,
                product_type="ThingType.MUSIQUE",
                date_created="2020-05-10",
            )
            create_offer(
                venue_id=1,
                product_id=2,
                id=3,
                product_type="ThingType.MUSIQUE",
                date_created="2020-05-11",
            )
            create_stock(offer_id=2, id=2)
            create_booking(id=1,
                           user_id=1,
                           quantity=1,
                           stock_id=2,
                           is_used=True)
            create_booking(id=2,
                           user_id=1,
                           quantity=1,
                           stock_id=2,
                           token="ABC321",
                           is_used=True)
            create_booking(
                id=3,
                user_id=1,
                quantity=3,
                stock_id=2,
                token="FAM321",
                is_cancelled=True,
            )
            create_booking(id=4,
                           user_id=1,
                           quantity=3,
                           stock_id=1,
                           token="CON321")
            expected_last_offer_creation_date = pandas.Series(
                data=["2020-05-11"],
                name="last_offer_creation_date",
                index=Int64Index([1], name="venue_id"),
            )
            expected_last_offer_creation_date = pandas.to_datetime(
                expected_last_offer_creation_date, format="%Y-%m-%d")
            # When
            query = _get_last_offer_creation_date()

            # Then
            with ENGINE.connect() as connection:
                last_offer_creation_date = pandas.read_sql(
                    query, connection, index_col="venue_id")
            pandas.testing.assert_series_equal(
                expected_last_offer_creation_date,
                last_offer_creation_date["last_offer_creation_date"],
            )
        def test_should_return_booking_cancelled_booking_and_used_booking_number_columns(
            self, ):
            # Given
            create_user(id=1)
            create_deposit(amount=500)
            create_offerer(id=10)
            create_product(id=1,
                           product_type="ThingType.MUSEES_PATRIMOINE_ABO")
            create_venue(id=15, offerer_id=10)
            create_offer(
                id=30,
                venue_id=15,
                product_type="ThingType.MUSEES_PATRIMOINE_ABO",
                product_id=1,
            )
            create_stock(id=20, offer_id=30)
            create_booking(id=1,
                           user_id=1,
                           amount=10,
                           quantity=1,
                           stock_id=20,
                           is_used=True)
            create_booking(
                id=2,
                user_id=1,
                amount=10,
                quantity=1,
                stock_id=20,
                token="ABC321",
                is_used=True,
            )
            create_booking(
                id=3,
                user_id=1,
                amount=10,
                quantity=3,
                stock_id=20,
                token="FAM321",
                is_cancelled=True,
            )

            expected_booking_number = pandas.Series(
                index=pandas.Index(data=[30], name="offer_id"),
                data=[5],
                name="Nombre de réservations",
            )

            expected_cancelled_booking_number = pandas.Series(
                index=pandas.Index(data=[30], name="offer_id"),
                data=[3],
                name="Nombre de réservations annulées",
            )

            expected_used_booking_number = pandas.Series(
                index=pandas.Index(data=[30], name="offer_id"),
                data=[2],
                name="Nombre de réservations validées",
            )

            # When
            query = _get_offer_booking_information_query()

            # Then
            with ENGINE.connect() as connection:
                offer_booking_information = pandas.read_sql(
                    query, connection, index_col="offer_id")
            pandas.testing.assert_series_equal(
                offer_booking_information["Nombre de réservations"],
                expected_booking_number,
            )
            pandas.testing.assert_series_equal(
                offer_booking_information["Nombre de réservations annulées"],
                expected_cancelled_booking_number,
            )
            pandas.testing.assert_series_equal(
                offer_booking_information["Nombre de réservations validées"],
                expected_used_booking_number,
            )
示例#28
0
        def test_should_return_current_year_revenue(self):

            # Given
            create_user(id=1)
            create_deposit(amount=500)
            create_offerer(id=10)
            create_product(id=1,
                           product_type="ThingType.MUSEES_PATRIMOINE_ABO")
            create_venue(id=15, offerer_id=10)
            create_offer(
                id=30,
                venue_id=15,
                product_type="ThingType.MUSEES_PATRIMOINE_ABO",
                product_id=1,
            )
            create_stock(id=20, offer_id=30)
            create_booking(
                id=1,
                user_id=1,
                amount=10,
                quantity=1,
                stock_id=20,
                is_used=True,
            )
            create_booking(id=2,
                           user_id=1,
                           amount=10,
                           quantity=1,
                           stock_id=20,
                           token="ABC321",
                           is_used=True,
                           date_created=f'{datetime.now().year}-01-05')
            create_booking(
                id=3,
                user_id=1,
                amount=10,
                quantity=3,
                stock_id=20,
                token="FAM321",
                is_cancelled=True,
            )

            expected_current_year_revenue = pandas.Series(
                index=pandas.Index(data=[10], name="offerer_id"),
                data=[10.0],
                name="Chiffre d'affaire réel année civile en cours",
            )

            # When
            query = _get_current_year_revenue()

            # Then
            with ENGINE.connect() as connection:
                current_year_revenue = pandas.read_sql(query,
                                                       connection,
                                                       index_col="offerer_id")
            pandas.testing.assert_series_equal(
                current_year_revenue[
                    "Chiffre d'affaire réel année civile en cours"],
                expected_current_year_revenue,
            )
        def test_should_return_all_values(self):
            # Given
            create_user(id=1)
            create_user(id=2, email="*****@*****.**")
            create_product(id=1, product_type="EventType.CINEMA")
            create_product(id=2, product_type="ThingType.LIVRE_EDITION")
            create_offerer(id=3)
            create_venue(
                offerer_id=3,
                id=1,
                siret=None,
                postal_code=None,
                city=None,
                departement_code=None,
                is_virtual=True,
            )
            create_offer(
                venue_id=1,
                product_id=1,
                id=3,
                product_type="EventType.CINEMA",
                name="Test",
            )
            create_stock(
                offer_id=3,
                id=1,
                date_created="2019-11-01",
                quantity=10,
                booking_limit_datetime="2019-11-23",
                beginning_datetime="2019-11-24",
            )
            create_offer(
                venue_id=1,
                product_id=2,
                id=2,
                product_type="ThingType.LIVRE_EDITION",
                name="Test bis",
            )
            create_stock(offer_id=2,
                         id=2,
                         date_created="2019-10-01",
                         quantity=12)
            create_booking(user_id=1, stock_id=1, id=4, quantity=2)
            create_payment(booking_id=4, id=1)
            create_payment_status(payment_id=1,
                                  id=1,
                                  date="2019-01-01",
                                  status="PENDING")

            create_stocks_booking_view(ENGINE)
            create_available_stocks_view(ENGINE)

            expected_stocks_details = pandas.DataFrame(
                index=pandas.Index(data=[1, 2], name="stock_id"),
                data={
                    "Identifiant de l'offre": [3, 2],
                    "Nom de l'offre": ["Test", "Test bis"],
                    "offerer_id": [3, 3],
                    "Type d'offre":
                    ["EventType.CINEMA", "ThingType.LIVRE_EDITION"],
                    "Département": [None, None],
                    "Date de création du stock": [
                        datetime(2019, 11, 1),
                        datetime(2019, 10, 1),
                    ],
                    "Date limite de réservation":
                    [datetime(2019, 11, 23), pandas.NaT],
                    "Date de début de l'évènement": [
                        datetime(2019, 11, 24),
                        pandas.NaT,
                    ],
                    "Stock disponible réel": [8, 12],
                    "Stock disponible brut de réservations": [10, 12],
                    "Nombre total de réservations": [2, 0],
                    "Nombre de réservations annulées": [0, 0],
                    "Nombre de réservations ayant un paiement": [2, 0],
                },
            )

            # When
            create_materialized_enriched_stock_view(ENGINE)

            # Then
            with ENGINE.connect() as connection:
                stocks_details = pandas.read_sql_table("enriched_stock_data",
                                                       connection,
                                                       index_col="stock_id")
            pandas.testing.assert_frame_equal(stocks_details,
                                              expected_stocks_details)
            def test_should_return_booking_payment_status(self, app):
                # Given
                create_user(id=1)
                create_deposit(user_id=1)
                create_offerer(id=1)
                create_venue(offerer_id=1, id=1)
                create_product(id=1, product_type="ThingType.ACTIVATION")
                create_offer(venue_id=1,
                             product_id=1,
                             id=1,
                             product_type="ThingType.ACTIVATION")
                create_stock(offer_id=1, id=1)
                create_product(id=2, product_type="ThingType.MUSIQUE")
                create_offer(venue_id=1,
                             product_id=2,
                             id=2,
                             product_type="ThingType.MUSIQUE")
                create_stock(offer_id=2, id=2)
                create_booking(id=1,
                               user_id=1,
                               quantity=1,
                               stock_id=2,
                               is_used=True)
                create_booking(
                    id=2,
                    user_id=1,
                    quantity=1,
                    amount=10,
                    stock_id=2,
                    token="ABC321",
                    is_used=True,
                )
                create_booking(
                    id=3,
                    user_id=1,
                    quantity=3,
                    amount=5,
                    stock_id=2,
                    token="FAM321",
                    is_cancelled=True,
                )
                create_payment(id=1, booking_id=2, amount=10)
                create_payment_status(id=1, payment_id=1, status="SENT")
                create_payment(id=2, booking_id=3, amount=15)
                create_payment_status(id=2, payment_id=2, status="PENDING")
                expected_booking_payment_status = pandas.Series(
                    data=["Remboursé"],
                    name="Remboursé",
                    index=Int64Index([2], name="booking_id"),
                )

                # When
                query = get_booking_payment_status()

                # Then
                with ENGINE.connect() as connection:
                    booking_payment = pandas.read_sql(query,
                                                      connection,
                                                      index_col="booking_id")
                pandas.testing.assert_series_equal(
                    booking_payment["Remboursé"],
                    expected_booking_payment_status)