def test_get_ldap_user_class(self): """Check that get_ldap_user returns an LDAPUser instance of the given user, without modifying the original object. """ self.assertNotIsInstance(self.user, LDAPUser) make_ldap_user(self.user) self.assertIsInstance(self.user, LDAPUser) self.assertEqual(self.user.get_username(), self.username)
def test_num_sql_queries(self): """Ensure that the method leads to no additional SQL queries changing the user to an instance of LDAPUser. """ # pylint: disable=E1103 with self.assertNumQueries(0): make_ldap_user(self.user) self.assertIsInstance(self.user, LDAPUser) self.assertEqual(self.user.get_username(), self.username)
def save(self, commit=True): # Call the ModelForm save method directly, since we are overriding the # Django UserCreationForm save() functionality here user = forms.ModelForm.save(self, commit=False) if USE_LDAP: # Create an entry in LDAP for this new user: ldap_utils.create_user(user.get_username(), self.cleaned_data['password1'], user.email, user.first_name, user.last_name) # Use the LDAPUser proxy model for this object make_ldap_user(user) user.set_password(self.cleaned_data['password1']) if commit: user.save() return user
def save(self, commit=True): # Call the ModelForm save method directly, since we are overriding the # Django UserCreationForm save() functionality here user = forms.ModelForm.save(self, commit=False) if USE_LDAP: # Create an entry in LDAP for this new user: ldap_utils.create_user( user.get_username(), self.cleaned_data['password1'], user.email, user.first_name, user.last_name) # Use the LDAPUser proxy model for this object make_ldap_user(user) user.set_password(self.cleaned_data['password1']) if commit: user.save() return user
def __init__(self, *args, **kwargs): super(MakeLDAPUserMixin, self).__init__(*args, **kwargs) if USE_LDAP and self.user: make_ldap_user(self.user)