forked from GithubBackups/healthchecks
ping is csrf exempt.
This commit is contained in:
parent
a099a498da
commit
965599c8eb
@ -4,11 +4,9 @@ from django.conf import settings
|
|||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
from django.contrib.auth import login as auth_login, logout as auth_logout
|
from django.contrib.auth import login as auth_login, logout as auth_logout
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.mail import send_mail
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http import HttpResponseBadRequest
|
from django.http import HttpResponseBadRequest
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.template import loader
|
|
||||||
|
|
||||||
from hc.accounts.forms import EmailForm
|
from hc.accounts.forms import EmailForm
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from django.contrib.auth.models import User
|
from django.test import Client, TestCase
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
|
|
||||||
@ -7,10 +6,7 @@ from hc.api.models import Check
|
|||||||
class PingTestCase(TestCase):
|
class PingTestCase(TestCase):
|
||||||
|
|
||||||
def test_it_works(self):
|
def test_it_works(self):
|
||||||
user = User(username="jdoe")
|
check = Check()
|
||||||
user.save()
|
|
||||||
|
|
||||||
check = Check(user=user)
|
|
||||||
check.save()
|
check.save()
|
||||||
|
|
||||||
r = self.client.get("/ping/%s/" % check.code)
|
r = self.client.get("/ping/%s/" % check.code)
|
||||||
@ -18,3 +14,11 @@ class PingTestCase(TestCase):
|
|||||||
|
|
||||||
same_check = Check.objects.get(code=check.code)
|
same_check = Check.objects.get(code=check.code)
|
||||||
assert same_check.status == "up"
|
assert same_check.status == "up"
|
||||||
|
|
||||||
|
def test_post_works(self):
|
||||||
|
check = Check()
|
||||||
|
check.save()
|
||||||
|
|
||||||
|
csrf_client = Client(enforce_csrf_checks=True)
|
||||||
|
r = csrf_client.post("/ping/%s/" % check.code)
|
||||||
|
assert r.status_code == 200
|
||||||
|
@ -3,10 +3,12 @@ import json
|
|||||||
from django.contrib.humanize.templatetags.humanize import naturaltime
|
from django.contrib.humanize.templatetags.humanize import naturaltime
|
||||||
from django.http import HttpResponse, HttpResponseBadRequest
|
from django.http import HttpResponse, HttpResponseBadRequest
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
def ping(request, code):
|
def ping(request, code):
|
||||||
try:
|
try:
|
||||||
check = Check.objects.get(code=code)
|
check = Check.objects.get(code=code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user