示例#1
0
文件: tests.py 项目: nbailey/quark
 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))
示例#2
0
文件: tests.py 项目: ochan1/quark
 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))
示例#3
0
文件: tests.py 项目: nbailey/quark
    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))
示例#4
0
文件: tests.py 项目: ochan1/quark
    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))
示例#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()
示例#6
0
文件: tests.py 项目: nbailey/quark
    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()
示例#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()
示例#8
0
文件: tests.py 项目: nbailey/quark
    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()
示例#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))
示例#10
0
文件: tests.py 项目: nbailey/quark
    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))
示例#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))
示例#12
0
文件: tests.py 项目: nbailey/quark
    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))
示例#13
0
 def tearDown(self):
     if username_exists(self.username):
         self.assertTrue(delete_user(self.username))
示例#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)
示例#15
0
文件: models.py 项目: nbailey/quark
 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)
示例#16
0
文件: tests.py 项目: nbailey/quark
 def tearDown(self):
     if username_exists(self.username):
         self.assertTrue(delete_user(self.username))