Exemple #1
0
 def put(self, request, pk):
     reservation = get_object_or_404(Reservation.objects.all(), pk=pk)
     serializer = ReservationSerializer(reservation, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200)
     return Response(status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
	def post(self, request, pk):
		request.data['event']=pk
		serializer=ReservationSerializer(data=request.data)
		if serializer.is_valid():
			serializer.save()
			return Response(serializer.data, status=status.HTTP_201_CREATED)
		return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)	
Exemple #3
0
 def post(self, request, pk):
     request.data['event'] = pk
     serializer = ReservationSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 def test_invalid_reservation_not_enough_vacancies(self):
     test_data = self.valid_reservation_json_data
     test_data['paid_amount'] = 25500.0
     test_data['attendee_number'] = 51
     serializer = ReservationSerializer(data=test_data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(set(serializer.errors['non_field_errors']),
                      set(['Not enough vacancies for the reservation']))
 def test_invalid_reservation_paid_amount_serializer(self):
     test_data = self.valid_reservation_json_data
     test_data[
         'paid_amount'] = 1234.0  # not valid since it should be 2*500=1000
     serializer = ReservationSerializer(data=test_data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(set(serializer.errors['non_field_errors']),
                      set(['The paid amount is not valid']))
 def test_reservation_serializer(self):
     serializer = ReservationSerializer(
         data=self.valid_reservation_json_data)
     self.assertTrue(serializer.is_valid())
     reservation_fields = [
         'attendee_number', 'observations', 'paid_amount',
         'event_occurrence'
     ]
     self.assertEqual(set(serializer.validated_data.keys()),
                      set(reservation_fields))
 def test_invalid_reservation_old_occurrence(self):
     occurrence = EventOccurrence.objects.create(
         start='2018-10-31T20:00:00',
         end='2018-10-31T23:00:00',
         vacancies=50,
         event=self.event)
     test_data = self.valid_reservation_json_data
     test_data['event_occurrence'] = occurrence.id
     serializer = ReservationSerializer(data=test_data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(set(serializer.errors['non_field_errors']),
                      set(['The date is no longer available']))
 def test_invalid_reservation_event_cancelled(self):
     cancelled_event = Event.objects.create(
         name='Event Cancelled',
         description='Shouldnt be able to make a reservation',
         cancelled='2019-9-15T20:00:00',
         winery=self.winery,
         price=500.0,
     )
     occurrence = EventOccurrence.objects.create(
         start='2030-10-31T20:00:00',
         end='2030-10-31T23:00:00',
         vacancies=50,
         event=cancelled_event)
     test_data = self.valid_reservation_json_data
     test_data['event_occurrence'] = occurrence.id
     serializer = ReservationSerializer(data=test_data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(set(serializer.errors['non_field_errors']),
                      set(['The event is cancelled']))
Exemple #9
0
 def post(self, request):
     serializer = ReservationSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(status=status.HTTP_201_CREATED)
     return Response(status=status.HTTP_400_BAD_REQUEST)
 def test_invalid_reservation_serializer(self):
     serializer = ReservationSerializer(data=self.invalid_reservation_data)
     self.assertFalse(serializer.is_valid())
     self.assertEqual(set(serializer.errors), self.required_fields)