From 60d1c6e2a31a8815d18f83c066f15cc7b475502c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 15 Jun 2020 12:20:07 +0300 Subject: [PATCH] Format timestamp as ISO 8601 without microseconds, same as elsewhere. --- hc/api/models.py | 5 ++++- hc/api/tests/test_get_flips.py | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hc/api/models.py b/hc/api/models.py index 7616f648..aceb5b83 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -762,7 +762,10 @@ class Flip(models.Model): ] def to_dict(self): - return {"timestamp": self.created, "up": 1 if self.new_status == "up" else 0} + return { + "timestamp": isostring(self.created), + "up": 1 if self.new_status == "up" else 0, + } def send_alerts(self): if self.new_status == "up" and self.old_status in ("new", "paused"): diff --git a/hc/api/tests/test_get_flips.py b/hc/api/tests/test_get_flips.py index e6e5aa17..ecc19c14 100644 --- a/hc/api/tests/test_get_flips.py +++ b/hc/api/tests/test_get_flips.py @@ -25,13 +25,12 @@ class GetFlipsTestCase(BaseTestCase): return self.client.get(self.url, HTTP_X_API_KEY=api_key) def test_it_works(self): - self.f1 = Flip( + Flip.objects.create( owner=self.a1, - created=dt(2020,6,1,12,24,32,tzinfo=timezone.utc), - old_status='new', - new_status='up', + created=dt(2020, 6, 1, 12, 24, 32, 123000, tzinfo=timezone.utc), + old_status="new", + new_status="up", ) - self.f1.save() r = self.get() self.assertEqual(r.status_code, 200) @@ -41,7 +40,8 @@ class GetFlipsTestCase(BaseTestCase): self.assertEqual(len(doc["flips"]), 1) flip = doc["flips"][0] - self.assertEqual(flip["timestamp"], dt(2020,6,1,12,24,32,tzinfo=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')) + # Microseconds (123000) should be stripped out + self.assertEqual(flip["timestamp"], "2020-06-01T12:24:32+00:00") self.assertEqual(flip["up"], 1) def test_readonly_key_is_allowed(self):