Browse Source

Test for check.prune_pings() method

pull/25/merge
Pēteris Caune 9 years ago
parent
commit
940534e563
2 changed files with 21 additions and 2 deletions
  1. +2
    -2
      hc/api/models.py
  2. +19
    -0
      hc/api/tests/test_check_model.py

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

@ -112,8 +112,8 @@ class Check(models.Model):
if len(cutoff) == 0:
return 0
cutoff_date = cutoff[0].created
q = Ping.objects.filter(owner=self, created__lte=cutoff_date)
cutoff_id = cutoff[0].id
q = Ping.objects.filter(owner=self, id__lte=cutoff_id)
n_pruned, _ = q.delete()
self.n_pings = keep_limit


+ 19
- 0
hc/api/tests/test_check_model.py View File

@ -0,0 +1,19 @@
from django.test import TestCase
from hc.api.models import Check, Ping
class CheckModelTestCase(TestCase):
def test_prune_pings(self):
check = Check()
check.save()
for i in range(0, 6):
p = Ping(owner=check, ua="UA%d" % i)
p.save()
check.prune_pings(keep_limit=3)
ua_set = set(Ping.objects.values_list("ua", flat=True))
# UA0, UA1, UA2 should have been pruned--
self.assertEqual(ua_set, set(["UA3", "UA4", "UA5"]))

Loading…
Cancel
Save