Пример #1
0
 def test_get_or_create(self):
     backend = NOCLocalBackend()
     # Get existing
     r = backend.get_or_create_db_user("local_test",
                                       first_name="Local",
                                       last_name="Test")
     self.assertNotEqual(r, None)
     self.assertEqual(r.username, "local_test")
     self.assertEqual(r.is_active, True)
     self.assertEqual(r.is_superuser, False)
     self.assertEqual(r.first_name, "Local")
     self.assertEqual(r.last_name, "Test")
     # Create
     r = backend.get_or_create_db_user("local_test1",
                                       first_name="New",
                                       last_name="User",
                                       is_active=True,
                                       is_superuser=True,
                                       email="*****@*****.**")
     self.assertNotEqual(r, None)
     self.assertEqual(r.username, "local_test1")
     self.assertEqual(r.is_active, True)
     self.assertEqual(r.is_superuser, True)
     self.assertEqual(r.first_name, "New")
     self.assertEqual(r.last_name, "User")
     self.assertEqual(r.email, "*****@*****.**")
     r.delete()
Пример #2
0
 def test_get_user(self):
     backend = NOCLocalBackend()
     user = backend.User.objects.get(username="******")
     r = backend.get_user(user.id)
     self.assertNotEqual(r, None)
     self.assertEqual(r.username, "local_test")
     self.assertEqual(r.is_active, True)
     self.assertEqual(r.is_superuser, False)
     r = backend.get_user(1278221)
     self.assertEqual(r, None)
Пример #3
0
 def test_authenticate(self):
     backend = NOCLocalBackend()
     # Valid user, valid password
     r = backend.authenticate(username="******", password="******")
     self.assertNotEqual(r, None)
     self.assertEqual(r.username, "local_test")
     self.assertEqual(r.is_active, True)
     self.assertEqual(r.is_superuser, False)
     # Valid user, invalid password
     r = backend.authenticate(username="******", password="******")
     self.assertEqual(r, None)
     # Invalid user, valid password
     r = backend.authenticate(username="******", password="******")
     self.assertEqual(r, None)
     # Invalid user, invalid password
     r = backend.authenticate(username="******",
                              password="******")
     self.assertEqual(r, None)
Пример #4
0
 def test_change_credentials(self):
     backend = NOCLocalBackend()
     user = backend.User.objects.get(username="******")
     # Failed attempt
     with self.assertRaises(ValueError):
         backend.change_credentials(user,
                                    old_password="******",
                                    new_password="******",
                                    retype_password="******")
     r = backend.authenticate(username="******", password="******")
     self.assertNotEqual(r, None)
     r = backend.authenticate(username="******", password="******")
     self.assertEqual(r, None)
     # Failed attempt #2
     with self.assertRaises(ValueError):
         backend.change_credentials(user,
                                    old_password="******",
                                    new_password="******",
                                    retype_password="******")
     r = backend.authenticate(username="******", password="******")
     self.assertNotEqual(r, None)
     r = backend.authenticate(username="******", password="******")
     self.assertEqual(r, None)
     # Success
     backend.change_credentials(user,
                                old_password="******",
                                new_password="******",
                                retype_password="******")
     r = backend.authenticate(username="******", password="******")
     self.assertEqual(r, None)
     r = backend.authenticate(username="******", password="******")
     self.assertNotEqual(r, None)