Ejemplo n.º 1
0
    def test_get_by_username(self):
        username = "******"
        User.get_or_create_by_username(username)
        user = User.get_by_username(username)
        self.assertEqual(_User.objects.count(), 1)
        self.assertEqual(user.to_json()["username"], username)

        default_equipment_ids = set([1, 2, 5, 10, 20, 21])
        self.assertItemsEqual(set(user.to_json()["equipment_ids"]), default_equipment_ids)
Ejemplo n.º 2
0
    def inner(request, *args, **kwargs):
        if 'username' not in request.GET:
            return render_to_json({
                "message": "GET requires a 'username'"
            }, status=400)
        username = request.GET['username']
        user = User.get_by_username(username)

        if 'access_token' not in request.GET:
            return render_to_json({
                "message": "GET requires an 'access_token'"
            }, status=400)
        access_token = AccessToken.get_from_token_data(request.GET['access_token'])
        if not access_token.has_access_to_user(user):
            return render_to_json({
                "message": "Invalid Access Token"
            }, status=403)
        kwargs['user'] = user

        return fn(request, *args, **kwargs)