Skip to content

Commit

Permalink
simplify query
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Feb 4, 2025
1 parent e08db77 commit a1aca79
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/api/views/auth_factor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
User,
)
from codeforlife.user.permissions import IsTeacher
from django.db.models import Count
from django.db.models import Count, Q

from ..permissions import HasAuthFactor
from .auth_factor import AuthFactorViewSet
Expand Down Expand Up @@ -195,14 +195,19 @@ def test_list__user(self):
# - one admin teacher;
# - two teachers with auth factors enabled.
school = (
School.objects.filter(
id__in=School.objects.filter(
teacher_school__is_admin=True,
).values_list("id", flat=True)
School.objects.annotate(
admin_teacher_count=Count(
"teacher_school",
filter=Q(teacher_school__is_admin=True),
),
mfa_teacher_count=Count(
"teacher_school",
filter=Q(
teacher_school__new_user__auth_factors__isnull=False
),
),
)
.filter(teacher_school__new_user__auth_factors__isnull=False)
.annotate(teacher_count=Count("teacher_school"))
.filter(teacher_count__gte=2)
.filter(admin_teacher_count__gte=1, mfa_teacher_count__gte=2)
.first()
)
assert school
Expand Down

0 comments on commit a1aca79

Please sign in to comment.