def test_attendance_context_only_populated_with_desired_statuses(self):
     attendance = Attendance(user=self.user, occurrence=self.occurrence)
     try:
         signals.collect_validators.disconnect(
             CannotAttendFutureEventsValidator, sender=Attendance
         )
         for status in (Attendance.STATUS.booked, Attendance.STATUS.attended):
             attendance.status = status
             attendance.save()
             response = self.client.get(
                 reverse('occurrence-detail',
                         args=(self.event.slug, self.occurrence.pk)), follow=True
             )
             assert_equal(response.context['attendance'], attendance)
         for status in (Attendance.STATUS.inactive, Attendance.STATUS.cancelled):
             attendance.status = status
             attendance.save()
             response = self.client.get(reverse('occurrence-detail',
                 args=(self.event.slug, self.occurrence.pk)), follow=True
             )
             assert_not_equal(response.context['attendance'], attendance)
     finally:
         signals.collect_validators.connect(
             CannotAttendFutureEventsValidator, sender=Attendance
         )
 def test_only_one_active_attendance_record_for_user_occurrence(self):
     try:
         collect_validators.disconnect(
             CannotAttendFutureEventsValidator, sender=Attendance
         )
         att = Attendance(user=self.user, occurrence=self.occurrence)
         for status in [Attendance.STATUS.booked, Attendance.STATUS.attended]:
             att.status = att.STATUS.attended
             att.save()
             self.assertRaises(ValidationError, Attendance.objects.create,
                 user=self.user, occurrence=self.occurrence
             )
         for status in [Attendance.STATUS.inactive, Attendance.STATUS.cancelled]:
             att.status = status
             att.save()
             att2 = Attendance.objects.create(
                 user=self.user, occurrence=self.occurrence
             )
             att2.delete()
     finally:
         collect_validators.connect(
             CannotAttendFutureEventsValidator, sender=Attendance
         )