Skip to content

Commit

Permalink
Fixes #1563 -- Use iexact matching when querying users (#1973)
Browse files Browse the repository at this point in the history
* Fixes #1563 -- Use iexact mathing when querying users
* Add .pytest_cache to gitignore
* Make identifier non-optional
  • Loading branch information
oliverroick authored Feb 9, 2018
1 parent ba39323 commit 8c65ade
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ wheels/
*.pyc
.cache
__pycache__/
.pytest_cache

# Coverage
.coverage
Expand Down
6 changes: 3 additions & 3 deletions cadasta/accounts/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


class UserManager(DjangoUserManager):
def get_from_username_or_email_or_phone(self, identifier=None):
users = self.filter(Q(username=identifier) | Q(
email=identifier) | Q(phone=identifier))
def get_from_username_or_email_or_phone(self, identifier):
users = self.filter(Q(username__iexact=identifier) | Q(
email__iexact=identifier) | Q(phone=identifier))
users_count = len(users)

if users_count == 1:
Expand Down
15 changes: 15 additions & 0 deletions cadasta/accounts/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,28 @@ def test_get_from_username(self):

assert found == user

def test_get_from_username_non_case_sensitive(self):
user = UserFactory.create(username='TestUser')
found = User.objects.get_from_username_or_email_or_phone(
identifier='testuser'
)

assert found == user

def test_get_from_email(self):
user = UserFactory.create()
found = User.objects.get_from_username_or_email_or_phone(
identifier=user.email)

assert found == user

def test_get_from_email_non_case_sensitive(self):
user = UserFactory.create(email='[email protected]')
found = User.objects.get_from_username_or_email_or_phone(
identifier='[email protected]')

assert found == user

def test_get_from_phone(self):
user = UserFactory.create()
found = User.objects.get_from_username_or_email_or_phone(
Expand Down

0 comments on commit 8c65ade

Please sign in to comment.