@ -0,0 +1,18 @@ | |||||
# Generated by Django 3.0.4 on 2020-06-02 07:35 | |||||
from django.db import migrations, models | |||||
class Migration(migrations.Migration): | |||||
dependencies = [ | |||||
('api', '0070_auto_20200411_1310'), | |||||
] | |||||
operations = [ | |||||
migrations.AddField( | |||||
model_name='check', | |||||
name='manual_resume', | |||||
field=models.NullBooleanField(default=False), | |||||
), | |||||
] |
@ -12,12 +12,16 @@ class FilteringRulesTestCase(BaseTestCase): | |||||
def test_it_works(self): | def test_it_works(self): | ||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
r = self.client.post(self.url, data={"subject": "SUCCESS", "methods": "POST"}) | |||||
r = self.client.post( | |||||
self.url, | |||||
data={"subject": "SUCCESS", "methods": "POST", "manual_resume": "1"}, | |||||
) | |||||
self.assertRedirects(r, self.redirect_url) | self.assertRedirects(r, self.redirect_url) | ||||
self.check.refresh_from_db() | self.check.refresh_from_db() | ||||
self.assertEqual(self.check.subject, "SUCCESS") | self.assertEqual(self.check.subject, "SUCCESS") | ||||
self.assertEqual(self.check.methods, "POST") | self.assertEqual(self.check.methods, "POST") | ||||
self.assertTrue(self.check.manual_resume) | |||||
def test_it_clears_method(self): | def test_it_clears_method(self): | ||||
self.check.method = "POST" | self.check.method = "POST" | ||||
@ -29,3 +33,25 @@ class FilteringRulesTestCase(BaseTestCase): | |||||
self.check.refresh_from_db() | self.check.refresh_from_db() | ||||
self.assertEqual(self.check.methods, "") | self.assertEqual(self.check.methods, "") | ||||
def test_it_clears_subject(self): | |||||
self.check.subject = "SUCCESS" | |||||
self.check.save() | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url, data={"methods": ""}) | |||||
self.assertRedirects(r, self.redirect_url) | |||||
self.check.refresh_from_db() | |||||
self.assertEqual(self.check.subject, "") | |||||
def test_it_clears_manual_resume_flag(self): | |||||
self.check.manual_resume = True | |||||
self.check.save() | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url, data={}) | |||||
self.assertRedirects(r, self.redirect_url) | |||||
self.check.refresh_from_db() | |||||
self.assertFalse(self.check.manual_resume) |
@ -10,7 +10,7 @@ class PauseTestCase(BaseTestCase): | |||||
super(PauseTestCase, self).setUp() | super(PauseTestCase, self).setUp() | ||||
self.check = Check.objects.create(project=self.project, status="up") | self.check = Check.objects.create(project=self.project, status="up") | ||||
self.url = "/checks/%s/pause/" % self.check.code | self.url = "/checks/%s/pause/" % self.check.code | ||||
self.redirect_url = "/projects/%s/checks/" % self.project.code | |||||
self.redirect_url = "/checks/%s/details/" % self.check.code | |||||
def test_it_pauses(self): | def test_it_pauses(self): | ||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
@ -0,0 +1,28 @@ | |||||
from hc.api.models import Check | |||||
from hc.test import BaseTestCase | |||||
class ResumeTestCase(BaseTestCase): | |||||
def setUp(self): | |||||
super(ResumeTestCase, self).setUp() | |||||
self.check = Check.objects.create(project=self.project, status="paused") | |||||
self.url = "/checks/%s/resume/" % self.check.code | |||||
self.redirect_url = "/checks/%s/details/" % self.check.code | |||||
def test_it_resumes(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url) | |||||
self.assertRedirects(r, self.redirect_url) | |||||
self.check.refresh_from_db() | |||||
self.assertEqual(self.check.status, "new") | |||||
def test_it_rejects_get(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get(self.url) | |||||
self.assertEqual(r.status_code, 405) | |||||
def test_it_allows_cross_team_access(self): | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.post(self.url) | |||||
self.assertRedirects(r, self.redirect_url) |
@ -50,3 +50,15 @@ class StatusSingleTestCase(BaseTestCase): | |||||
self.client.login(username="[email protected]", password="password") | self.client.login(username="[email protected]", password="password") | ||||
r = self.client.get("/checks/%s/status/" % self.check.code) | r = self.client.get("/checks/%s/status/" % self.check.code) | ||||
self.assertEqual(r.status_code, 200) | self.assertEqual(r.status_code, 200) | ||||
def test_it_handles_manual_resume(self): | |||||
self.check.status = "paused" | |||||
self.check.manual_resume = True | |||||
self.check.save() | |||||
self.client.login(username="[email protected]", password="password") | |||||
r = self.client.get("/checks/%s/status/" % self.check.code) | |||||
doc = r.json() | |||||
self.assertEqual(doc["status"], "paused") | |||||
self.assertTrue("will ignore pings until resumed" in doc["status_text"]) |