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

This commit is contained in:
Pēteris Caune 2020-06-15 12:20:07 +03:00
parent a90f8a3a56
commit 60d1c6e2a3
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
2 changed files with 10 additions and 7 deletions

View File

@ -762,7 +762,10 @@ class Flip(models.Model):
] ]
def to_dict(self): 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): def send_alerts(self):
if self.new_status == "up" and self.old_status in ("new", "paused"): if self.new_status == "up" and self.old_status in ("new", "paused"):

View File

@ -25,13 +25,12 @@ class GetFlipsTestCase(BaseTestCase):
return self.client.get(self.url, HTTP_X_API_KEY=api_key) return self.client.get(self.url, HTTP_X_API_KEY=api_key)
def test_it_works(self): def test_it_works(self):
self.f1 = Flip( Flip.objects.create(
owner=self.a1, owner=self.a1,
created=dt(2020,6,1,12,24,32,tzinfo=timezone.utc), created=dt(2020, 6, 1, 12, 24, 32, 123000, tzinfo=timezone.utc),
old_status='new', old_status="new",
new_status='up', new_status="up",
) )
self.f1.save()
r = self.get() r = self.get()
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
@ -41,7 +40,8 @@ class GetFlipsTestCase(BaseTestCase):
self.assertEqual(len(doc["flips"]), 1) self.assertEqual(len(doc["flips"]), 1)
flip = doc["flips"][0] 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) self.assertEqual(flip["up"], 1)
def test_readonly_key_is_allowed(self): def test_readonly_key_is_allowed(self):