diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 218c20ee67..d4acf521d0 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -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 diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index 39c1c727aa..30c93bcdf9 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -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"""