def setUp(self): self.ion = IonAuth() self.user = UserFactory.build( is_active=True ) self.user.password = self.ion.password_hash('123') self.active_user = UserFactory(is_active=True) self.inactive_user = UserFactory(is_active=False)
class IonTest(TestCase): '''Authorization tests''' def setUp(self): self.ion = IonAuth() self.user = UserFactory.build( is_active=True ) self.user.password = self.ion.password_hash('123') self.active_user = UserFactory(is_active=True) self.inactive_user = UserFactory(is_active=False) def tearDown(self): self.active_user.delete() self.inactive_user.delete() self.user = None def test_ion_auth(self): self.assertEquals(40, len(self.user.password)) def test_password_rewrite(self): ''' If user enters correct ion password, backend will rehash password to django-specific password hash. ''' self.user.save() u2 = self.ion.authenticate(username=self.user.email, password='******') self.assertIsNotNone(u2) self.assertFalse(u2.is_anonymous()) self.assertNotEqual(self.user.password, u2.password) self.user.delete() def test_inactive_user(self): u2 = self.ion.authenticate( username=self.inactive_user.email, password='******') self.assertIsNone(u2) def test_unexists_user(self): u2 = self.ion.authenticate(username="******", password='******') self.assertIsNone(u2) def test_wrong_password(self): u2 = self.ion.authenticate( username=self.active_user.email, password='******') self.assertIsNone(u2)