|
|
@ -10,13 +10,6 @@ from django.conf import settings |
|
|
|
class LoginTestCase(TestCase): |
|
|
|
|
|
|
|
def test_it_sends_link(self): |
|
|
|
check = Check() |
|
|
|
check.save() |
|
|
|
|
|
|
|
session = self.client.session |
|
|
|
session["welcome_code"] = str(check.code) |
|
|
|
session.save() |
|
|
|
|
|
|
|
form = {"identity": "[email protected]"} |
|
|
|
|
|
|
|
r = self.client.post("/accounts/login/", form) |
|
|
@ -31,34 +24,14 @@ class LoginTestCase(TestCase): |
|
|
|
self.assertEqual(mail.outbox[0].subject, subject) |
|
|
|
|
|
|
|
# And check should be associated with the new user |
|
|
|
check_again = Check.objects.get(code=check.code) |
|
|
|
assert check_again.user |
|
|
|
check = Check.objects.get() |
|
|
|
self.assertEqual(check.name, "My First Check") |
|
|
|
|
|
|
|
def test_it_pops_bad_link_from_session(self): |
|
|
|
self.client.session["bad_link"] = True |
|
|
|
self.client.get("/accounts/login/") |
|
|
|
assert "bad_link" not in self.client.session |
|
|
|
|
|
|
|
def test_it_handles_missing_welcome_check(self): |
|
|
|
|
|
|
|
# This check does not exist in database, |
|
|
|
# but login should still work. |
|
|
|
session = self.client.session |
|
|
|
session["welcome_code"] = "00000000-0000-0000-0000-000000000000" |
|
|
|
session.save() |
|
|
|
|
|
|
|
form = {"identity": "[email protected]"} |
|
|
|
|
|
|
|
r = self.client.post("/accounts/login/", form) |
|
|
|
assert r.status_code == 302 |
|
|
|
|
|
|
|
# An user should have been created |
|
|
|
self.assertEqual(User.objects.count(), 1) |
|
|
|
|
|
|
|
# And email sent |
|
|
|
self.assertEqual(len(mail.outbox), 1) |
|
|
|
subject = "Log in to %s" % settings.SITE_NAME |
|
|
|
self.assertEqual(mail.outbox[0].subject, subject) |
|
|
|
|
|
|
|
@override_settings(REGISTRATION_OPEN=False) |
|
|
|
def test_it_obeys_registration_open(self): |
|
|
|