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
    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_thing_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": {
                    "type": "book",
                    "offer_name": "Martine a la playa",
                    "offer_identifier": humanize(thing_booking_recap.offer_identifier),
                    "offer_isbn": "987654345678",
                },
                "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_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_cancelled_status_when_booking_is_cancelled_and_used(self):
                # Given
                booking_recap = create_domain_thing_booking_recap(
                    booking_is_used=True, booking_is_cancelled=True, booking_is_reimbursed=False
                )

                # When
                booking_recap_status = booking_recap.booking_status

                # Then
                assert booking_recap_status == BookingRecapStatus.cancelled
        def test_should_return_token_when_offer_is_thing_and_booking_is_used_and_cancelled(self):
            # Given
            booking_recap = create_domain_thing_booking_recap(
                booking_token="ABCDE", booking_is_used=True, booking_is_cancelled=True
            )

            # When
            booking_recap_token = booking_recap.booking_token

            # Then
            assert booking_recap_token == "ABCDE"
Esempio n. 5
0
        def test_should_return_token_when_offer_is_thing_and_booking_is_not_used_and_is_cancelled(
                self):
            # Given
            booking_recap = create_domain_thing_booking_recap(
                booking_token="ABCDE",
                booking_is_used=False,
                booking_is_cancelled=True)

            # When
            booking_recap_token = booking_recap.booking_token

            # Then
            assert booking_recap_token == "ABCDE"  # pylint: disable=comparison-with-callable
            def test_should_return_booked_status_when_booking_is_not_cancelled_nor_used(self):
                # Given
                booking_recap = create_domain_thing_booking_recap(
                    booking_is_used=False,
                    booking_is_cancelled=False,
                    booking_is_confirmed=False,
                    booking_is_reimbursed=False,
                )

                # When
                booking_recap_status = booking_recap.booking_status

                # Then
                assert booking_recap_status == BookingRecapStatus.booked
        def test_should_return_booking_recap_history(self):
            # Given
            booking_recap = create_domain_thing_booking_recap(
                booking_token="ABCDE",
                booking_is_used=True,
                booking_is_cancelled=False,
                booking_amount=12,
                booking_date=datetime(2020, 1, 4),
            )

            # When
            booking_recap_history = booking_recap.booking_status_history

            # Then
            assert isinstance(booking_recap_history, BookingRecapHistory)
            assert booking_recap_history.booking_date == datetime(2020, 1, 4)
        def test_should_return_booking_recap_history_with_payment(self):
            # Given
            booking_recap = create_domain_thing_booking_recap(
                booking_token="ABCDE",
                booking_is_used=True,
                booking_is_cancelled=False,
                booking_amount=12,
                booking_date=datetime(2020, 1, 4),
                payment_date=datetime(2020, 1, 6),
                date_used=datetime(2020, 1, 5),
                booking_is_reimbursed=True,
            )

            # When
            booking_recap_history = booking_recap.booking_status_history

            # Then
            assert isinstance(booking_recap_history, BookingRecapReimbursedHistory)
            assert booking_recap_history.booking_date == datetime(2020, 1, 4)
            assert booking_recap_history.payment_date == datetime(2020, 1, 6)
            assert booking_recap_history.date_used == datetime(2020, 1, 5)
    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