def test_should_return_booking_recap_history_with_only_booking_date_when_just_booked(self, app: fixture):
        # Given
        booking_date = datetime(2020, 1, 1, 10, 0, 0)
        bookings_recap = [
            create_domain_thing_booking_recap(
                offer_name="Martine a la playa",
                offer_isbn="987654345678",
                beneficiary_firstname="Hari",
                beneficiary_lastname="Seldon",
                beneficiary_email="*****@*****.**",
                booking_date=booking_date,
                booking_token="LUNE",
            )
        ]
        bookings_recap_paginated_response = BookingsRecapPaginated(
            bookings_recap=list(bookings_recap), page=0, pages=1, total=2
        )

        # When
        results = serialize_bookings_recap_paginated(bookings_recap_paginated_response)

        # Then
        expected_booking_recap_history = [
            {
                "status": "booked",
                "date": "2020-01-01T10:00:00",
            },
        ]
        assert results["bookings_recap"][0]["booking_status_history"] == expected_booking_recap_history
Esempio n. 2
0
    def test_should_return_json_with_offer_isbn_additional_parameter_for_thing_stock(self, app: fixture):
        # Given
        booking_date = datetime(2020, 1, 1, 10, 0, 0)
        thing_booking_recap = create_domain_booking_recap(
            offer_identifier=1,
            offer_name="Martine a la playa",
            offer_isbn="987654345678",
            offerer_name="La maman de Martine",
            beneficiary_firstname="Hari",
            beneficiary_lastname="Seldon",
            beneficiary_email="*****@*****.**",
            booking_date=booking_date,
            booking_token="LUNE",
        )
        bookings_recap = [thing_booking_recap]
        bookings_recap_paginated_response = BookingsRecapPaginated(
            bookings_recap=list(bookings_recap), page=0, pages=1, total=2
        )

        # When
        results = serialize_bookings_recap_paginated(bookings_recap_paginated_response)

        # Then
        expected_response = [
            {
                "stock": {
                    "event_beginning_datetime": None,
                    "offer_name": "Martine a la playa",
                    "offer_identifier": humanize(thing_booking_recap.offer_identifier),
                    "offer_isbn": "987654345678",
                    "offer_is_educational": False,
                },
                "beneficiary": {
                    "lastname": "Seldon",
                    "firstname": "Hari",
                    "email": "*****@*****.**",
                    "phonenumber": "0100000000",
                },
                "booking_date": format_into_timezoned_date(booking_date),
                "booking_token": None,
                "booking_status": "booked",
                "booking_is_duo": False,
                "booking_amount": 0,
                "booking_status_history": [
                    {
                        "status": "booked",
                        "date": "2020-01-01T10:00:00",
                    },
                ],
                "offerer": {"name": "La maman de Martine"},
                "venue": {"identifier": "AE", "name": "Librairie Kléber", "is_virtual": False},
            },
        ]
        assert results["bookings_recap"] == expected_response
        assert results["page"] == 0
        assert results["pages"] == 1
        assert results["total"] == 2
    def test_should_return_json_with_event_date_additional_parameter_for_event_stock(self, app: fixture):
        # Given
        booking_date = datetime(2020, 1, 1, 10, 0, 0)
        day_after_booking_date = booking_date + timedelta(days=1)
        event_booking_recap = create_domain_event_booking_recap(
            offer_name="Cirque du soleil",
            offerer_name="Fondation des cirques de France",
            beneficiary_firstname="Hari",
            beneficiary_lastname="Seldon",
            beneficiary_email="*****@*****.**",
            booking_date=booking_date,
            booking_token="SOLEIL",
            event_beginning_datetime=day_after_booking_date,
        )
        bookings_recap = [event_booking_recap]
        bookings_recap_paginated_response = BookingsRecapPaginated(
            bookings_recap=list(bookings_recap), page=0, pages=1, total=2
        )

        # When
        results = serialize_bookings_recap_paginated(bookings_recap_paginated_response)

        # Then
        expected_response = [
            {
                "stock": {
                    "type": "event",
                    "offer_name": "Cirque du soleil",
                    "offer_identifier": humanize(event_booking_recap.offer_identifier),
                    "event_beginning_datetime": format_into_timezoned_date(day_after_booking_date),
                },
                "beneficiary": {
                    "lastname": "Seldon",
                    "firstname": "Hari",
                    "email": "*****@*****.**",
                },
                "booking_date": format_into_timezoned_date(booking_date),
                "booking_token": "SOLEIL",
                "booking_status": "booked",
                "booking_is_duo": False,
                "booking_status_history": [
                    {
                        "status": "booked",
                        "date": "2020-01-01T10:00:00",
                    },
                ],
                "booking_amount": 0,
                "offerer": {"name": "Fondation des cirques de France"},
                "venue": {"identifier": "AE", "name": "Librairie Kléber", "is_virtual": False},
            },
        ]
        assert results["bookings_recap"] == expected_response
        assert results["page"] == 0
        assert results["pages"] == 1
        assert results["total"] == 2
Esempio n. 4
0
def get_all_bookings():
    page = request.args.get("page", 1)
    check_page_format_is_number(page)

    check_is_authorized_to_access_bookings_recap(current_user)

    # FIXME: rewrite this route. The repository function should return
    # a bare SQLAlchemy query, and the route should handle the
    # serialization so that we can get rid of BookingsRecapPaginated
    # that is only used here.
    bookings_recap_paginated = booking_repository.find_by_pro_user_id(
        user_id=current_user.id, page=int(page))

    return serialize_bookings_recap_paginated(bookings_recap_paginated), 200
Esempio n. 5
0
    def test_should_return_booking_recap_history_with_empty_validated_date_when_booking_was_not_validated_but_reimbursed(
        self, app: fixture
    ):
        # Given
        booking_date = datetime(2020, 1, 1, 10, 0, 0)
        bookings_recap = [
            create_domain_booking_recap(
                offer_name="Martine a la playa",
                offer_isbn="987654345678",
                beneficiary_firstname="Hari",
                beneficiary_lastname="Seldon",
                beneficiary_email="*****@*****.**",
                booking_date=booking_date,
                booking_token="LUNE",
                booking_is_used=False,
                booking_is_reimbursed=True,
                payment_date=datetime(2020, 5, 3, 10, 0),
                date_used=None,
            )
        ]
        bookings_recap_paginated_response = BookingsRecapPaginated(
            bookings_recap=list(bookings_recap), page=0, pages=1, total=2
        )

        # When
        results = serialize_bookings_recap_paginated(bookings_recap_paginated_response)

        # Then
        expected_booking_recap_history = [
            {
                "status": "booked",
                "date": "2020-01-01T10:00:00",
            },
            {
                "status": "validated",
                "date": None,
            },
            {
                "status": "reimbursed",
                "date": "2020-05-03T10:00:00",
            },
        ]
        assert results["bookings_recap"][0]["booking_status_history"] == expected_booking_recap_history
    def test_should_return_json_with_all_parameters_for_thing_stock(self, app: fixture):
        # Given
        booking_date = datetime(2020, 1, 1, 10, 0, 0)
        thing_booking_recap = create_domain_thing_booking_recap(
            offer_identifier=1,
            offer_name="Fondation",
            offerer_name="Fondation de Caen",
            beneficiary_firstname="Hari",
            beneficiary_lastname="Seldon",
            beneficiary_email="*****@*****.**",
            booking_date=booking_date,
            booking_token="FOND",
            booking_is_used=False,
            booking_amount=18,
        )
        thing_booking_recap_2 = create_domain_thing_booking_recap(
            offer_identifier=2,
            offer_name="Fondation",
            offerer_name="Fondation de Paris",
            beneficiary_firstname="Golan",
            beneficiary_lastname="Trevize",
            beneficiary_email="*****@*****.**",
            booking_date=booking_date,
            booking_token="FOND",
            booking_is_duo=True,
        )
        bookings_recap = [thing_booking_recap, thing_booking_recap_2]
        bookings_recap_paginated_response = BookingsRecapPaginated(
            bookings_recap=list(bookings_recap), page=0, pages=1, total=2
        )

        # When
        result = serialize_bookings_recap_paginated(bookings_recap_paginated_response)

        # Then
        expected_bookings_recap = [
            {
                "stock": {
                    "type": "thing",
                    "offer_name": "Fondation",
                    "offer_identifier": humanize(thing_booking_recap.offer_identifier),
                },
                "beneficiary": {
                    "lastname": "Seldon",
                    "firstname": "Hari",
                    "email": "*****@*****.**",
                },
                "booking_date": format_into_timezoned_date(booking_date),
                "booking_token": None,
                "booking_status": "booked",
                "booking_is_duo": False,
                "booking_status_history": [
                    {
                        "status": "booked",
                        "date": "2020-01-01T10:00:00",
                    },
                ],
                "booking_amount": 18,
                "offerer": {"name": "Fondation de Caen"},
                "venue": {"identifier": "AE", "name": "Librairie Kléber", "is_virtual": False},
            },
            {
                "stock": {
                    "type": "thing",
                    "offer_name": "Fondation",
                    "offer_identifier": humanize(thing_booking_recap_2.offer_identifier),
                },
                "beneficiary": {
                    "lastname": "Trevize",
                    "firstname": "Golan",
                    "email": "*****@*****.**",
                },
                "booking_date": format_into_timezoned_date(booking_date),
                "booking_token": None,
                "booking_status": "booked",
                "booking_is_duo": True,
                "booking_status_history": [
                    {
                        "status": "booked",
                        "date": "2020-01-01T10:00:00",
                    },
                ],
                "booking_amount": 0,
                "offerer": {"name": "Fondation de Paris"},
                "venue": {"identifier": "AE", "name": "Librairie Kléber", "is_virtual": False},
            },
        ]
        assert result["bookings_recap"] == expected_bookings_recap
        assert result["page"] == 0
        assert result["pages"] == 1
        assert result["total"] == 2