forked from GithubBackups/healthchecks
Merge pull request #11 from BetterWorks/resilience
make welcome code logic resilient
This commit is contained in:
commit
f08221a1db
@ -1,4 +1,5 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
from hc.api.models import Check
|
||||||
|
|
||||||
|
|
||||||
class BasicsTestCase(TestCase):
|
class BasicsTestCase(TestCase):
|
||||||
@ -6,3 +7,15 @@ class BasicsTestCase(TestCase):
|
|||||||
def test_it_shows_welcome(self):
|
def test_it_shows_welcome(self):
|
||||||
r = self.client.get("/")
|
r = self.client.get("/")
|
||||||
self.assertContains(r, "Get Notified", status_code=200)
|
self.assertContains(r, "Get Notified", status_code=200)
|
||||||
|
|
||||||
|
def test_welcome_code(self):
|
||||||
|
r = self.client.get("/")
|
||||||
|
code = self.client.session["welcome_code"]
|
||||||
|
assert Check.objects.filter(code=code).exists()
|
||||||
|
|
||||||
|
self.client.session["welcome_code"] = "x"
|
||||||
|
r = self.client.get("/")
|
||||||
|
code = self.client.session["welcome_code"]
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert code != "x"
|
||||||
|
assert Check.objects.filter(code=code).exists()
|
||||||
|
@ -27,14 +27,16 @@ def index(request):
|
|||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
return redirect("hc-checks")
|
return redirect("hc-checks")
|
||||||
|
|
||||||
if "welcome_code" not in request.session:
|
check = None
|
||||||
|
if "welcome_code" in request.session:
|
||||||
|
code = request.session["welcome_code"]
|
||||||
|
check = Check.objects.filter(code=code).first()
|
||||||
|
|
||||||
|
if check is None:
|
||||||
check = Check()
|
check = Check()
|
||||||
check.save()
|
check.save()
|
||||||
code = str(check.code)
|
code = str(check.code)
|
||||||
request.session["welcome_code"] = code
|
request.session["welcome_code"] = code
|
||||||
else:
|
|
||||||
code = request.session["welcome_code"]
|
|
||||||
check = Check.objects.get(code=code)
|
|
||||||
|
|
||||||
ctx = {
|
ctx = {
|
||||||
"page": "welcome",
|
"page": "welcome",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user