revsys / django-test-plus

Useful additions to Django's default TestCase

Home Page:https://django-test-plus.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

make_user would not work with projects with a custom User model

nessita opened this issue · comments

Considering a project with a custom User model such as the user identifier is the email, not an username, when calling:

user = tp.make_user()

The following error is raised:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

tp = <test_plus.plugin.TestCase testMethod=runTest>

<removed code>

>       user = tp.make_user()
foo/tests/test_views.py:105:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'test_plus.plugin.TestCase'>, username = 'testuser', password = 'password', perms = None

    @classmethod
    def make_user(cls, username='testuser', password='password', perms=None):
        """
        Build a user with <username> and password of 'password' for testing
        purposes.
        """
        User = get_user_model()

        if cls.user_factory:
            USERNAME_FIELD = getattr(
                cls.user_factory._meta.model, 'USERNAME_FIELD', 'username')
            test_user = cls.user_factory(**{
                USERNAME_FIELD: username,
            })
            test_user.set_password(password)
            test_user.save()
        else:
>           test_user = User.objects.create_user(
                username,
                '{0}@example.com'.format(username),
                password,
            )
E           TypeError: UserManager.create_user() takes from 2 to 3 positional arguments but 4 were given