예제 #1
0
    def test_new_badge_mapreduce(self):
        # Setting up the data is a bit complicated.  First, we have to
        # have a user do 5 correct exercises in a row, to earn the
        # easiest streak-badge.  But we have to do it in a way that
        # the code doesn't award the badge right away.  Then we can
        # run the mapreduce, which should award the badge then.  To do
        # this, we stub out the call that would normally award the
        # badge right away.
        orig_update_fn = util_badges.update_with_user_exercise
        try:
            util_badges.update_with_user_exercise = lambda *args, **kw: None
            new_user = user_models.UserData.insert_for('badgeuser',
                                                       '*****@*****.**')
            exercise = exercise_models.Exercise.get_by_name('exponent_rules')
            user_exercise = new_user.get_or_insert_exercise(exercise)
            for i in xrange(1, 10):  # 5 is enough, but we'll do 10
                exercise_util.attempt_problem(new_user,
                                              user_exercise,
                                              i,
                                              1,
                                              "firsttry",
                                              "sha1",
                                              "seed",
                                              True,
                                              0,
                                              3,
                                              False,
                                              False,
                                              "obsolete",
                                              "127.0.0.1", {},
                                              "TEST",
                                              "TEST",
                                              1,
                                              7,
                                              async_problem_log_put=False,
                                              async_stack_log_put=False)
        finally:
            util_badges.update_with_user_exercise = orig_update_fn

        # The badges info should be empty.
        b = models_badges.UserBadge.all().filter('user ='******'user =', new_user.user).get()
        self.assertNotEqual(None, b)
예제 #2
0
    def test_new_badge_mapreduce(self):
        # Setting up the data is a bit complicated.  First, we have to
        # have a user do 5 correct exercises in a row, to earn the
        # easiest streak-badge.  But we have to do it in a way that
        # the code doesn't award the badge right away.  Then we can
        # run the mapreduce, which should award the badge then.  To do
        # this, we stub out the call that would normally award the
        # badge right away.
        orig_update_fn = util_badges.update_with_user_exercise
        try:
            util_badges.update_with_user_exercise = lambda *args, **kw: None
            new_user = user_models.UserData.insert_for('badgeuser',
                                                       '*****@*****.**')
            exercise = exercise_models.Exercise.get_by_name('exponent_rules')
            user_exercise = new_user.get_or_insert_exercise(exercise)
            for i in xrange(1, 10):    # 5 is enough, but we'll do 10
                exercise_util.attempt_problem(new_user, user_exercise,
                                              i, 1, "firsttry", "sha1", "seed",
                                              True, 0, 3, False, False,
                                              "obsolete", "127.0.0.1", {},
                                              "TEST", "TEST", 1, 7,
                                              async_problem_log_put=False,
                                              async_stack_log_put=False)
        finally:
            util_badges.update_with_user_exercise = orig_update_fn

        # The badges info should be empty.
        b = models_badges.UserBadge.all().filter('user ='******'user =', new_user.user).get()
        self.assertNotEqual(None, b)
예제 #3
0
 def get(self):
     # Admin-only restriction is handled by /admin/* URL pattern
     # so this can be called by a cron job.
     mapreduce_id = util_badges.start_new_badge_mapreduce()
     self.response.out.write("OK: " + str(mapreduce_id))
예제 #4
0
 def get(self):
     # Admin-only restriction is handled by /admin/* URL pattern
     # so this can be called by a cron job.
     mapreduce_id = util_badges.start_new_badge_mapreduce()
     self.response.out.write("OK: " + str(mapreduce_id))