def test_uber_searcher(self): #Test UberSearcher # add a score in for the other category HighScore(user=self.u, category=self.c, highest_score=2000).save() hs = HighScore.objects.filter(user=self.u) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) #should not trigger achievement self.assertEquals(len(new_achievements_list), 0) # add a score in for the other category HighScore(user=self.u, category=self.c, highest_score=3000).save() hs = HighScore.objects.filter(user=self.u) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) self.assertEquals(len(new_achievements_list), 1)
def highscores(): HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Films")[0],highest_score=2566).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Actors")[0],highest_score=3200).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Films")[0],highest_score=1420).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Games")[0],highest_score=1667).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Universities")[0],highest_score=500).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Films")[0],highest_score=179).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Actors")[0],highest_score=800).save() HighScore(user=User.objects.filter(username='******')[0],category=Category.objects.filter(name="Actors")[0],highest_score=700).save()
def test_fives_pages_in_game(self): #testing FivePagesInAGame achievemnt class # add a score in for the other category HighScore(user=self.u, category=self.c, most_no_pages_found=2).save() hs = HighScore.objects.filter(user=self.u) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) #should not trigger achievement self.assertEquals(len(new_achievements_list), 0) HighScore(user=self.u, category=self.c, most_no_pages_found=5).save() hs = HighScore.objects.filter(user=self.u) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) #should trigger FivePagesInAGame achievement self.assertEquals(len(new_achievements_list), 1)
def test_all_cats(self): # add a score in for the other category for cat in Category.objects.all(): HighScore(user=self.u, category=cat, highest_score=1000).save() hs = HighScore.objects.filter(user=self.u) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) # the All Cats achievement is triggered self.assertEquals(new_achievements_list[0].achievement, self.allcat[0])
def test_achievements(self): print "testing achievements" # make sure there are no highscores so far hs = HighScore.objects.filter(user=self.u) self.assertEquals(len(hs), 0) # get the latest highscores new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) # check that no achievements are awarded self.assertEquals(len(new_achievements_list), 0) HighScore(user=self.u, category=self.c, highest_score=2900).save() hs = HighScore.objects.filter(user=self.u) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) # still no achievements should be awarded yet self.assertEquals(len(new_achievements_list), 0)
def test_highscorer(self): HighScore(user=self.u, category=self.c, highest_score=9000).save() hs = HighScore.objects.filter(user=self.u) total = 0 for h in hs: total += hs[0].highest_score print("testing highscorer\nTotal score:{0}".format(total)) new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) # The Ubersearcher achievement is triggered self.assertEquals(len(new_achievements_list), 1) # the high scores were increased hs = HighScore.objects.filter(user=self.u) for s in hs: s.highest_score += 3000 s.save() new_achievements_list = self.gac.check_and_set_new_achievements( self.up, hs, self.cg) # The high scorer achievement is triggered self.assertEquals(len(new_achievements_list), 1)
def profile_page(request, username): view_permission = False context = RequestContext(request, {}) user = User.objects.get(username=username) if user: user_profile = user.get_profile() achievements = PlayerAchievement.objects.filter(user=user) #TODO(mtbvc): do the following in a cleaner way #filter out achievements player got from all that are available available_achievements = Achievement.objects.all() player_badges = [item.achievement for item in achievements] av_achievements = [] for item in available_achievements: if item not in player_badges: av_achievements.append(item) #do same with highscores available_cats = Category.objects.all() highscores = HighScore.objects.filter(user=user) scores = list(highscores) player_cats = [item.category for item in highscores] for item in available_cats: if item not in player_cats: scores.append(HighScore(category=item, highest_score=0)) progress = get_progress(user, user_profile) for score in scores: score.url = encode_string_to_url(score.category.name) print score.url if request.user == user: view_permission = True return render_to_response( 'profiles/profile_page.html', { 'usr': user, 'profile': user_profile, 'murl': MEDIA_URL, 'achievements': achievements, 'available_achievements': av_achievements, 'view_perm': view_permission, 'highscores': scores, 'progress': progress, 'total_score': sum(i.highest_score for i in highscores) }, context)