示例#1
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)
示例#2
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)
示例#3
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_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 occupation_event.event_type == 'seat-occupied'
        assert occupation_event.data == {
            'seat_id': str(seat1.id),
            'initiator_id': str(self.owner.id),
        }

        # switch to another seat

        ticket_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 switch_event.event_type == 'seat-occupied'
        assert switch_event.data == {
            'previous_seat_id': str(seat1.id),
            'seat_id': str(seat2.id),
            'initiator_id': str(self.owner.id),
        }

        # release seat

        ticket_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 release_event.event_type == 'seat-released'
        assert release_event.data == {
            'initiator_id': str(self.owner.id),
        }
示例#4
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_service.occupy_seat(bundled_ticket.id, seat.id,
                                       self.owner.id)
示例#5
0
    def test_occupy_seat_with_invalid_id(self):
        invalid_seat_id = 'ffffffff-ffff-ffff-ffff-ffffffffffff'

        with raises(ValueError):
            ticket_service.occupy_seat(self.ticket.id, invalid_seat_id,
                                       self.owner.id)