From 7480eca2a5ad684417f6c82da266d31843031a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Fri, 4 Jan 2019 11:24:53 +0200 Subject: [PATCH] Add Ping.kind field --- CHANGELOG.md | 1 + hc/api/migrations/0050_ping_kind.py | 18 +++++++++++++++ hc/api/migrations/0051_auto_20190104_0908.py | 24 ++++++++++++++++++++ hc/api/models.py | 11 +++++++-- hc/api/tests/test_ping.py | 3 +++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 hc/api/migrations/0050_ping_kind.py create mode 100644 hc/api/migrations/0051_auto_20190104_0908.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 981803c5..4644a09b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Improvements - Database schema: set Check.user to not null - Database schema: add uniqueness constraint to Check.code +- Database schema: add Ping.kind field ## 1.4.0 - 2018-12-25 diff --git a/hc/api/migrations/0050_ping_kind.py b/hc/api/migrations/0050_ping_kind.py new file mode 100644 index 00000000..132b343d --- /dev/null +++ b/hc/api/migrations/0050_ping_kind.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.4 on 2019-01-04 09:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0049_auto_20190102_0743'), + ] + + operations = [ + migrations.AddField( + model_name='ping', + name='kind', + field=models.CharField(blank=True, max_length=6, null=True), + ), + ] diff --git a/hc/api/migrations/0051_auto_20190104_0908.py b/hc/api/migrations/0051_auto_20190104_0908.py new file mode 100644 index 00000000..f42e70fe --- /dev/null +++ b/hc/api/migrations/0051_auto_20190104_0908.py @@ -0,0 +1,24 @@ +# Generated by Django 2.1.4 on 2019-01-04 09:08 + +from django.db import migrations + + +def fill_ping_kind(apps, schema_editor): + Ping = apps.get_model('api', 'Ping') + + q = Ping.objects.filter(start=True) + q.update(kind="start") + + q = Ping.objects.filter(fail=True) + q.update(kind="fail") + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0050_ping_kind'), + ] + + operations = [ + migrations.RunPython(fill_ping_kind), + ] diff --git a/hc/api/models.py b/hc/api/models.py index 6dab0c88..982a9949 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -230,8 +230,14 @@ class Check(models.Model): ping = Ping(owner=self) ping.n = self.n_pings - ping.start = action == "start" - ping.fail = action == "fail" + + if action == "start": + ping.start = True + ping.kind = "start" + elif action == "fail": + ping.fail = True + ping.kind = "fail" + ping.remote_addr = remote_addr ping.scheme = scheme ping.method = method @@ -246,6 +252,7 @@ class Ping(models.Model): n = models.IntegerField(null=True) owner = models.ForeignKey(Check, models.CASCADE) created = models.DateTimeField(auto_now_add=True) + kind = models.CharField(max_length=6, blank=True, null=True) start = models.NullBooleanField(default=False) fail = models.NullBooleanField(default=False) scheme = models.CharField(max_length=10, default="http") diff --git a/hc/api/tests/test_ping.py b/hc/api/tests/test_ping.py index 1d3223f1..ff40452c 100644 --- a/hc/api/tests/test_ping.py +++ b/hc/api/tests/test_ping.py @@ -23,6 +23,7 @@ class PingTestCase(BaseTestCase): ping = Ping.objects.latest("id") self.assertEqual(ping.scheme, "http") + self.assertEqual(ping.kind, None) def test_it_changes_status_of_paused_check(self): self.check.status = "paused" @@ -139,6 +140,7 @@ class PingTestCase(BaseTestCase): ping = Ping.objects.get() self.assertTrue(ping.fail) + self.assertEqual(ping.kind, "fail") flip = Flip.objects.get() self.assertEqual(flip.owner, self.check) @@ -158,6 +160,7 @@ class PingTestCase(BaseTestCase): ping = Ping.objects.get() self.assertTrue(ping.start) + self.assertEqual(ping.kind, "start") def test_start_does_not_change_status_of_paused_check(self): self.check.status = "paused"