示例#1
0
 def testAwardRollback(self):
   """Tests that the last_awarded_submission field rolls back to a previous task."""
   user = User(username="******", password="******")
   user.save()
   
   activity1 = Activity(
               title="Test activity",
               slug="test-activity",
               description="Testing!",
               duration=10,
               point_value=10,
               pub_date=datetime.datetime.today(),
               expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
               confirm_type="text",
               type="activity",
   )
   activity1.save()
   
   activity2 = Activity(
               title="Test activity 2",
               slug="test-activity-2",
               description="Testing!",
               duration=10,
               point_value=15,
               pub_date=datetime.datetime.today(),
               expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
               confirm_type="text",
               type="activity",
   )
   activity2.save()
   activities = [activity1, activity2]
   
   # Submit the first activity.  This is what we're going to rollback to.
   activity_member = ActivityMember(user=user, activity=activities[0], submission_date=datetime.datetime.today())
   activity_member.approval_status = "approved"
   activity_member.submission_date = datetime.datetime.today() - datetime.timedelta(days=1)
   activity_member.save()
   
   points = user.get_profile().points
   submit_date = user.get_profile().last_awarded_submission
   
   # Submit second activity.
   activity_member = ActivityMember(user=user, activity=activities[1], submission_date=datetime.datetime.today())
   activity_member.approval_status = "approved"
   activity_member.submission_date = datetime.datetime.today()
   activity_member.save()
   logs = user.pointstransaction_set.count()
   
   activity_member.approval_status = "rejected"
   activity_member.submission_date = datetime.datetime.today()
   activity_member.save()
   
   # Verify that we rolled back to the previous activity.
   self.assertEqual(points, user.get_profile().points)
示例#2
0
    def simulate_activities_for_round_1(self):
        round_start = datetime.datetime.strptime(
            settings.COMPETITION_ROUNDS["Round 1"]["start"],
            "%Y-%m-%d").date()
        round_end = datetime.datetime.strptime(
            settings.COMPETITION_ROUNDS["Round 1"]["end"], "%Y-%m-%d").date()
        date_delta = (round_end - round_start).days
        self.stdout.write(
            "Simulating activity participation in the first round.\n")

        activities = Activity.objects.filter(pub_date__gte=round_start,
                                             pub_date__lt=round_end)
        for profile in Profile.objects.all():
            if (profile.user.username == "admin"):
                # We want to skip admin for now.
                continue

            # Assume user will participate between 0 and 3 activities
            # Random activity from http://stackoverflow.com/questions/962619/how-to-pull-a-random-record-using-djangos-orm
            user_activities = activities.order_by("?")[0:random.randint(0, 3)]
            for activity in user_activities:
                member = ActivityMember(user=profile.user, activity=activity)
                member.submission_date = datetime.datetime.combine(
                    round_start, datetime.time()) + datetime.timedelta(
                        days=random.randint(0, date_delta))
                member.approval_status = "approved"
                member.save()
示例#3
0
 def simulate_activities_for_round_2(self):
   round_start = datetime.datetime.strptime(settings.COMPETITION_ROUNDS["Round 2"]["start"], "%Y-%m-%d").date()
   round_end = datetime.datetime.strptime(settings.COMPETITION_ROUNDS["Round 2"]["end"], "%Y-%m-%d").date()
   today_diff = (datetime.date.today() - round_start).days
   self.stdout.write("Simulating activity participation in the second round.\n")
   
   for profile in Profile.objects.all():
     # In this case, let's just add a pending activity or two.
     activities = get_available_activities(profile.user).order_by("?")[0:random.randint(0, 2)]
     for activity in activities:
       member = ActivityMember(user=profile.user, activity=activity)
       member.submission_date = datetime.datetime.today() - datetime.timedelta(days=random.randint(0, today_diff))
       member.approval_status = "pending"
       member.save()
示例#4
0
 def simulate_activities_for_round_1(self):
   round_start = datetime.datetime.strptime(settings.COMPETITION_ROUNDS["Round 1"]["start"], "%Y-%m-%d").date()
   round_end = datetime.datetime.strptime(settings.COMPETITION_ROUNDS["Round 1"]["end"], "%Y-%m-%d").date()
   date_delta = (round_end - round_start).days
   self.stdout.write("Simulating activity participation in the first round.\n")
   
   activities = Activity.objects.filter(pub_date__gte=round_start, pub_date__lt=round_end)
   for profile in Profile.objects.all():
     if(profile.user.username == "admin"):
       # We want to skip admin for now.
       continue
       
     # Assume user will participate between 0 and 3 activities
     # Random activity from http://stackoverflow.com/questions/962619/how-to-pull-a-random-record-using-djangos-orm
     user_activities = activities.order_by("?")[0:random.randint(0, 3)]
     for activity in user_activities:
       member = ActivityMember(user=profile.user, activity=activity)
       member.submission_date = datetime.datetime.combine(round_start, datetime.time()) + datetime.timedelta(days=random.randint(0, date_delta))
       member.approval_status = "approved"
       member.save()
示例#5
0
    def simulate_activities_for_round_2(self):
        round_start = datetime.datetime.strptime(
            settings.COMPETITION_ROUNDS["Round 2"]["start"],
            "%Y-%m-%d").date()
        round_end = datetime.datetime.strptime(
            settings.COMPETITION_ROUNDS["Round 2"]["end"], "%Y-%m-%d").date()
        today_diff = (datetime.date.today() - round_start).days
        self.stdout.write(
            "Simulating activity participation in the second round.\n")

        for profile in Profile.objects.all():
            # In this case, let's just add a pending activity or two.
            activities = get_available_activities(
                profile.user).order_by("?")[0:random.randint(0, 2)]
            for activity in activities:
                member = ActivityMember(user=profile.user, activity=activity)
                member.submission_date = datetime.datetime.today(
                ) - datetime.timedelta(days=random.randint(0, today_diff))
                member.approval_status = "pending"
                member.save()
示例#6
0
  def testRoundDoesNotUpdate(self):
    """Test that the score for the round does not update for an activity submitted outside of the round."""
    entry, created = ScoreboardEntry.objects.get_or_create(
                        profile=self.user.get_profile(), 
                        round_name=self.current_round,
                      )
    round_points = entry.points
    round_submission_date = entry.last_awarded_submission

    activity_member = ActivityMember(user=self.user, activity=self.activity)
    activity_member.approval_status = "approved"
    activity_member.submission_date = datetime.datetime.today() - datetime.timedelta(days=1)
    activity_member.save()

    # Verify that the points for the round has not been updated.
    entry, created = ScoreboardEntry.objects.get_or_create(
                        profile=self.user.get_profile(), 
                        round_name=self.current_round,
                      )
                      
    self.assertEqual(round_points, entry.points)
    self.assertEqual(round_submission_date, entry.last_awarded_submission)
示例#7
0
    def testAwardRollback(self):
        """Tests that the last_awarded_submission field rolls back to a previous task."""
        user = User(username="******", password="******")
        user.save()

        activity1 = Activity(
            title="Test activity",
            slug="test-activity",
            description="Testing!",
            duration=10,
            point_value=10,
            pub_date=datetime.datetime.today(),
            expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
            confirm_type="text",
            type="activity",
        )
        activity1.save()

        activity2 = Activity(
            title="Test activity 2",
            slug="test-activity-2",
            description="Testing!",
            duration=10,
            point_value=15,
            pub_date=datetime.datetime.today(),
            expire_date=datetime.datetime.today() + datetime.timedelta(days=7),
            confirm_type="text",
            type="activity",
        )
        activity2.save()
        activities = [activity1, activity2]

        # Submit the first activity.  This is what we're going to rollback to.
        activity_member = ActivityMember(
            user=user,
            activity=activities[0],
            submission_date=datetime.datetime.today())
        activity_member.approval_status = "approved"
        activity_member.submission_date = datetime.datetime.today(
        ) - datetime.timedelta(days=1)
        activity_member.save()

        points = user.get_profile().points
        submit_date = user.get_profile().last_awarded_submission

        # Submit second activity.
        activity_member = ActivityMember(
            user=user,
            activity=activities[1],
            submission_date=datetime.datetime.today())
        activity_member.approval_status = "approved"
        activity_member.submission_date = datetime.datetime.today()
        activity_member.save()
        logs = user.pointstransaction_set.count()

        activity_member.approval_status = "rejected"
        activity_member.submission_date = datetime.datetime.today()
        activity_member.save()

        # Verify that we rolled back to the previous activity.
        self.assertEqual(points, user.get_profile().points)