timetracker/tests/test_session_formatting.py

41 lines
1.1 KiB
Python
Raw Permalink Normal View History

2023-11-10 20:34:36 +00:00
import os
from datetime import datetime
from zoneinfo import ZoneInfo
2023-11-15 18:36:22 +00:00
import django
from django.db import models
from django.test import TestCase
2023-11-10 20:34:36 +00:00
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
django.setup()
from django.conf import settings
2023-11-15 18:36:22 +00:00
from games.models import Edition, Game, Purchase, Session
2023-11-10 20:34:36 +00:00
ZONEINFO = ZoneInfo(settings.TIME_ZONE)
class FormatDurationTest(TestCase):
def setUp(self) -> None:
return super().setUp()
def test_duration_format(self):
g = Game(name="The Test Game")
g.save()
e = Edition(game=g, name="The Test Game Edition")
e.save()
p = Purchase(
edition=e, date_purchased=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO)
)
p.save()
s = Session(
purchase=p,
timestamp_start=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO),
timestamp_end=datetime(2022, 9, 26, 17, 38, tzinfo=ZONEINFO),
)
s.save()
self.assertEqual(
s.duration_formatted(),
"02:40",
)