Esempio n. 1
0
 def test_create_new_user(self):
     """Can properly create new user"""
     self.assertFalse(utils.username_exists(self.new_user))
     self.assertTrue(utils.create_user(self.new_user, self.password,
                                       self.email,
                                       self.first_name, self.last_name))
     self.assertTrue(utils.username_exists(self.new_user))
     utils.delete_user(self.new_user)
     self.assertFalse(utils.username_exists(self.new_user))
Esempio n. 2
0
 def test_create_new_user(self):
     """Can properly create new user"""
     self.assertFalse(utils.username_exists(self.new_user))
     self.assertTrue(
         utils.create_user(self.new_user, self.password, self.email,
                           self.first_name, self.last_name))
     self.assertTrue(utils.username_exists(self.new_user))
     utils.delete_user(self.new_user)
     self.assertFalse(utils.username_exists(self.new_user))
Esempio n. 3
0
    def tearDown(self):
        if utils.username_exists(self.user):
            utils.delete_user(self.user)
        if utils.username_exists(self.new_user):
            utils.delete_user(self.new_user)

        # Remove groups:
        utils.delete_group(self.group_of_names)
        self.assertFalse(utils.group_exists(self.group_of_names))
        utils.delete_group(self.posix_group)
        self.assertFalse(utils.group_exists(self.posix_group))
        utils.delete_group(self.super_group)
        self.assertFalse(utils.group_exists(self.super_group))
Esempio n. 4
0
    def tearDown(self):
        if utils.username_exists(self.user):
            utils.delete_user(self.user)
        if utils.username_exists(self.new_user):
            utils.delete_user(self.new_user)

        # Remove groups:
        utils.delete_group(self.group_of_names)
        self.assertFalse(utils.group_exists(self.group_of_names))
        utils.delete_group(self.posix_group)
        self.assertFalse(utils.group_exists(self.posix_group))
        utils.delete_group(self.super_group)
        self.assertFalse(utils.group_exists(self.super_group))
Esempio n. 5
0
    def test_direct_create_user(self):
        """Creating an LDAP user directly via model instantiation."""
        if username_exists(self.username):
            self.assertTrue(delete_user(self.username))
        user = self.model(
            username=self.username,
            email=self.email,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        user.save()

        self.verify_user_attributes_valid()
Esempio n. 6
0
    def test_direct_create_user(self):
        """Creating an LDAP user directly via model instantiation."""
        if username_exists(self.username):
            self.assertTrue(delete_user(self.username))
        user = self.model(
            username=self.username,
            email=self.email,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        user.save()

        self.verify_user_attributes_valid()
Esempio n. 7
0
    def test_create_user(self):
        """Test creating a user."""
        if username_exists(self.username):
            self.assertTrue(delete_user(self.username))

        self.assertFalse(
            self.model.objects.filter(username=self.username).exists())
        self.assertIsNotNone(self.model.objects.create_user(
            username=self.username,
            email=self.email,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name))

        self.verify_user_attributes_valid()
Esempio n. 8
0
    def test_create_user(self):
        """Test creating a user."""
        if username_exists(self.username):
            self.assertTrue(delete_user(self.username))

        self.assertFalse(
            self.model.objects.filter(username=self.username).exists())
        self.assertIsNotNone(self.model.objects.create_user(
            username=self.username,
            email=self.email,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name))

        self.verify_user_attributes_valid()
Esempio n. 9
0
    def test_create_incomplete_user(self):
        """Creating an LDAP user with incomplete information should raise a
        ValidationError.
        """
        if username_exists(self.username):
            self.assertTrue(delete_user(self.username))
        # Lacking first_name, last_name
        user = self.model(
            username=self.username,
            email=self.email,
            password=self.password)
        self.assertRaises(ValidationError, user.save)

        self.assertFalse(
            self.model.objects.filter(username=self.username).exists())
        self.assertFalse(username_exists(self.username))
Esempio n. 10
0
    def test_create_incomplete_user(self):
        """Creating an LDAP user with incomplete information should raise a
        ValidationError.
        """
        if username_exists(self.username):
            self.assertTrue(delete_user(self.username))
        # Lacking first_name, last_name
        user = self.model(
            username=self.username,
            email=self.email,
            password=self.password)
        self.assertRaises(ValidationError, user.save)

        self.assertFalse(
            self.model.objects.filter(username=self.username).exists())
        self.assertFalse(username_exists(self.username))
Esempio n. 11
0
    def verify_user_attributes_valid(self, is_superuser=False):
        # Make sure it's saved
        query = self.model.objects.filter(username=self.username)
        self.assertEqual(1, query.count())
        user = query[0]

        # Attributes
        self.assertEqual(user.get_username(), self.username)
        self.assertEqual(user.email, self.email)
        self.assertEqual(user.is_superuser, is_superuser)
        self.assertEqual(user.first_name, self.first_name)
        self.assertEqual(user.last_name, self.last_name)

        # check_password and has_usable_password should work
        self.assertFalse(get_user_model().has_usable_password(user))
        self.assertTrue(user.has_usable_password())
        self.assertTrue(user.check_password(self.password))
        user.set_unusable_password()
        self.assertFalse(user.has_usable_password())

        # Verify LDAP utilities
        self.assertTrue(username_exists(self.username))
        self.assertTrue(delete_user(self.username))
Esempio n. 12
0
    def verify_user_attributes_valid(self, is_superuser=False):
        # Make sure it's saved
        query = self.model.objects.filter(username=self.username)
        self.assertEqual(1, query.count())
        user = query[0]

        # Attributes
        self.assertEqual(user.get_username(), self.username)
        self.assertEqual(user.email, self.email)
        self.assertEqual(user.is_superuser, is_superuser)
        self.assertEqual(user.first_name, self.first_name)
        self.assertEqual(user.last_name, self.last_name)

        # check_password and has_usable_password should work
        self.assertFalse(get_user_model().has_usable_password(user))
        self.assertTrue(user.has_usable_password())
        self.assertTrue(user.check_password(self.password))
        user.set_unusable_password()
        self.assertFalse(user.has_usable_password())

        # Verify LDAP utilities
        self.assertTrue(username_exists(self.username))
        self.assertTrue(delete_user(self.username))
Esempio n. 13
0
 def tearDown(self):
     if username_exists(self.username):
         self.assertTrue(delete_user(self.username))
Esempio n. 14
0
 def delete(self, *args, **kwargs):
     """Delete the instance only if LDAP user deletion was successfull."""
     if ldap_utils.delete_user(self.get_username()):
         super(LDAPUser, self).delete(*args, **kwargs)
Esempio n. 15
0
 def delete(self, *args, **kwargs):
     """Delete the instance only if LDAP user deletion was successfull."""
     if ldap_utils.delete_user(self.get_username()):
         super(LDAPUser, self).delete(*args, **kwargs)
Esempio n. 16
0
 def tearDown(self):
     if username_exists(self.username):
         self.assertTrue(delete_user(self.username))