forked from GithubBackups/healthchecks
Tests for hc.accounts
This commit is contained in:
parent
52c6beccef
commit
364e7ebec9
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
0
hc/accounts/tests/__init__.py
Normal file
0
hc/accounts/tests/__init__.py
Normal file
17
hc/accounts/tests/test_check_token.py
Normal file
17
hc/accounts/tests/test_check_token.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class CheckTokenTestCase(TestCase):
|
||||||
|
|
||||||
|
def test_it_redirects(self):
|
||||||
|
alice = User(username="alice")
|
||||||
|
alice.set_password("secret-token")
|
||||||
|
alice.save()
|
||||||
|
|
||||||
|
r = self.client.get("/accounts/check_token/alice/secret-token/")
|
||||||
|
assert r.status_code == 302
|
||||||
|
|
||||||
|
# After login, password should be unusable
|
||||||
|
alice_again = User.objects.get(username="alice")
|
||||||
|
assert not alice_again.has_usable_password()
|
32
hc/accounts/tests/test_login.py
Normal file
32
hc/accounts/tests/test_login.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.core import mail
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from hc.api.models import Check
|
||||||
|
|
||||||
|
|
||||||
|
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 = {"email": "alice@example.org"}
|
||||||
|
|
||||||
|
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)
|
||||||
|
self.assertEqual(mail.outbox[0].subject, 'Log in to healthchecks.io')
|
||||||
|
|
||||||
|
# And check should be associated with the new user
|
||||||
|
check_again = Check.objects.get(code=check.code)
|
||||||
|
assert check_again.user
|
Loading…
x
Reference in New Issue
Block a user