コード例 #1
0
    def test_occupy_and_release_seat(self):
        area = self.create_area('main', 'Main Hall')
        seat1 = seat_service.create_seat(area, 0, 1, self.category_id)
        seat2 = seat_service.create_seat(area, 0, 2, self.category_id)

        assert self.ticket.occupied_seat_id is None

        # occupy seat

        ticket_seat_management_service \
            .occupy_seat(self.ticket.id, seat1.id, self.owner.id)
        assert self.ticket.occupied_seat_id == seat1.id

        events_after_occupation = event_service.get_events_for_ticket(
            self.ticket.id)
        assert len(events_after_occupation) == 1

        occupation_event = events_after_occupation[0]
        assert_event(occupation_event, 'seat-occupied', {
            'seat_id': str(seat1.id),
            'initiator_id': str(self.owner.id),
        })

        # switch to another seat

        ticket_seat_management_service \
            .occupy_seat(self.ticket.id, seat2.id, self.owner.id)
        assert self.ticket.occupied_seat_id == seat2.id

        events_after_switch = event_service.get_events_for_ticket(
            self.ticket.id)
        assert len(events_after_switch) == 2

        switch_event = events_after_switch[1]
        assert_event(
            switch_event, 'seat-occupied', {
                'previous_seat_id': str(seat1.id),
                'seat_id': str(seat2.id),
                'initiator_id': str(self.owner.id),
            })

        # release seat

        ticket_seat_management_service \
            .release_seat(self.ticket.id, self.owner.id)
        assert self.ticket.occupied_seat_id is None

        events_after_release = event_service.get_events_for_ticket(
            self.ticket.id)
        assert len(events_after_release) == 3

        release_event = events_after_release[2]
        assert_event(release_event, 'seat-released', {
            'seat_id': str(seat2.id),
            'initiator_id': str(self.owner.id),
        })
コード例 #2
0
    def test_revoke_ticket_with_seat(self):
        area = seating_area_service.create_area(self.party.id, 'main', 'Main')
        seat = seat_service.create_seat(area, 0, 0, self.category_id)

        ticket = ticket_creation_service \
            .create_ticket(self.category_id, self.owner_id)

        ticket_seat_management_service \
            .occupy_seat(ticket.id, seat.id, self.owner_id)

        assert ticket.occupied_seat_id == seat.id

        events_before = event_service.get_events_for_ticket(ticket.id)
        event_types_before = {event.event_type for event in events_before}
        assert 'seat-released' not in event_types_before

        # -------------------------------- #

        ticket_revocation_service.revoke_ticket(ticket.id, self.admin_id)

        # -------------------------------- #

        assert ticket.occupied_seat_id is None

        events_after = event_service.get_events_for_ticket(ticket.id)
        event_types_after = {event.event_type for event in events_after}
        assert 'seat-released' in event_types_after
コード例 #3
0
ファイル: test_revocation.py プロジェクト: leathe/byceps
    def test_revoke_tickets_with_seats(self):
        area = seating_area_service.create_area(self.party.id, 'main', 'Main')

        tickets = ticket_creation_service.create_tickets(
            self.category_id, self.owner_id, 2)

        ticket_ids = {ticket.id for ticket in tickets}

        for ticket in tickets:
            seat = seat_service.create_seat(area, 0, 0, self.category_id)

            ticket_seat_management_service.occupy_seat(ticket.id, seat.id,
                                                       self.owner_id)

            assert ticket.occupied_seat_id == seat.id

        # -------------------------------- #

        ticket_revocation_service.revoke_tickets(ticket_ids, self.admin_id)

        # -------------------------------- #

        for ticket in tickets:
            assert ticket.occupied_seat_id is None

            events_after = event_service.get_events_for_ticket(ticket.id)
            event_types_after = {event.event_type for event in events_after}
            assert 'seat-released' in event_types_after
コード例 #4
0
    def test_occupy_seat_with_wrong_category(self):
        other_category_id = self.create_category('Economy').id

        area = self.create_area('main', 'Main Hall')
        seat = seat_service.create_seat(area, 0, 0, other_category_id)

        assert self.ticket.category_id != other_category_id

        with raises(TicketCategoryMismatch):
            ticket_service.occupy_seat(self.ticket.id, seat.id, self.owner.id)
コード例 #5
0
    def test_occupy_and_release_seat(self):
        area = self.create_area('main', 'Main Hall')
        seat = seat_service.create_seat(area, 0, 0, self.category)

        self.assertIsNone(self.ticket.occupied_seat_id)

        ticket_service.occupy_seat(self.ticket.id, seat.id)
        self.assertEqual(self.ticket.occupied_seat_id, seat.id)

        ticket_service.release_seat(self.ticket.id)
        self.assertIsNone(self.ticket.occupied_seat_id)
コード例 #6
0
    def test_occupy_seat_with_bundled_ticket(self):
        ticket_quantity = 1
        ticket_bundle = ticket_bundle_service \
            .create_bundle(self.category_id, ticket_quantity, self.owner.id)

        bundled_ticket = ticket_bundle.tickets[0]

        area = self.create_area('main', 'Main Hall')
        seat = seat_service.create_seat(area, 0, 0, self.category_id)

        with raises(SeatChangeDeniedForBundledTicket):
            ticket_seat_management_service \
                .occupy_seat(bundled_ticket.id, seat.id, self.owner.id)