def test_resign_confirm_with_bad_token(self): """Ensures that get request with bad token and uidb36 to /resign_confirm/ is considered invalid link """ bad_req = self.request_factory.get('/resign_confirm/NO-OP/') bad_resp = resign_confirm(bad_req, 'NO', 'OP') self.assertEquals(bad_resp.status_code, 200) self.assertEquals(bad_resp.template_name, 'registration/resign_confirm.html') self.assertIsNone(bad_resp.context_data['form']) self.assertFalse(bad_resp.context_data['validlink'])
def test_resign_confirm_with_over_maxlength_reason(self): """Ensures that post request with over maxlength resign_reason to /resign_confirm/ is considered invalid form """ bad_req = self.request_factory.post( '/resign_confirm/{0}-{1}/'.format(self.uidb36, self.token), {'resign_reason': self.resign_reason + 'a'} ) bad_resp = resign_confirm(bad_req, self.uidb36, self.token) self.assertEquals(bad_resp.status_code, 200) self.assertEquals(bad_resp.template_name, 'registration/resign_confirm.html') self.assertIsNotNone(bad_resp.context_data['form']) # assert that the returned form is invalid self.assertFalse(bad_resp.context_data['form'].is_valid())
def test_resign_confirm_with_good_token(self): """Ensures that get request with good token and uidb36 to /resign_confirm/ is considered valid link """ good_req = self.request_factory.get('/resign_confirm/{0}-{1}/'.format(self.uidb36, self.token)) good_resp = resign_confirm(good_req, self.uidb36, self.token) self.assertEquals(good_resp.status_code, 200) self.assertEquals(good_resp.template_name, 'registration/resign_confirm.html') self.assertIsNotNone(good_resp.context_data['form']) self.assertTrue(good_resp.context_data['validlink']) # assert that the user's UserStanding record is not created yet self.assertRaises( UserStanding.DoesNotExist, UserStanding.objects.get, user=self.user)
def test_resign_confirm_with_good_reason(self, logout_user): """Ensures that post request with good resign_reason to /resign_confirm/ makes the user logged out and disabled """ good_req = self.request_factory.post('/resign_confirm/{0}-{1}/'.format(self.uidb36, self.token), {'resign_reason': self.resign_reason}) good_resp = resign_confirm(good_req, self.uidb36, self.token) self.assertTrue(logout_user.called) self.assertEquals(good_resp.status_code, 200) self.assertEquals(good_resp.template_name, 'registration/resign_complete.html') # assert that the user is active self.user = User.objects.get(pk=self.user.pk) self.assertTrue(self.user.is_active) # assert that the user's account_status is disabled user_account = UserStanding.objects.get(user=self.user) self.assertTrue(user_account.account_status, UserStanding.ACCOUNT_DISABLED) self.assertTrue(user_account.resign_reason, self.resign_reason)