Fix: pas d'erreur quand pas de compte K-Fêt

This commit is contained in:
Ludovic Stephan 2019-12-25 12:35:46 +01:00
parent 786c8f132f
commit 8d11044610
2 changed files with 15 additions and 6 deletions

View file

@ -3,7 +3,7 @@ from datetime import datetime, timedelta
from decimal import Decimal from decimal import Decimal
from unittest import mock from unittest import mock
from django.contrib.auth.models import Group from django.contrib.auth.models import Group, User
from django.test import Client, TestCase from django.test import Client, TestCase
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
@ -4151,12 +4151,18 @@ class HistoryJSONViewTests(ViewTestCaseMixin, TestCase):
url_expected = "/k-fet/history.json" url_expected = "/k-fet/history.json"
auth_user = "user" auth_user = "user"
auth_forbidden = [None] auth_forbidden = [None, "noaccount"]
def test_ok(self): def test_ok(self):
r = self.client.post(self.url) r = self.client.post(self.url)
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
def get_users_extra(self):
noaccount = User.objects.create(username="noaccount")
noaccount.set_password("noaccount")
noaccount.save()
return {"noaccount": noaccount}
class AccountReadJSONViewTests(ViewTestCaseMixin, TestCase): class AccountReadJSONViewTests(ViewTestCaseMixin, TestCase):
url_name = "kfet.account.read.json" url_name = "kfet.account.read.json"

View file

@ -1423,10 +1423,13 @@ def history_json(request):
) )
if not request.user.has_perm("kfet.is_team"): if not request.user.has_perm("kfet.is_team"):
acc = request.user.profile.account_kfet try:
transfer_queryset_prefetch = transfer_queryset_prefetch.filter( acc = request.user.profile.account_kfet
Q(from_acc=acc) | Q(to_acc=acc) transfer_queryset_prefetch = transfer_queryset_prefetch.filter(
) Q(from_acc=acc) | Q(to_acc=acc)
)
except Account.DoesNotExist:
return JsonResponse({}, status=403)
transfer_prefetch = Prefetch( transfer_prefetch = Prefetch(
"transfers", queryset=transfer_queryset_prefetch, to_attr="filtered_transfers" "transfers", queryset=transfer_queryset_prefetch, to_attr="filtered_transfers"