Beispiel #1
0
class BcryptBackendTest(TestCase):

    fixtures = ['users_test_data.json']

    def setUp(self):
        self.backend = BcryptBackend()

    def test_authenticate_without_username(self):
        # Test that method interrupts if username is None.
        user = self.backend.authenticate(password='******')
        self.assertFalse(user)

    def test_authenticate_without_password(self):
        # Test that method interrupts if password is None.
        user = self.backend.authenticate(username='******')
        self.assertFalse(user)

    def test_unsuccessful_authenticate(self):
        # Test that method returns None if authenticate is unsuccessful.
        data = {
            'username': '******',
            'password': '******'
        }
        user = self.backend.authenticate(**data)
        self.assertFalse(user)

    def test_successful_authenticate(self):
        # Test authenticate method of backend with bcrypt password.
        data = {
            'username': '******',
            'password': '******'
        }
        user = self.backend.authenticate(**data)
        self.assertEqual(user.username, data['username'])

    def test_successful_authenticate_not_bcrypt(self):
        # Test authenticate method of backend with none bcrypt password.
        data = {
            'username': '******',
            'password': '******'
        }
        user = self.backend.authenticate(**data)
        self.assertEqual(user.username, data['username'])

    def test_get_existing_user(self):
        # Test get existing user.
        user_id = 1
        user = self.backend.get_user(user_id)
        self.assertEqual(user.username, 'testuser')

    def test_get_none_existing_user(self):
        # Test get none existing user.
        user_id = 99
        user = self.backend.get_user(user_id)
        self.assertFalse(user)
Beispiel #2
0
 def setUp(self):
     self.backend = BcryptBackend()