Skip to content

Commit

Permalink
normli
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Dec 19, 2023
1 parent eb16776 commit 0002479
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions comptages/test/test_import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytz
from datetime import datetime
from datetime import datetime, timezone, tzinfo
from django.test import TransactionTestCase
from django.core.management import call_command

Expand Down Expand Up @@ -42,14 +42,17 @@ def test_import_vbv1(self):
importer.import_file(utils.test_data_path("00056520.V01"), count)

self.assertEqual(models.CountDetail.objects.count(), 18114)
first = models.CountDetail.objects.first()
last = models.CountDetail.objects.last()
assert first
assert last

tz = pytz.timezone("Europe/Zurich")
zurich_timezone = pytz.timezone("Europe/Zurich")
first = first.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)
last = last.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)

first = tz.normalize(models.CountDetail.objects.first().timestamp)
last = tz.normalize(models.CountDetail.objects.last().timestamp)

self.assertEqual(first, tz.localize(datetime(2021, 10, 15, 9, 46, 43, 500000)))
self.assertEqual(last, tz.localize(datetime(2021, 10, 15, 23, 59, 54, 600000)))
self.assertEqual(first, datetime(2021, 10, 15, 9, 46, 43, 500000))
self.assertEqual(last, datetime(2021, 10, 15, 23, 59, 54, 600000))

def test_import_mc(self):
model = models.Model.objects.all()[0]
Expand All @@ -76,13 +79,18 @@ def test_import_mc(self):

self.assertEqual(models.CountDetail.objects.count(), 25867)

tz = pytz.timezone("Europe/Zurich")
first = models.CountDetail.objects.first()
last = models.CountDetail.objects.last()
zurich_timezone = pytz.timezone("Europe/Zurich")

assert first
assert last

first = tz.normalize(models.CountDetail.objects.first().timestamp)
last = tz.normalize(models.CountDetail.objects.last().timestamp)
first = first.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)
last = last.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)

self.assertEqual(first, tz.localize(datetime(2021, 9, 10, 4, 16, 16)))
self.assertEqual(last, tz.localize(datetime(2021, 9, 21, 8, 2, 15)))
self.assertEqual(first, datetime(2021, 9, 10, 4, 16, 16))
self.assertEqual(last, datetime(2021, 9, 21, 8, 2, 15))

def test_import_int2(self):
model = models.Model.objects.all()[0]
Expand All @@ -107,13 +115,17 @@ def test_import_int2(self):

importer.import_file(utils.test_data_path("10020260.A01"), count)

tz = pytz.timezone("Europe/Zurich")
first = models.CountDetail.objects.first()
last = models.CountDetail.objects.last()
assert first
assert last

first = tz.normalize(models.CountDetail.objects.first().timestamp)
last = tz.normalize(models.CountDetail.objects.last().timestamp)
zurich_timezone = pytz.timezone("Europe/Zurich")
first = first.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)
last = last.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)

self.assertEqual(first, tz.localize(datetime(2018, 4, 13, 12, 0)))
self.assertEqual(last, tz.localize(datetime(2018, 5, 1, 13, 0)))
self.assertEqual(first, datetime(2018, 4, 13, 12, 0))
self.assertEqual(last, datetime(2018, 5, 1, 13, 0))

def test_import_simple_int2(self):
model = models.Model.objects.all()[0]
Expand Down Expand Up @@ -142,13 +154,17 @@ def test_import_simple_int2(self):

self.assertEqual(models.CountDetail.objects.count(), 52)

tz = pytz.timezone("Europe/Zurich")
first = models.CountDetail.objects.first()
last = models.CountDetail.objects.last()
assert first
assert last

first = tz.normalize(models.CountDetail.objects.first().timestamp)
last = tz.normalize(models.CountDetail.objects.last().timestamp)
zurich_timezone = pytz.timezone("Europe/Zurich")
first = first.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)
last = last.timestamp.astimezone(zurich_timezone).replace(tzinfo=None)

self.assertEqual(first, tz.localize(datetime(2018, 9, 24, 0, 0)))
self.assertEqual(last, tz.localize(datetime(2018, 9, 24, 1, 0)))
self.assertEqual(first, datetime(2018, 9, 24, 0, 0))
self.assertEqual(last, datetime(2018, 9, 24, 1, 0))

speed20 = models.CountDetail.objects.filter(speed=20)
self.assertEqual(speed20[0].times, 3)
Expand Down

0 comments on commit 0002479

Please sign in to comment.