Browse Source

Add Ping.kind field

pull/211/head
Pēteris Caune 6 years ago
parent
commit
7480eca2a5
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
5 changed files with 55 additions and 2 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +18
    -0
      hc/api/migrations/0050_ping_kind.py
  3. +24
    -0
      hc/api/migrations/0051_auto_20190104_0908.py
  4. +9
    -2
      hc/api/models.py
  5. +3
    -0
      hc/api/tests/test_ping.py

+ 1
- 0
CHANGELOG.md View File

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Improvements ### Improvements
- Database schema: set Check.user to not null - Database schema: set Check.user to not null
- Database schema: add uniqueness constraint to Check.code - Database schema: add uniqueness constraint to Check.code
- Database schema: add Ping.kind field
## 1.4.0 - 2018-12-25 ## 1.4.0 - 2018-12-25


+ 18
- 0
hc/api/migrations/0050_ping_kind.py View File

@ -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),
),
]

+ 24
- 0
hc/api/migrations/0051_auto_20190104_0908.py View File

@ -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),
]

+ 9
- 2
hc/api/models.py View File

@ -230,8 +230,14 @@ class Check(models.Model):
ping = Ping(owner=self) ping = Ping(owner=self)
ping.n = self.n_pings 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.remote_addr = remote_addr
ping.scheme = scheme ping.scheme = scheme
ping.method = method ping.method = method
@ -246,6 +252,7 @@ class Ping(models.Model):
n = models.IntegerField(null=True) n = models.IntegerField(null=True)
owner = models.ForeignKey(Check, models.CASCADE) owner = models.ForeignKey(Check, models.CASCADE)
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
kind = models.CharField(max_length=6, blank=True, null=True)
start = models.NullBooleanField(default=False) start = models.NullBooleanField(default=False)
fail = models.NullBooleanField(default=False) fail = models.NullBooleanField(default=False)
scheme = models.CharField(max_length=10, default="http") scheme = models.CharField(max_length=10, default="http")


+ 3
- 0
hc/api/tests/test_ping.py View File

@ -23,6 +23,7 @@ class PingTestCase(BaseTestCase):
ping = Ping.objects.latest("id") ping = Ping.objects.latest("id")
self.assertEqual(ping.scheme, "http") self.assertEqual(ping.scheme, "http")
self.assertEqual(ping.kind, None)
def test_it_changes_status_of_paused_check(self): def test_it_changes_status_of_paused_check(self):
self.check.status = "paused" self.check.status = "paused"
@ -139,6 +140,7 @@ class PingTestCase(BaseTestCase):
ping = Ping.objects.get() ping = Ping.objects.get()
self.assertTrue(ping.fail) self.assertTrue(ping.fail)
self.assertEqual(ping.kind, "fail")
flip = Flip.objects.get() flip = Flip.objects.get()
self.assertEqual(flip.owner, self.check) self.assertEqual(flip.owner, self.check)
@ -158,6 +160,7 @@ class PingTestCase(BaseTestCase):
ping = Ping.objects.get() ping = Ping.objects.get()
self.assertTrue(ping.start) self.assertTrue(ping.start)
self.assertEqual(ping.kind, "start")
def test_start_does_not_change_status_of_paused_check(self): def test_start_does_not_change_status_of_paused_check(self):
self.check.status = "paused" self.check.status = "paused"


Loading…
Cancel
Save