Example #1
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,
            )
Example #2
0
        def test_should_return_column_with_number_of_bookings_appearing_on_payment(
            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_booking(user_id=2,
                           stock_id=2,
                           id=5,
                           quantity=1,
                           token="IS02JE")
            create_payment(booking_id=4, id=1)
            create_payment_status(payment_id=1)

            expected_stocks_booking_information = pandas.Series(
                index=pandas.Index(data=[1, 2], name="stock_id"),
                data=[2, 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,
            )
        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_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_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)
            def test_should_return_booking_ranking(app):
                # Given
                create_user(id=1)
                create_user(id=2, email="*****@*****.**")
                create_deposit(id=1, user_id=1)
                create_deposit(id=2, user_id=2)
                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_product(id=3, product_type="ThingType.AUDIOVISUEL")
                create_offer(venue_id=1,
                             product_id=3,
                             id=3,
                             product_type="ThingType.AUDIOVISUEL")
                create_stock(offer_id=3, id=3)
                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=3,
                    token="ABC321",
                    is_used=True,
                    date_created="2020-05-11",
                )
                create_booking(
                    id=3,
                    user_id=1,
                    quantity=3,
                    amount=5,
                    stock_id=2,
                    token="FAM321",
                    is_cancelled=True,
                    date_created="2020-06-21",
                )
                create_booking(
                    id=4,
                    user_id=2,
                    quantity=1,
                    amount=5,
                    stock_id=3,
                    token="OLD321",
                    is_used=True,
                    date_created="2020-06-21",
                )
                create_booking(
                    id=5,
                    user_id=2,
                    quantity=1,
                    amount=5,
                    stock_id=2,
                    token="YOO321",
                    is_used=True,
                    date_created="2020-10-25",
                )
                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_ranking = pandas.Series(
                    data=[1, 1, 2, 1, 1],
                    name="Classement de la réservation dans la même catégorie",
                    index=Int64Index([1, 2, 3, 4, 5], name="booking_id"),
                )

                # When
                query = get_booking_ranking_in_category()

                # Then
                with ENGINE.connect() as connection:
                    booking_ranking = pandas.read_sql(query,
                                                      connection,
                                                      index_col="booking_id")
                pandas.testing.assert_series_equal(
                    booking_ranking[
                        "Classement de la réservation dans la même catégorie"],
                    expected_booking_ranking,
                )