def test_only_re_send_the_validation_code_after_15_minutes_when_last_sent( self): captcha = RegisterViewTest.captcha_through() self.client.post("/user/register/", data={ "email": "*****@*****.**", "password": "******", "captcha_0": captcha.hashkey, "captcha_1": captcha.response, }) record = EmailVerify.objects.get(email="*****@*****.**") register_time = minutes_ago(datetime.now(), 31) record.send_time = register_time record.save() self.client.post("/user/reactive/", data={ "email": "*****@*****.**", }) record = EmailVerify.objects.filter(email="*****@*****.**") self.assertEqual(record.count(), 2) activate_url = generate_verify_url(record[1].code) resp = self.client.get(activate_url) self.assertTemplateUsed(resp, "login.html") user = UserProfile.objects.get(email="*****@*****.**") self.assertTrue(user.is_active)
def test_activate_unactive_user(self): captcha = RegisterViewTest.captcha_through() self.client.post("/user/register/", data={ "email": "*****@*****.**", "password": "******", "captcha_0": captcha.hashkey, "captcha_1": captcha.response, }) record = EmailVerify.objects.get(email="*****@*****.**") activate_url = generate_verify_url(record.code) resp = self.client.get(activate_url) self.assertTemplateUsed(resp, "login.html") user = UserProfile.objects.get(email="*****@*****.**") self.assertTrue(user.is_active)
def test_delete_the_validation_code_once_it_has_been_verified(self): captcha = RegisterViewTest.captcha_through() self.client.post("/user/register/", data={ "email": "*****@*****.**", "password": "******", "captcha_0": captcha.hashkey, "captcha_1": captcha.response, }) record = EmailVerify.objects.get(email="*****@*****.**") activate_url = generate_verify_url(record.code) resp = self.client.get(activate_url) self.assertTemplateUsed(resp, "login.html") self.assertEqual(EmailVerify.objects.count(), 0) record = EmailVerify.objects.filter(email="*****@*****.**") self.assertEqual(len(record), 0)
def test_validation_code_could_been_out_of_date(self): captcha = RegisterViewTest.captcha_through() self.client.post("/user/register/", data={ "email": "*****@*****.**", "password": "******", "captcha_0": captcha.hashkey, "captcha_1": captcha.response, }) record = EmailVerify.objects.get(email="*****@*****.**") register_time = minutes_ago(datetime.now(), 31) record.send_time = register_time record.save() activate_url = generate_verify_url(record.code) resp = self.client.get(activate_url) self.assertTemplateUsed(resp, "verify.html") self.assertContains(resp, "the validation code is out of date") user = UserProfile.objects.get(email="*****@*****.**") self.assertFalse(user.is_active)
def test_delete_the_validation_code_once_it_has_been_expired(self): captcha = RegisterViewTest.captcha_through() self.client.post("/user/register/", data={ "email": "*****@*****.**", "password": "******", "captcha_0": captcha.hashkey, "captcha_1": captcha.response, }) record = EmailVerify.objects.get(email="*****@*****.**") register_time = minutes_ago(datetime.now(), 31) record.send_time = register_time record.save() activate_url = generate_verify_url(record.code) resp = self.client.get(activate_url) self.assertTemplateUsed(resp, "verify.html") self.assertContains(resp, "the validation code is out of date") self.assertEqual(EmailVerify.objects.count(), 0) record = EmailVerify.objects.filter(email="*****@*****.**") self.assertEqual(len(record), 0)
def test_resend_a_validation_code_request_by_an_activated_user_should_return_wrong( self): captcha = RegisterViewTest.captcha_through() self.client.post("/user/register/", data={ "email": "*****@*****.**", "password": "******", "captcha_0": captcha.hashkey, "captcha_1": captcha.response, }) record = EmailVerify.objects.get(email="*****@*****.**") activate_url = generate_verify_url(record.code) self.client.get(activate_url) resp = self.client.post("/user/reactive/", data={ "email": "*****@*****.**", }) self.assertTemplateUsed(resp, "verify.html") self.assertContains(resp, "email address already been activated") user = UserProfile.objects.get(email="*****@*****.**") self.assertTrue(user.is_active)
def test_activate_unactive_user_with_a_wrong_active_code(self): activate_url = generate_verify_url("Hfjsdlfeur") resp = self.client.get(activate_url) self.assertTemplateUsed(resp, "verify.html") self.assertContains(resp, "cannot activate user, active code is wrong")
def test_generate_register_mail(self): code = generate_random_code() url = generate_verify_url(code) self.assertIn(code, url) self.assertEqual(url, server_url + "user/activate/" + code + '/')