from functools import partial
from operator import itemgetter

from rest_framework.reverse import reverse
from rest_framework import status

from ..utils import render_url


def user_to_data(user, response):
    return {
        'id': user.id,
        'username': user.username,
        'url': render_url(response, 'api:users-detail', user.id),
    }


def test_users_list(client, new_user):
    new_users = [new_user() for _ in range(5)] + [
        new_user(is_email_verified=False, is_active=True),  # Additional unverified user
        new_user(is_email_verified=True, is_active=False),  # Additional inactive user
    ]

    response = client.get(reverse('api:users-list'))

    sort_by_id = partial(sorted, key=itemgetter('id'))
    expected = map(partial(user_to_data, response=response), new_users)

    assert response.status_code == status.HTTP_200_OK
    assert sort_by_id(response.json()) == sort_by_id(expected)

@@ -56,16 +56,30 @@
 getter%0A%0A
+import pytest%0A
 from res
@@ -148,16 +148,50 @@
 status%0A%0A
+from user.models import FruitUser%0A
 from ..u
@@ -394,16 +394,39 @@
     %7D%0A%0A%0A
+@pytest.mark.django_db%0A
 def test
@@ -449,18 +449,65 @@
 nt, 
-new_user):
+truncate_table, new_user):%0A    truncate_table(FruitUser)%0A
 %0A   

Fix user testing bugs