diff --git a/dandiapi/api/tests/test_stats.py b/dandiapi/api/tests/test_stats.py index 176307dbe..20e7f157c 100644 --- a/dandiapi/api/tests/test_stats.py +++ b/dandiapi/api/tests/test_stats.py @@ -36,29 +36,17 @@ 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 - + 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 + users = [user_factory(username=username, metadata__status=status[0]) for _ in range(users_per_status)] + + stats = api_client.get('/api/stats/').data + + # Assert that the user count only includes users with APPROVED status + assert stats['user_count'] == approved_user_count stats = api_client.get('/api/stats/').data