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)
示例#3
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,
            )
示例#4
0
        def test_should_return_None_if_the_offerer_has_no_booking(self):
            # Given
            create_offerer()

            # 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"] is None
示例#5
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_should_return_postal_code_related_to_existing_offerers(
                self, app):
            # Given
            create_offerer(id=1, postal_code="75003")
            create_offerer(id=2, postal_code="97459", siren="123456788")
            expected_postal_code_dataframe = pandas.DataFrame(data={
                "id": [1, 2],
                "postalCode": ["75003", "97459"]
            })

            # When
            postal_code_dataframe = get_postal_code_dataframe(ENGINE)

            # Then
            pandas.testing.assert_frame_equal(postal_code_dataframe,
                                              expected_postal_code_dataframe)
示例#7
0
        def test_should_return_the_number_of_offers(self):
            # Given
            create_offerer(id=1)
            create_venue(offerer_id=1, id=1)
            create_product(id=1)
            create_product(id=2)
            create_offer(venue_id=1, product_id=1, id=1)
            create_offer(venue_id=1, product_id=2, id=2)

            # When
            query = _get_number_of_offers_query()

            # Then
            with ENGINE.connect() as connection:
                number_of_offers = pandas.read_sql(query,
                                                   connection,
                                                   index_col="offerer_id")
            assert number_of_offers.loc[1, "Nombre d’offres"] == 2
        def test_should_return_how_many_stocks(self):
            # Given
            create_offerer(id=10)
            create_venue(id=15, offerer_id=10)
            create_product(id=1)
            create_offer(id=30, venue_id=15, product_id=1)
            create_stock(id=20, offer_id=30)
            create_stock(id=21, offer_id=30)

            expected_offer_stock = pandas.Series(index=pandas.Index(
                data=[30], name="offer_id"),
                                                 data=[20],
                                                 name="Stock")
            # When
            query = _get_offer_info_with_quantity()
            # Then
            with ENGINE.connect() as connection:
                offer_stock = pandas.read_sql(query,
                                              connection,
                                              index_col="offer_id")
            pandas.testing.assert_series_equal(offer_stock["Stock"],
                                               expected_offer_stock)
        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,
            )
示例#11
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)
        def test_should_return_siren_related_to_existing_offerers(self, app):
            # Given
            create_offerer(id=1, siren="345678123")
            create_offerer(id=2, siren=None)
            create_offerer(id=3, siren="123456789")
            expected_siren_dataframe = pandas.DataFrame(data={
                "id": [1, 3],
                "siren": ["345678123", "123456789"]
            })

            # When
            siren_dataframe = get_siren_dataframe(ENGINE)

            # Then
            pandas.testing.assert_frame_equal(siren_dataframe,
                                              expected_siren_dataframe)