def test_resign_by_nonexist_email_user(self): """Now test the exception cases with of resign called with invalid email.""" bad_email_req = self.request_factory.post('/resign/', {'email': self.user.email + "makeItFail"}) bad_email_resp = resign(bad_email_req) # Note: even if the email is bad, we return a successful response code # This prevents someone potentially trying to "brute-force" find out which emails are and aren't registered with edX self.assertEquals(bad_email_resp.status_code, 200) obj = json.loads(bad_email_resp.content) self.assertEquals(obj, { 'success': True, })
def test_resign_email(self, send_email): """Tests contents of resign email""" good_req = self.request_factory.post('/resign/', {'email': self.user.email}) good_resp = resign(good_req) self.assertEquals(good_resp.status_code, 200) obj = json.loads(good_resp.content) self.assertEquals(obj, { 'success': True, }) ((subject, msg, from_addr, to_addrs), sm_kwargs) = send_email.call_args #self.assertIn("Resignation from", subject) #self.assertIn("You're receiving this e-mail because you requested a resignation", msg) self.assertEquals(from_addr, settings.DEFAULT_FROM_EMAIL) self.assertEquals(len(to_addrs), 1) self.assertIn(self.user.email, to_addrs) # test that the user is not active (as well as test_reset_password_email) self.user = User.objects.get(pk=self.user.pk) self.assertFalse(self.user.is_active) url_match = re.search(r'resign_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/', msg).groupdict() self.assertEquals(url_match['uidb36'], self.uidb36) self.assertEquals(url_match['token'], self.token)