more reforting

This commit is contained in:
Amir Qayyum Khan
2018-05-25 15:49:29 +05:00
parent 70440672c9
commit 2f7643f7d8
2 changed files with 11 additions and 7 deletions

View File

@@ -2276,7 +2276,7 @@ def get_user_by_username_or_email(username_or_email):
username_or_email = strip_if_string(username_or_email)
# there should be one user with either username or email equal to username_or_email
user = User.objects.get(Q(email=username_or_email) | Q(username=username_or_email))
if user is not None and user.username == username_or_email:
if user.username == username_or_email:
UserRetirementRequest = apps.get_model('user_api', 'UserRetirementRequest')
if UserRetirementRequest.has_user_requested_retirement(user):
raise User.DoesNotExist

View File

@@ -370,8 +370,8 @@ class TestStudentFromIdentifier(TestCase):
def setUpClass(cls):
super(TestStudentFromIdentifier, cls).setUpClass()
cls.valid_student = UserFactory.create(username='baz@touchstone')
cls.duplicate_email = UserFactory.create(email='foo@touchstone.com')
cls.duplicate_user_name = UserFactory.create(username='foo@touchstone.com')
cls.student_conflicting_email = UserFactory.create(email='foo@touchstone.com')
cls.student_conflicting_username = UserFactory.create(username='foo@touchstone.com')
def test_valid_student_id(self):
"""Test with valid username"""
@@ -387,10 +387,12 @@ class TestStudentFromIdentifier(TestCase):
there is user B with email example: foo@touchstone.com
"""
with self.assertRaises(MultipleObjectsReturned):
tools.get_student_from_identifier(self.duplicate_user_name.username)
tools.get_student_from_identifier(self.student_conflicting_username.username)
# can get student with alternative identifier, in this case email.
assert self.duplicate_user_name == tools.get_student_from_identifier(self.duplicate_user_name.email)
assert self.student_conflicting_username == tools.get_student_from_identifier(
self.student_conflicting_username.email
)
def test_student_email_has_conflict_with_others_username(self):
"""
@@ -398,10 +400,12 @@ class TestStudentFromIdentifier(TestCase):
there is user B with username example: foo@touchstone.com
"""
with self.assertRaises(MultipleObjectsReturned):
tools.get_student_from_identifier(self.duplicate_email.email)
tools.get_student_from_identifier(self.student_conflicting_email.email)
# can get student with alternative identifier, in this case username.
assert self.duplicate_email == tools.get_student_from_identifier(self.duplicate_email.username)
assert self.student_conflicting_email == tools.get_student_from_identifier(
self.student_conflicting_email.username
)
def test_invalid_student_id(self):
"""Test with invalid identifier"""