Browse Source

Format timestamp as ISO 8601 without microseconds, same as elsewhere.

pull/387/head
Pēteris Caune 4 years ago
parent
commit
60d1c6e2a3
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 10 additions and 7 deletions
  1. +4
    -1
      hc/api/models.py
  2. +6
    -6
      hc/api/tests/test_get_flips.py

+ 4
- 1
hc/api/models.py View File

@ -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"):


+ 6
- 6
hc/api/tests/test_get_flips.py View File

@ -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):


Loading…
Cancel
Save