Ejemplo n.º 1
0
    def test_student_skips_a_service_but_multiplier_stays_the_same_in_other_services(
            self):

        # Day 1: add attendance for sunday school and for bible study
        AttendanceService().add_attendance_by_card(self.card1,
                                                   for_bible_study=True)
        AttendanceService().add_attendance_by_card(self.card1,
                                                   for_sunday_school=True)

        # Day 2: The person skipped sunday school
        self.func_with_different_date(
            1, lambda: DayService().add_attendance_day(for_sunday_school=True))
        self.func_with_different_date(
            1, lambda: AttendanceService().add_attendance_by_card(
                self.card1, for_bible_study=True))

        # Day 3: Person came for both services
        self.func_with_different_date(
            2, lambda: AttendanceService().add_attendance_by_card(
                self.card1, for_sunday_school=True))
        self.func_with_different_date(
            2, lambda: AttendanceService().add_attendance_by_card(
                self.card1, for_bible_study=True))

        multiplier = MultiplierSelector().get_multiplier(self.card1.holder)
        self.assertEqual(multiplier.sunday_school, 1)
        self.assertEqual(multiplier.bible_study, 3)
Ejemplo n.º 2
0
 def test_student_has_same_multiplier_when_being_added_twice_for_same_day(
         self):
     AttendanceService().add_attendance_by_card(self.card1)
     with self.assertRaises(IntegrityError):
         AttendanceService().add_attendance_by_card(self.card1)
         multiplier = MultiplierSelector(
         ).get_multiplier_for_specific_service_value(self.card1.holder)
         self.assertEqual(multiplier, 1)
Ejemplo n.º 3
0
 def test_multiplier_adds_bonus_for_different_services_independently(self):
     for i in range(1, 4):
         self.func_with_different_date(
             i, lambda: AttendanceService().add_attendance_by_card(
                 self.card1, for_sunday_school=True))
     self.func_with_different_date(
         1, lambda: AttendanceService().add_attendance_by_card(
             self.card1, for_bible_study=True))
     # 3 weeks for sunday school, 1 week for bible study and NOT monthly bonus for sunday school
     bonus_value = BonusSelector().get_weekly_bonus() * 4
     self.assertEqual(bonus_value, self.card1.balance)
Ejemplo n.º 4
0
    def test_adding_attendance_for_student_increases_their_multiplier(self):
        AttendanceService().add_attendance_by_card(card=self.card1,
                                                   for_sunday_school=True)
        AttendanceService().add_attendance_by_card(card=self.card1,
                                                   for_bible_study=True)
        AttendanceService().add_attendance_by_card(card=self.card1)

        multiplier = MultiplierSelector().get_multiplier(
            student=self.card1.holder)
        self.assertEqual(multiplier.sunday_school, 1)
        self.assertEqual(multiplier.bible_study, 1)
        self.assertEqual(multiplier.summer_club, 1)
Ejemplo n.º 5
0
def name_attendance_sunday_school(request):

    if not request.user.is_authenticated:
        return redirect('config:login')
    if request.user.username != 'admin':
        return HttpResponse('Unauthorized', status=401)

    err, student = '', ''
    full_name = request.POST['full_name']
    student_names = StudentSelector().get_all_student_names()

    try:
        student = StudentSelector.get_student_by_full_name(full_name)
        AttendanceService().add_attendance_by_student(student,
                                                      for_sunday_school=True)
    except ObjectDoesNotExist:
        err = 'Name does not exist.'
    except IntegrityError:
        err = f'{str(student)} has already been recorded.'

    context = {
        'err':
        err,
        'student_names':
        student_names,
        'attendance_count':
        AttendanceSelector.get_attendance_count_by_day(for_sunday_school=True),
    }
    return render(request, 'attendance/sunday_school.html', context)
Ejemplo n.º 6
0
def card_attendance_summer_club(request):

    if not request.user.is_authenticated:
        return redirect('config:login')
    if request.user.username != 'admin':
        return HttpResponse('Unauthorized', status=401)

    err, card = '', ''
    card_number = request.POST['card_number']
    student_names = StudentSelector().get_all_student_names()

    try:
        card = CardSelector().get_card_by_number(card_number)
        AttendanceService().add_attendance_by_card(card=card)
    except ObjectDoesNotExist:
        err = 'Card does not exist.'
    except IntegrityError:
        err = f'{str(card.holder)} has already been recorded.'

    context = {
        'err': err,
        'student_names': student_names,
        'attendance_count': AttendanceSelector.get_attendance_count_by_day(),
    }
    return render(request, 'attendance/summer_club.html', context)
Ejemplo n.º 7
0
    def test_bonus_added_correctly_for_monthly_and_quarterly_multiplier(self):
        # Pass one month
        for i in range(1, 5):
            self.func_with_different_date(
                i, lambda: AttendanceService().add_attendance_by_card(
                    self.card1, for_sunday_school=True))
        bonus = BonusSelector().get_bonus_values()
        monthly_value = bonus.WEEK * 3 + bonus.MONTH
        self.assertEqual(monthly_value, self.card1.balance)

        # Pass two more months for the quarter
        for i in range(5, 13):
            self.func_with_different_date(
                i, lambda: AttendanceService().add_attendance_by_card(
                    self.card1, for_sunday_school=True))
        quarter_value = bonus.WEEK * 9 + bonus.MONTH * 2 + bonus.QUARTER * 1
        self.assertEqual(quarter_value, self.card1.balance)
Ejemplo n.º 8
0
    def test_student_loses_multiplier_bonus_after_skipping_a_day(self):
        # Day 1: increment multiplier
        add_attendance = lambda card: AttendanceService(
        ).add_attendance_by_card(card, for_sunday_school=True)
        add_attendance(self.card1)

        # Day 2: no attendance
        self.func_with_different_date(
            1, lambda: DayService().add_attendance_day(for_sunday_school=True))

        # Day 3: consecutive attendance should equal 1
        self.func_with_different_date(
            2, lambda: AttendanceService().add_attendance_by_card(
                self.card1, for_sunday_school=True))

        multiplier = MultiplierSelector().get_multiplier(self.card1.holder)
        self.assertEqual(multiplier.sunday_school, 1)
Ejemplo n.º 9
0
 def test_money_is_added_as_bonus_for_attendance_with_card(self):
     AttendanceService().add_attendance_by_card(self.card1,
                                                for_sunday_school=True)
     bonus = BonusSelector().get_weekly_bonus()
     self.assertEqual(self.card1.balance, bonus)
Ejemplo n.º 10
0
 def test_adding_same_student_to_attendance_returns_integrity_error(self):
     AttendanceService().add_attendance_by_card(card=self.card1,
                                                for_sunday_school=True)
     with self.assertRaises(IntegrityError):
         AttendanceService().add_attendance_by_card(card=self.card1,
                                                    for_sunday_school=True)
Ejemplo n.º 11
0
    def test_when_a_student_is_added_by_name_multiplier_is_incremented(self):
        AttendanceService().add_attendance_by_student(self.card1.holder,
                                                      for_sunday_school=True)
        multiplier = MultiplierSelector().get_multiplier(self.card1.holder)

        self.assertEqual(multiplier.sunday_school, 1)
Ejemplo n.º 12
0
 def test_transaction_recorded_when_attendance_money_is_added(self):
     AttendanceService().add_attendance_by_card(self.card1)
     self.assertEqual(self.card1.transactions.count(), 1)
Ejemplo n.º 13
0
 def test_no_money_is_added_when_student_has_attendance_by_name(self):
     AttendanceService().add_attendance_by_student(self.card1.holder,
                                                   for_sunday_school=True)
     self.assertEqual(self.card1.balance, 0)