示例#1
0
    def test_my_ranking_weekly(self):
        from models import User, AuthToken, UserStats
        from django.test import RequestFactory
        from django.core.urlresolvers import reverse
        from views import my_ranking_weekly

        users = []
        for i in range(10):
            u = User()
            u.email = '*****@*****.**' + str(i)
            u.public_name = 'TEST' + str(i)
            u.save()
            users.append(u)
            UserStats.record_stats(u, i * 100, datetime.date.today())

        auth = AuthToken()
        auth.token_string = AuthToken.gen_token_string('*****@*****.**')
        auth.user = users[9]
        auth.valid = True
        auth.save()

        factory = RequestFactory()

        rq = factory.get(reverse('my_ranking_weekly'),
                         data={'token': auth.token_string})

        response = my_ranking_weekly(rq)

        data = json.loads(response.content)

        self.assertEqual(data['status'], 'OK')
示例#2
0
def log_distance(request):
    from models import UserStats
    token_param = request.GET.get('token')
    if not AuthToken.is_token_valid(token_param) and settings.DEBUG is False:
        return JsonResponse({'status': 'INVALID_TOKEN'})

    steps = request.GET.get('steps')
    if not steps:
        HttpResponseBadRequest('steps parameter is required')

    steps = int(steps)

    token = AuthToken.objects.get(token_string=token_param)
    user = token.user

    UserStats.record_stats(user, steps)

    return JsonResponse({'status': 'OK'})