Example #1
0
    def test_grant_reward_points(self):
        """
            submits several requests that trigger the reward point granting and checks that the reward point
            granting works as expected for the different requests.
        """
        user = UserProfile.objects.get(pk=5)
        reward_points_before_end = reward_points_of_user(user)
        response = self.app.get(reverse("student:vote", args=[9]),
                                user="******")

        form = lastform(response)
        for key, value in form.fields.items():
            if key is not None and "question" in key:
                form.set(key, 6)

        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))

        # semester is not activated --> number of reward points should not increase
        self.assertEqual(reward_points_before_end, reward_points_of_user(user))

        # reset course for another try
        course = Course.objects.get(pk=9)
        course.voters = []
        # activate semester
        activation = SemesterActivation.objects.get(semester=course.semester)
        activation.is_active = True
        activation.save()
        # create a new course
        new_course = mommy.make(Course, semester=course.semester)
        new_course.save()
        new_course.participants.add(user)
        new_course.save()
        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))

        # user also has other courses this semester --> number of reward points should not increase
        self.assertEqual(reward_points_before_end, reward_points_of_user(user))

        course.voters = []
        course.save()
        new_course.participants.remove(user)
        new_course.save()

        # last course of user so he may get reward points
        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))
        # if this test fails because of this assertion check that the user is allowed to receive reward points!
        self.assertEqual(
            reward_points_before_end + settings.REWARD_POINTS_PER_SEMESTER,
            reward_points_of_user(user))

        # test behaviour if user already got reward points
        course.voters = []
        course.save()
        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))
        self.assertEqual(
            reward_points_before_end + settings.REWARD_POINTS_PER_SEMESTER,
            reward_points_of_user(user))
Example #2
0
    def test_grant_reward_points(self):
        """
            submits several requests that trigger the reward point granting and checks that the reward point
            granting works as expected for the different requests.
        """
        user = UserProfile.objects.get(pk=5)
        reward_points_before_end = reward_points_of_user(user)
        response = self.app.get(reverse("student:vote", args=[9]), user="******")

        form = response.forms["student-vote-form"]
        for key, value in form.fields.items():
            if key is not None and "question" in key:
                form.set(key, 6)

        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))

        # semester is not activated --> number of reward points should not increase
        self.assertEqual(reward_points_before_end, reward_points_of_user(user))

        # reset course for another try
        course = Course.objects.get(pk=9)
        course.voters = []
        # activate semester
        activation = SemesterActivation.objects.get(semester=course.semester)
        activation.is_active = True
        activation.save()
        # create a new course
        new_course = mommy.make(Course, semester=course.semester)
        new_course.save()
        new_course.participants.add(user)
        new_course.save()
        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))

        # user also has other courses this semester --> number of reward points should not increase
        self.assertEqual(reward_points_before_end, reward_points_of_user(user))

        course.voters = []
        course.save()
        new_course.participants.remove(user)
        new_course.save()

        # last course of user so he may get reward points
        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))
        # if this test fails because of this assertion check that the user is allowed to receive reward points!
        self.assertEqual(reward_points_before_end + settings.REWARD_POINTS_PER_SEMESTER, reward_points_of_user(user))

        # test behaviour if user already got reward points
        course.voters = []
        course.save()
        response = form.submit()
        self.assertRedirects(response, reverse('student:index'))
        self.assertEqual(reward_points_before_end + settings.REWARD_POINTS_PER_SEMESTER, reward_points_of_user(user))
Example #3
0
def index(request):
    if request.method == 'POST':
        redemptions = {}
        for key, value in request.POST.items():
            if key.startswith('points-'):
                event_id = int(key.rpartition('-')[2])
                redemptions[event_id] = int(value)

        try:
            save_redemptions(request, redemptions)
            messages.success(request, _("You successfully redeemed your points."))
        except (NoPointsSelected, NotEnoughPoints) as error:
            messages.warning(request, error)

    total_points_available = reward_points_of_user(request.user)
    reward_point_grantings = RewardPointGranting.objects.filter(user_profile=request.user)
    reward_point_redemptions = RewardPointRedemption.objects.filter(user_profile=request.user)
    events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__gte=datetime.now())
    events = sorted(events, key=lambda event: event.date)

    reward_point_actions = []
    for granting in reward_point_grantings:
        reward_point_actions.append((granting.granting_time, _('Reward for') + ' ' + granting.semester.name, granting.value, ''))
    for redemption in reward_point_redemptions:
        reward_point_actions.append((redemption.redemption_time, redemption.event.name, '', redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    template_data = dict(
            reward_point_actions=reward_point_actions,
            total_points_available=total_points_available,
            events=events,
            point_selection=[x for x in range(0, total_points_available + 1)])
    return render(request, "rewards_index.html", template_data)
Example #4
0
 def test_semester_activated_not_all_courses(self):
     SemesterActivation.objects.create(semester=self.course.semester,
                                       is_active=True)
     mommy.make(Course,
                semester=self.course.semester,
                participants=[self.student])
     self.form.submit()
     self.assertEqual(1, reward_points_of_user(self.student))
Example #5
0
 def test_redeem_too_many_points(self):
     response = self.app.get(reverse('rewards:index'), user='******')
     form = response.forms['reward-redemption-form']
     form.set('points-1', 3)
     form.set('points-2', 3)
     response = form.submit()
     self.assertContains(response, "have enough reward points.")
     self.assertEqual(5, reward_points_of_user(self.student))
Example #6
0
 def test_redeem_too_many_points(self):
     response = self.app.get(reverse('rewards:index'), user='******')
     form = response.forms['reward-redemption-form']
     form.set('points-1', 3)
     form.set('points-2', 3)
     response = form.submit()
     self.assertContains(response, "have enough reward points.")
     self.assertEqual(5, reward_points_of_user(self.student))
Example #7
0
 def test_redeem_too_many_points(self):
     response = self.app.get(self.url, user=self.student)
     form = response.forms["reward-redemption-form"]
     form.set("points-1", 3)
     form.set("points-2", 3)
     response = form.submit()
     self.assertContains(response, "have enough reward points.")
     self.assertEqual(5, reward_points_of_user(self.student))
Example #8
0
 def test_redeem_all_points(self):
     response = self.app.get(self.url, user=self.student)
     form = response.forms["reward-redemption-form"]
     form.set(f"points-{self.event1.pk}", 2)
     form.set(f"points-{self.event2.pk}", 3)
     response = form.submit()
     self.assertContains(response, "You successfully redeemed your points.")
     self.assertEqual(0, reward_points_of_user(self.student))
Example #9
0
 def test_redeem_points_for_expired_event(self):
     """ Regression test for #846 """
     response = self.app.get(self.url, user=self.student)
     form = response.forms['reward-redemption-form']
     form.set('points-2', 1)
     RewardPointRedemptionEvent.objects.update(redeem_end_date=date.today() - timedelta(days=1))
     response = form.submit()
     self.assertContains(response, "event expired already.")
     self.assertEqual(5, reward_points_of_user(self.student))
Example #10
0
 def test_redeem_all_points(self):
     response = self.app.get(self.url, user='******')
     form = response.forms['reward-redemption-form']
     form.set('points-1', 2)
     form.set('points-2', 3)
     response = form.submit()
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "You successfully redeemed your points.")
     self.assertEqual(0, reward_points_of_user(self.student))
Example #11
0
 def test_redeem_too_many_points(self):
     response = self.app.get(self.url,
                             user="******")
     form = response.forms['reward-redemption-form']
     form.set('points-1', 3)
     form.set('points-2', 3)
     response = form.submit()
     self.assertContains(response, "have enough reward points.")
     self.assertEqual(5, reward_points_of_user(self.student))
Example #12
0
 def test_redeem_points_for_expired_event(self):
     """ Regression test for #846 """
     response = self.app.get(reverse('rewards:index'), user='******')
     form = response.forms['reward-redemption-form']
     form.set('points-2', 1)
     RewardPointRedemptionEvent.objects.update(redeem_end_date=date.today() - timedelta(days=1))
     response = form.submit()
     self.assertContains(response, "event expired already.")
     self.assertEqual(5, reward_points_of_user(self.student))
Example #13
0
 def test_redeem_too_many_points(self):
     mommy.make(RewardPointRedemptionEvent)
     response = self.app.get(reverse('rewards:index'), user='******')
     form = response.forms['reward-redemption-form']
     form.set('points-1', 3)
     form.set('points-2', 3)
     response = form.submit()
     self.assertIn(b"have enough reward points.", response.body)
     self.assertEqual(5, reward_points_of_user(self.student))
Example #14
0
 def test_already_got_points(self):
     SemesterActivation.objects.create(semester=self.course.semester,
                                       is_active=True)
     mommy.make(RewardPointGranting,
                user_profile=self.student,
                value=0,
                semester=self.course.semester)
     self.form.submit()
     self.assertEqual(0, reward_points_of_user(self.student))
Example #15
0
 def test_redeem_all_points(self):
     response = self.app.get(reverse('rewards:index'), user='******')
     form = response.forms['reward-redemption-form']
     form.set('points-1', 2)
     form.set('points-2', 3)
     response = form.submit()
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "You successfully redeemed your points.")
     self.assertEqual(0, reward_points_of_user(self.student))
Example #16
0
    def test_redeem_reward_points(self):
        """
            Submits a request that redeems all available reward points and checks that this works.
            Also checks that it is not possible to redeem more points than the user actually has.
        """
        response = self.app.get(reverse("rewards:index"), user="******")
        self.assertEqual(response.status_code, 200)

        user = UserProfile.objects.get(pk=5)
        form = response.forms["reward-redemption-form"]
        form.set("points-1", reward_points_of_user(user))
        response = form.submit()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "You successfully redeemed your points.")
        self.assertEqual(0, reward_points_of_user(user))

        form.set("points-1", 1)
        form.set("points-2", 3)
        response = form.submit()
        self.assertIn(b"have enough reward points.", response.body)
Example #17
0
    def test_redeem_reward_points(self):
        """
            Submits a request that redeems all available reward points and checks that this works.
            Also checks that it is not possible to redeem more points than the user actually has.
        """
        response = self.app.get(reverse("rewards:index"), user="******")
        self.assertEqual(response.status_code, 200)

        user = UserProfile.objects.get(pk=5)
        form = lastform(response)
        form.set("points-1", reward_points_of_user(user))
        response = form.submit()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "You successfully redeemed your points.")
        self.assertEqual(0, reward_points_of_user(user))

        form.set("points-1", 1)
        form.set("points-2", 3)
        response = form.submit()
        self.assertIn(b"have enough reward points.", response.body)
Example #18
0
 def test_already_got_grant_objects_but_points_missing(self):
     SemesterActivation.objects.create(
         semester=self.evaluation.course.semester, is_active=True)
     baker.make(RewardPointGranting,
                user_profile=self.student,
                value=0,
                semester=self.evaluation.course.semester)
     self.form.submit()
     self.assertEqual(3, reward_points_of_user(self.student))
     self.assertEqual(
         2,
         RewardPointGranting.objects.filter(
             user_profile=self.student,
             semester=self.evaluation.course.semester).count())
Example #19
0
 def test_already_got_enough_points(self):
     SemesterActivation.objects.create(
         semester=self.evaluation.course.semester, is_active=True)
     mommy.make(RewardPointGranting,
                user_profile=self.student,
                value=3,
                semester=self.evaluation.course.semester)
     self.form.submit()
     self.assertEqual(3, reward_points_of_user(self.student))
     self.assertEqual(
         1,
         RewardPointGranting.objects.filter(
             user_profile=self.student,
             semester=self.evaluation.course.semester).count())
Example #20
0
def index(request):
    if request.method == "POST":
        redemptions = {}
        try:
            for key, value in request.POST.items():
                if key.startswith("points-"):
                    event_id = int(key.rpartition("-")[2])
                    redemptions[event_id] = int(value)
        except ValueError as e:
            raise BadRequest from e

        try:
            save_redemptions(request, redemptions)
            messages.success(request,
                             _("You successfully redeemed your points."))
        except (NoPointsSelected, NotEnoughPoints,
                RedemptionEventExpired) as error:
            messages.warning(request, error)

    total_points_available = reward_points_of_user(request.user)
    reward_point_grantings = RewardPointGranting.objects.filter(
        user_profile=request.user)
    reward_point_redemptions = RewardPointRedemption.objects.filter(
        user_profile=request.user)
    events = RewardPointRedemptionEvent.objects.filter(
        redeem_end_date__gte=datetime.now()).order_by("date")

    reward_point_actions = []
    for granting in reward_point_grantings:
        reward_point_actions.append(
            (granting.granting_time,
             _("Reward for") + " " + granting.semester.name, granting.value,
             ""))
    for redemption in reward_point_redemptions:
        reward_point_actions.append(
            (redemption.redemption_time, redemption.event.name, "",
             redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    template_data = dict(
        reward_point_actions=reward_point_actions,
        total_points_available=total_points_available,
        events=events,
        point_selection=range(0, total_points_available + 1),
    )
    return render(request, "rewards_index.html", template_data)
Example #21
0
def index(request):
    if request.method == 'POST':
        redemptions = {}
        for key, value in request.POST.items():
            if (key.startswith('points-')):
                event_id = int(key.rpartition('-')[2])
                redemptions[event_id] = int(value)

        try:
            save_redemptions(request, redemptions)
            messages.success(request,
                             _("You successfully redeemed your points."))
        except (NoPointsSelected, NotEnoughPoints) as error:
            messages.warning(request, error)

    total_points_available = reward_points_of_user(request.user)
    reward_point_grantings = RewardPointGranting.objects.filter(
        user_profile=request.user)
    reward_point_redemptions = RewardPointRedemption.objects.filter(
        user_profile=request.user)
    events = RewardPointRedemptionEvent.objects.filter(
        redeem_end_date__gte=datetime.now())
    events = sorted(events, key=lambda event: event.date)

    reward_point_actions = []
    for granting in reward_point_grantings:
        reward_point_actions.append(
            (granting.granting_time,
             _('Reward for') + ' ' + granting.semester.name, granting.value,
             ''))
    for redemption in reward_point_redemptions:
        reward_point_actions.append(
            (redemption.redemption_time, redemption.event.name, '',
             redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    template_data = dict(
        reward_point_actions=reward_point_actions,
        total_points_available=total_points_available,
        events=events,
        point_selection=[x for x in range(0, total_points_available + 1)])
    return render(request, "rewards_index.html", template_data)
Example #22
0
File: views.py Project: Nef10/EvaP
def index(request):
    if request.method == 'POST':
        redemptions = {}
        for key, value in request.POST.iteritems():
            if(key.startswith('points-')):
                event_id = int(key.rpartition('-')[2])
                redemptions[event_id] = int(value)
     
        if save_redemptions(request, redemptions):
            messages.success(request, _("You successfully redeemed your points."))
        else:
            messages.warning(request, _("You don't have enough reward points."))            

    total_points_available = reward_points_of_user(request.user.userprofile)
    reward_point_grantings = RewardPointGranting.objects.filter(user_profile=request.user.userprofile)
    reward_point_redemptions = RewardPointRedemption.objects.filter(user_profile=request.user.userprofile)
    events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__gte=datetime.now())
    events = sorted(events, key=lambda event: event.date)

    reward_point_actions=[]
    for granting in reward_point_grantings:
        reward_point_actions.append((granting.granting_time, _('Reward for') + ' ' + granting.semester.name, granting.value, ''))
    for redemption in reward_point_redemptions:
        reward_point_actions.append((redemption.redemption_time, redemption.event.name, '', redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    return render_to_response(
        "rewards_index.html",
        dict(
            reward_point_actions=reward_point_actions,
            total_points_available=total_points_available,
            events=events,
            point_selection=[x for x in range(0,total_points_available+1)]
        ),
        context_instance=RequestContext(request))
Example #23
0
    def test_evaluation_removed_from_participant(self):
        self.student.evaluations_participating_in.remove(self.evaluation)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #24
0
    def test_participant_removed_from_evaluation(self):
        self.evaluation.participants.remove(self.student)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #25
0
 def test_everything_works(self):
     SemesterActivation.objects.create(semester=self.evaluation.course.semester, is_active=True)
     self.form.submit()
     self.assertEqual(reward_points_of_user(self.student), 3)
Example #26
0
 def test_semester_not_activated(self):
     self.form.submit()
     self.assertEqual(0, reward_points_of_user(self.student))
Example #27
0
    def test_participant_removed_from_course(self):
        self.course.participants.remove(self.student)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #28
0
 def test_already_got_enough_points(self):
     SemesterActivation.objects.create(semester=self.evaluation.course.semester, is_active=True)
     mommy.make(RewardPointGranting, user_profile=self.student, value=3, semester=self.evaluation.course.semester)
     self.form.submit()
     self.assertEqual(3, reward_points_of_user(self.student))
     self.assertEqual(1, RewardPointGranting.objects.filter(user_profile=self.student, semester=self.evaluation.course.semester).count())
Example #29
0
 def test_everything_works(self):
     SemesterActivation.objects.create(semester=self.course.semester, is_active=True)
     self.form.submit()
     self.assertEqual(settings.REWARD_POINTS_PER_SEMESTER, reward_points_of_user(self.student))
Example #30
0
    def test_course_removed_from_participant(self):
        self.student.courses_participating_in.remove(self.course)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #31
0
    def test_participant_removed_from_course(self):
        self.course.participants.remove(self.student)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #32
0
 def test_everything_works(self):
     SemesterActivation.objects.create(semester=self.course.semester,
                                       is_active=True)
     self.form.submit()
     self.assertEqual(settings.REWARD_POINTS_PER_SEMESTER,
                      reward_points_of_user(self.student))
Example #33
0
 def test_semester_not_activated(self):
     self.form.submit()
     self.assertEqual(0, reward_points_of_user(self.student))
Example #34
0
    def test_evaluation_removed_from_participant(self):
        self.student.evaluations_participating_in.remove(self.evaluation)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #35
0
    def test_participant_removed_from_evaluation(self):
        self.evaluation.participants.remove(self.student)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #36
0
 def test_activate_after_voting(self):
     baker.make(SemesterActivation, semester=self.semester, is_active=False)
     self.assertEqual(0, reward_points_of_user(self.student))
     response = self.app.post(self.url + "on", user=self.manager)
     self.assertContains(response, "3 reward points were granted")
     self.assertEqual(3, reward_points_of_user(self.student))
Example #37
0
    def test_course_removed_from_participant(self):
        self.student.courses_participating_in.remove(self.course)

        self.assertEqual(reward_points_of_user(self.student), settings.REWARD_POINTS_PER_SEMESTER)
Example #38
0
 def test_already_got_points(self):
     SemesterActivation.objects.create(semester=self.course.semester, is_active=True)
     mommy.make(RewardPointGranting, user_profile=self.student, value=0, semester=self.course.semester)
     self.form.submit()
     self.assertEqual(0, reward_points_of_user(self.student))
Example #39
0
    def test_course_removed_from_participant(self):
        self.student.courses_participating_in.remove(self.course)

        self.assertEqual(reward_points_of_user(self.student), 3)
Example #40
0
 def test_everything_works(self):
     SemesterActivation.objects.create(semester=self.evaluation.course.semester, is_active=True)
     self.form.submit()
     self.assertEqual(reward_points_of_user(self.student), 3)
Example #41
0
 def test_semester_activated_not_all_evaluations(self):
     SemesterActivation.objects.create(semester=self.evaluation.course.semester, is_active=True)
     mommy.make(Evaluation, course=mommy.make(Course, semester=self.evaluation.course.semester), participants=[self.student])
     self.form.submit()
     self.assertEqual(1, reward_points_of_user(self.student))