@ -0,0 +1,34 @@ | |||
from hc.api.models import Check | |||
from hc.test import BaseTestCase | |||
class PauseTestCase(BaseTestCase): | |||
def test_it_works(self): | |||
check = Check(user=self.alice, status="up") | |||
check.save() | |||
url = "/api/v1/checks/%s/pause" % check.code | |||
r = self.client.post(url, "", content_type="application/json", | |||
HTTP_X_API_KEY="abc") | |||
self.assertEqual(r.status_code, 200) | |||
check.refresh_from_db() | |||
self.assertEqual(check.status, "paused") | |||
def test_it_only_allows_post(self): | |||
url = "/api/v1/checks/1659718b-21ad-4ed1-8740-43afc6c41524/pause" | |||
r = self.client.get(url, HTTP_X_API_KEY="abc") | |||
self.assertEqual(r.status_code, 405) | |||
def test_it_validates_ownership(self): | |||
check = Check(user=self.bob, status="up") | |||
check.save() | |||
url = "/api/v1/checks/%s/pause" % check.code | |||
r = self.client.post(url, "", content_type="application/json", | |||
HTTP_X_API_KEY="abc") | |||
self.assertEqual(r.status_code, 400) |
@ -0,0 +1,20 @@ | |||
from hc.api.models import Check | |||
from hc.test import BaseTestCase | |||
class PauseTestCase(BaseTestCase): | |||
def setUp(self): | |||
super(PauseTestCase, self).setUp() | |||
self.check = Check(user=self.alice, status="up") | |||
self.check.save() | |||
def test_it_pauses(self): | |||
url = "/checks/%s/pause/" % self.check.code | |||
self.client.login(username="[email protected]", password="password") | |||
r = self.client.post(url) | |||
self.assertRedirects(r, "/checks/") | |||
self.check.refresh_from_db() | |||
self.assertEqual(self.check.status, "paused") |
@ -1,34 +1,43 @@ | |||
from django.conf.urls import url | |||
from django.conf.urls import include, url | |||
from hc.front import views | |||
check_urls = [ | |||
url(r'^name/$', views.update_name, name="hc-update-name"), | |||
url(r'^timeout/$', views.update_timeout, name="hc-update-timeout"), | |||
url(r'^pause/$', views.pause, name="hc-pause"), | |||
url(r'^remove/$', views.remove_check, name="hc-remove-check"), | |||
url(r'^log/$', views.log, name="hc-log"), | |||
] | |||
channel_urls = [ | |||
url(r'^$', views.channels, name="hc-channels"), | |||
url(r'^add/$', views.add_channel, name="hc-add-channel"), | |||
url(r'^add_email/$', views.add_email, name="hc-add-email"), | |||
url(r'^add_webhook/$', views.add_webhook, name="hc-add-webhook"), | |||
url(r'^add_pd/$', views.add_pd, name="hc-add-pd"), | |||
url(r'^add_slack/$', views.add_slack, name="hc-add-slack"), | |||
url(r'^add_slack_btn/$', views.add_slack_btn, name="hc-add-slack-btn"), | |||
url(r'^add_hipchat/$', views.add_hipchat, name="hc-add-hipchat"), | |||
url(r'^add_pushbullet/$', views.add_pushbullet, name="hc-add-pushbullet"), | |||
url(r'^add_pushover/$', views.add_pushover, name="hc-add-pushover"), | |||
url(r'^add_victorops/$', views.add_victorops, name="hc-add-victorops"), | |||
url(r'^([\w-]+)/checks/$', views.channel_checks, name="hc-channel-checks"), | |||
url(r'^([\w-]+)/remove/$', views.remove_channel, name="hc-remove-channel"), | |||
url(r'^([\w-]+)/verify/([\w-]+)/$', views.verify_email, | |||
name="hc-verify-email"), | |||
] | |||
urlpatterns = [ | |||
url(r'^$', views.index, name="hc-index"), | |||
url(r'^checks/$', views.my_checks, name="hc-checks"), | |||
url(r'^checks/add/$', views.add_check, name="hc-add-check"), | |||
url(r'^checks/([\w-]+)/name/$', views.update_name, name="hc-update-name"), | |||
url(r'^checks/([\w-]+)/timeout/$', views.update_timeout, name="hc-update-timeout"), | |||
url(r'^checks/([\w-]+)/remove/$', views.remove_check, name="hc-remove-check"), | |||
url(r'^checks/([\w-]+)/log/$', views.log, name="hc-log"), | |||
url(r'^docs/$', views.docs, name="hc-docs"), | |||
url(r'^docs/api/$', views.docs_api, name="hc-docs-api"), | |||
url(r'^about/$', views.about, name="hc-about"), | |||
url(r'^privacy/$', views.privacy, name="hc-privacy"), | |||
url(r'^terms/$', views.terms, name="hc-terms"), | |||
url(r'^integrations/$', views.channels, name="hc-channels"), | |||
url(r'^integrations/add/$', views.add_channel, name="hc-add-channel"), | |||
url(r'^integrations/add_email/$', views.add_email, name="hc-add-email"), | |||
url(r'^integrations/add_webhook/$', views.add_webhook, name="hc-add-webhook"), | |||
url(r'^integrations/add_pd/$', views.add_pd, name="hc-add-pd"), | |||
url(r'^integrations/add_slack/$', views.add_slack, name="hc-add-slack"), | |||
url(r'^integrations/add_slack_btn/$', views.add_slack_btn, name="hc-add-slack-btn"), | |||
url(r'^integrations/add_hipchat/$', views.add_hipchat, name="hc-add-hipchat"), | |||
url(r'^integrations/add_pushbullet/$', views.add_pushbullet, name="hc-add-pushbullet"), | |||
url(r'^integrations/add_pushover/$', views.add_pushover, name="hc-add-pushover"), | |||
url(r'^integrations/add_victorops/$', views.add_victorops, name="hc-add-victorops"), | |||
url(r'^integrations/([\w-]+)/checks/$', views.channel_checks, name="hc-channel-checks"), | |||
url(r'^integrations/([\w-]+)/remove/$', views.remove_channel, name="hc-remove-channel"), | |||
url(r'^integrations/([\w-]+)/verify/([\w-]+)/$', | |||
views.verify_email, name="hc-verify-email"), | |||
url(r'^$', views.index, name="hc-index"), | |||
url(r'^checks/$', views.my_checks, name="hc-checks"), | |||
url(r'^checks/add/$', views.add_check, name="hc-add-check"), | |||
url(r'^checks/([\w-]+)/', include(check_urls)), | |||
url(r'^integrations/', include(channel_urls)), | |||
url(r'^docs/$', views.docs, name="hc-docs"), | |||
url(r'^docs/api/$', views.docs_api, name="hc-docs-api"), | |||
url(r'^about/$', views.about, name="hc-about"), | |||
url(r'^privacy/$', views.privacy, name="hc-privacy"), | |||
url(r'^terms/$', views.terms, name="hc-terms"), | |||
] |
@ -0,0 +1,3 @@ | |||
<div class="highlight"><pre><span></span>curl {{ SITE_ROOT }}/api/v1/checks/0c8983c9-9d73-446f-adb5-0641fdacc9d4/pause <span class="se">\</span> | |||
--request POST --header <span class="s2">"X-Api-Key: your-api-key"</span> | |||
</pre></div> |
@ -0,0 +1,2 @@ | |||
curl SITE_ROOT/api/v1/checks/0c8983c9-9d73-446f-adb5-0641fdacc9d4/pause \ | |||
--request POST --header "X-Api-Key: your-api-key" |
@ -0,0 +1,13 @@ | |||
<div class="highlight"><pre><span></span><span class="p">{</span> | |||
<span class="nt">"grace"</span><span class="p">:</span> <span class="mi">60</span><span class="p">,</span> | |||
<span class="nt">"last_ping"</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> | |||
<span class="nt">"n_pings"</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> | |||
<span class="nt">"name"</span><span class="p">:</span> <span class="s2">"Backups"</span><span class="p">,</span> | |||
<span class="nt">"next_ping"</span><span class="p">:</span> <span class="kc">null</span><span class="p">,</span> | |||
<span class="nt">"pause_url"</span><span class="p">:</span> <span class="s2">"{{ SITE_ROOT }}/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pause"</span><span class="p">,</span> | |||
<span class="nt">"ping_url"</span><span class="p">:</span> <span class="s2">"{{ PING_ENDPOINT }}f618072a-7bde-4eee-af63-71a77c5723bc"</span><span class="p">,</span> | |||
<span class="nt">"status"</span><span class="p">:</span> <span class="s2">"paused"</span><span class="p">,</span> | |||
<span class="nt">"tags"</span><span class="p">:</span> <span class="s2">"prod www"</span><span class="p">,</span> | |||
<span class="nt">"timeout"</span><span class="p">:</span> <span class="mi">3600</span> | |||
<span class="p">}</span> | |||
</pre></div> |
@ -0,0 +1,12 @@ | |||
{ | |||
"grace": 60, | |||
"last_ping": null, | |||
"n_pings": 0, | |||
"name": "Backups", | |||
"next_ping": null, | |||
"pause_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pause", | |||
"ping_url": "PING_ENDPOINTf618072a-7bde-4eee-af63-71a77c5723bc", | |||
"status": "paused", | |||
"tags": "prod www", | |||
"timeout": 3600 | |||
} |