Esempio n. 1
0
    def test_check_achievements_friends(self):
        create_achievements()
        user = User.objects.create_user(username='******')
        
        check_achievements(user.id)
        self.assertFalse(user.has_achievement(get_achievement("Friendly")))
        self.assertFalse(user.has_achievement(get_achievement("Super Friendly")))
        self.assertFalse(user.has_achievement(get_achievement("Politician")))

        for i in range(1, 51):
            temp = User.objects.create_user(username=str(i))
            user.friends.add(temp)

        check_achievements(user.id)
        self.assertTrue(user.has_achievement(get_achievement("Friendly")))
        self.assertFalse(user.has_achievement(get_achievement("Super Friendly")))
        self.assertFalse(user.has_achievement(get_achievement("Politician")))
        
        for i in range(1, 51):
            temp = User.objects.create_user(username=str(i*100))
            user.friends.add(temp)

        check_achievements(user.id)
        self.assertTrue(user.has_achievement(get_achievement("Friendly")))
        self.assertTrue(user.has_achievement(get_achievement("Super Friendly")))
        self.assertFalse(user.has_achievement(get_achievement("Politician")))

        for i in range(1, 500):
            temp = User.objects.create_user(username=str(i*10000))
            user.friends.add(temp)

        check_achievements(user.id)
        self.assertTrue(user.has_achievement(get_achievement("Politician")))
        self.assertTrue(user.has_achievement(get_achievement("Super Friendly")))
        self.assertTrue(user.has_achievement(get_achievement("Politician")))
Esempio n. 2
0
def login(request):
    # Protect against CSRF attacks
    c = {}
    c.update(csrf(request))
    state = "Please log in below..."
    username = password = ''

    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')

        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                auth.login(request, user)
                check_achievements(user.id)
                return redirect('users:userview', user.id)
            else:
                state = "Your account is not active, please activate your account."
        else:
            state = "Your username and/or password were incorrect."
    return render_to_response('users/login_page.html', {'state':state, 'username': username}, context_instance=RequestContext(request))
Esempio n. 3
0
    def test_check_achievements_wallposts(self):
        create_achievements()
        now = datetime.utcnow().replace(tzinfo=utc)

        user = User.objects.create_user(username='******')
        other = User.objects.create_user(username='******')
        user.friends.add(other)
        self.assertFalse(user.has_achievement(get_achievement("Outspoken")))
        self.assertFalse(user.has_achievement(get_achievement("Social climber")))

        for i in range(1, 51):
            WallPost.objects.create(message="bla", pub_date=now, poster=user, receiver=other)

        check_achievements(user.id)
        self.assertTrue(user.has_achievement(get_achievement("Outspoken")))
        self.assertFalse(user.has_achievement(get_achievement("Social climber")))

        for i in range(1, 151):
            WallPost.objects.create(message="bla", pub_date=now, poster=user, receiver=other)

        check_achievements(user.id)
        self.assertTrue(user.has_achievement(get_achievement("Outspoken")))
        self.assertTrue(user.has_achievement(get_achievement("Social climber")))