From a8b5bd66956e6ba3e9e3de91a58000990f5aed45 Mon Sep 17 00:00:00 2001 From: Roni Choudhury <2903332+waxlamp@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:25:02 -0400 Subject: [PATCH] Simplify test code Co-authored-by: Mike VanDenburgh <37340715+mvandenburgh@users.noreply.github.com> --- dandiapi/api/tests/test_stats.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/dandiapi/api/tests/test_stats.py b/dandiapi/api/tests/test_stats.py index 176307dbe..3304f43f7 100644 --- a/dandiapi/api/tests/test_stats.py +++ b/dandiapi/api/tests/test_stats.py @@ -1,6 +1,5 @@ from __future__ import annotations -from django.contrib.auth.models import User import pytest from dandiapi.api.models import UserMetadata @@ -35,30 +34,11 @@ def test_stats_published(api_client, published_version_factory): @pytest.mark.django_db def test_stats_user(api_client, user_factory): - # Create multiple users with different statuses - approved_user_count = 0 - users_per_status = 3 - user_index = 0 + users_per_status = approved_user_count = 3 for status in UserMetadata.Status.choices: - status_value = status[0] - for _ in range(users_per_status): - username = f'{status_value.lower()}_user_{user_index}' - user = user_factory(username=username) - user_metadata, created = UserMetadata.objects.get_or_create( - user=user, - defaults={ - 'status': status_value, - 'questionnaire_form': None, - 'rejection_reason': '' - } - ) - if not created: - pass - if status_value == UserMetadata.Status.APPROVED: - approved_user_count += 1 - user_index += 1 + [user_factory(metadata__status=status[0]) for _ in range(users_per_status)] stats = api_client.get('/api/stats/').data