Exemple #1
0
    def test_serializer_updates_if_update_data_has_the_same_number_of_guests(
        self, ):
        room = MeetingRoom.objects.create(title="Games room")
        john = User.objects.create(username="******", password="******")
        peter = User.objects.create(username="******", password="******")
        zigmas = User.objects.create(username="******", password="******")
        reservation = Reservation.objects.create(
            title="Another foosball break",
            from_date=self.start,
            to_date=self.end,
            room=room,
            creator=john,
        )
        Invitation.objects.create(reservation=reservation, invitee=peter)
        new_invitation_data = [{"invitee": zigmas}]

        serializer = ReservationSerializer(instance=reservation)
        serializer.update_invitation_data(new_invitation_data)

        updated_invitation_data = reservation.guests.all()
        new_invitees = [
            invitation.invitee for invitation in updated_invitation_data
        ]
        self.assertEqual(len(updated_invitation_data), 1)
        self.assertEqual(new_invitees[0].username, "zigmas")
Exemple #2
0
    def test_serializer_updates_if_update_data_has_more_guests(self):
        room = MeetingRoom.objects.create(title="Games room")
        john = User.objects.create(username="******", password="******")
        peter = User.objects.create(username="******", password="******")
        zigmas = User.objects.create(username="******", password="******")
        reservation = Reservation.objects.create(
            title="Another foosball break",
            from_date=self.start,
            to_date=self.end,
            room=room,
            creator=john,
        )

        new_invitation_data = [{"invitee": zigmas}, {"invitee": peter}]
        serializer = ReservationSerializer(instance=reservation)
        serializer.update_invitation_data(new_invitation_data)

        updated_invitation_data = reservation.guests.all()
        self.assertEqual(len(updated_invitation_data), 2)