Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introspect the USERNAME_FIELD on custom User models #40

Merged
merged 3 commits into from May 23, 2016

Conversation

goodtune
Copy link
Contributor

The library used to make the assumption that the USERNAME_FIELD was always going to be username however this is easily overloaded.

This allows testing of the following form:

class MyTest(TestCase):

    user_factory = MyUserFactory

    def test_some_feature(self):
        u1 = self.make_user()
        self.login(u1):
            self.assertTrue(True)

Assuming custom User model, such as:

class User(AbstractBaseUser, PermissionsMixin):

    email = EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )

    USERNAME_FIELD = 'email'

The library used to make the assumption that the `USERNAME_FIELD` was
always going to be `username` however this is easily overloaded.

This allows testing of the following form:

    class MyTest(TestCase):

        user_factory = MyUserFactory

        def test_some_feature(self):
            u1 = self.make_user()
            self.login(u1):
                self.assertTrue(True)

Assuming custom User model, such as:

    class User(AbstractBaseUser, PermissionsMixin):

        email = EmailField(
            verbose_name='email address',
            max_length=255,
            unique=True,
        )

        USERNAME_FIELD = 'email'
@coveralls
Copy link

coveralls commented May 22, 2016

Coverage Status

Coverage remained the same at 96.983% when pulling 4102f6e on goodtune:custom-user-model into 633d839 on revsys:master.

@coveralls
Copy link

coveralls commented May 23, 2016

Coverage Status

Coverage increased (+0.03%) to 97.009% when pulling 3ff2ccf on goodtune:custom-user-model into 633d839 on revsys:master.

@coveralls
Copy link

coveralls commented May 23, 2016

Coverage Status

Coverage increased (+0.03%) to 97.009% when pulling b7c31be on goodtune:custom-user-model into 633d839 on revsys:master.

@frankwiles frankwiles merged commit 978003c into revsys:master May 23, 2016
@frankwiles
Copy link
Member

Awesome this actually bit me on a project recently and I hadn't dived into it yet.

@goodtune
Copy link
Contributor Author

No worries, I think I have left you with 1 small glitch - an import for Python 3.3 is failing for Django 1.9.

I am unfamiliar with the standard library for that version and what would be necessary to fix it.

@frankwiles
Copy link
Member

No worries, Django 1.9 dropped support for 3.3 so it doesn't matter :)

Frank Wiles
Revolution Systems | http://www.revsys.com/
frank@revsys.com | (800) 647-6298

On Mon, May 23, 2016 at 2:43 PM, Gary Reynolds notifications@github.com
wrote:

No worries, I think I have left you with 1 small glitch - an import for
Python 3.3 is failing for Django 1.9.

I am unfamiliar with the standard library for that version and what would
be necessary to fix it.


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#40 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants