# Path: user_management/models/tests/factories.py
# class UserFactory(factory.DjangoModelFactory):
#     name = factory.Sequence('Test User {}'.format)
#     email = factory.Sequence('email{}@example.com'.format)
#     is_active = True
# 
#     class Meta:
#         model = get_user_model()
# 
#     @factory.post_generation
#     def password(self, create, extracted='default password', **kwargs):
#         self.raw_password = extracted
#         self.set_password(self.raw_password)
#         if create:
#             self.save()
# 
# Path: user_management/models/tests/models.py
# class User(AvatarMixin, VerifyEmailMixin, PermissionsMixin, AbstractBaseUser):
#     pass
# 
# Path: user_management/models/admin.py
# class VerifyUserAdmin(UserAdmin):
#     readonly_fields = ('date_joined', 'email_verified')
# 
#     def get_fieldsets(self, request, obj=None):
#         fieldsets = super(VerifyUserAdmin, self).get_fieldsets(request, obj)
#         fieldsets_dict = OrderedDict(fieldsets)
# 
#         try:
#             fields = list(fieldsets_dict['Permissions']['fields'])
#         except KeyError:
#             return fieldsets
# 
#         try:
#             index = fields.index('is_active')
#         except ValueError:
#             # If get_fieldsets is called twice, 'is_active' will already be
#             # removed and fieldsets will be correct so return it
#             return fieldsets
# 
#         fields[index] = ('is_active', 'email_verified')
#         fieldsets_dict['Permissions']['fields'] = tuple(fields)
#         return tuple(fieldsets_dict.items())


from django.contrib.admin.sites import AdminSite
from django.test import TestCase
from .factories import UserFactory
from .models import User
from ..admin import VerifyUserAdmin
        expected_fieldsets = (
            (None, {
                'classes': ('wide',),
                'fields': ('email', 'password1', 'password2'),
            }),
        )

        verify_user_admin = VerifyUserAdmin(User, self.site)
        self.assertEqual(
            verify_user_admin.get_fieldsets(request=None),
            expected_fieldsets,
        )

    def test_fieldsets(self):
        expected_fieldsets = (
            (None, {'fields': ('email', 'password')}),
            ('Personal info', {'fields': ('name',)}),
            ('Permissions', {
                'fields': (
                    ('is_active', 'email_verified'),
                    'is_staff',
                    'is_superuser',
                    'groups',
                    'user_permissions',
                )
            }),
            ('Important dates', {
                'fields': ('last_login', 'date_joined'),
            }),
        )

# Path: user_management/models/tests/factories.py
# class UserFactory(factory.DjangoModelFactory):
#     name = factory.Sequence('Test User {}'.format)
#     email = factory.Sequence('email{}@example.com'.format)
#     is_active = True
# 
#     class Meta:
#         model = get_user_model()
# 
#     @factory.post_generation
#     def password(self, create, extracted='default password', **kwargs):
#         self.raw_password = extracted
#         self.set_password(self.raw_password)
#         if create:
#             self.save()
# 
# Path: user_management/models/tests/models.py
# class User(AvatarMixin, VerifyEmailMixin, PermissionsMixin, AbstractBaseUser):
#     pass
# 
# Path: user_management/models/admin.py
# class VerifyUserAdmin(UserAdmin):
#     readonly_fields = ('date_joined', 'email_verified')
# 
#     def get_fieldsets(self, request, obj=None):
#         fieldsets = super(VerifyUserAdmin, self).get_fieldsets(request, obj)
#         fieldsets_dict = OrderedDict(fieldsets)
# 
#         try:
#             fields = list(fieldsets_dict['Permissions']['fields'])
#         except KeyError:
#             return fieldsets
# 
#         try:
#             index = fields.index('is_active')
#         except ValueError:
#             # If get_fieldsets is called twice, 'is_active' will already be
#             # removed and fieldsets will be correct so return it
#             return fieldsets
# 
#         fields[index] = ('is_active', 'email_verified')
#         fieldsets_dict['Permissions']['fields'] = tuple(fields)
#         return tuple(fieldsets_dict.items())


# Path: user_management/models/tests/test_admin.py
from django.contrib.admin.sites import AdminSite
from django.test import TestCase
from .factories import UserFactory
from .models import User
from ..admin import VerifyUserAdmin

        expected_fieldsets = (
            (None, {
                'classes': ('wide',),
                'fields': ('email', 'password1', 'password2'),
            }),
        )

        verify_user_admin = VerifyUserAdmin(User, self.site)
        self.assertEqual(
            verify_user_admin.get_fieldsets(request=None),
            expected_fieldsets,
        )

    def test_fieldsets(self):
        expected_fieldsets = (
            (None, {'fields': ('email', 'password')}),
            ('Personal info', {'fields': ('name',)}),
            ('Permissions', {
                'fields': (
                    ('is_active', 'email_verified'),
                    'is_staff',
                    'is_superuser',
                    'groups',
                    'user_permissions',
                )
            }),
            ('Important dates', {
                'fields': ('last_login', 'date_joined'),
            }),
        )

        user = UserFactory.build()