def test_unpersisted_instance_saved_for_valid_forms(self):
     attendance = Attendance(user=self.user, occurrence=self.occurrence)
     assert not attendance.pk
     form = AttendanceForm(instance=attendance, data={})
     assert form.is_valid()
     attendance = form.save()
     assert attendance.pk
 def test_clean_method_sets_instance_cancelled_when_status_is_booked(self):
     attendance = Attendance.objects.create(
         user=self.user,
         occurrence=self.occurrence,
     )
     form = AttendanceForm(instance=attendance, data={})
     assert form.instance.status == Attendance.STATUS.booked
     assert form.is_valid()
     assert form.instance.status == Attendance.STATUS.cancelled
 def test_clean_method_performs_noop_if_status_attended(self):
     try:
         signals.collect_validators.disconnect(
             CannotAttendFutureEventsValidator, sender=Attendance
         )
         attendance = Attendance.objects.create(
             user=self.user,
             occurrence=self.occurrence,
             status=Attendance.STATUS.attended
         )
         form = AttendanceForm(instance=attendance, data={})
         assert form.is_valid()
         form.save()
         assert form.instance.status == Attendance.STATUS.attended
     finally:
         signals.collect_validators.connect(
             CannotAttendFutureEventsValidator, sender=Attendance
         )