Compare commits
2 Commits
3b37f2c3f0
...
667b161fff
Author | SHA1 | Date |
---|---|---|
Lukáš Kucharczyk | 667b161fff | |
Lukáš Kucharczyk | 5958cbf4a6 |
|
@ -0,0 +1,89 @@
|
|||
import django
|
||||
import os
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
|
||||
django.setup()
|
||||
from django.conf import settings
|
||||
|
||||
from games.models import Game, Edition, Purchase, Session, Platform
|
||||
|
||||
ZONEINFO = ZoneInfo(settings.TIME_ZONE)
|
||||
|
||||
|
||||
class PathWorksTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
pl = Platform(name="Test Platform")
|
||||
pl.save()
|
||||
g = Game(name="The Test Game")
|
||||
g.save()
|
||||
e = Edition(game=g, name="The Test Game Edition", platform=pl)
|
||||
e.save()
|
||||
p = Purchase(
|
||||
edition=e,
|
||||
platform=pl,
|
||||
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.testSession = s
|
||||
return super().setUp()
|
||||
|
||||
def test_add_device_returns_200(self):
|
||||
url = reverse("add_device")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_platform_returns_200(self):
|
||||
url = reverse("add_platform")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_game_returns_200(self):
|
||||
url = reverse("add_game")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_edition_returns_200(self):
|
||||
url = reverse("add_edition")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_purchase_returns_200(self):
|
||||
url = reverse("add_purchase")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_add_session_returns_200(self):
|
||||
url = reverse("add_session")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_edit_session_returns_200(self):
|
||||
id = self.testSession.id
|
||||
url = reverse("edit_session", args=[id])
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_view_game_returns_200(self):
|
||||
url = reverse("view_game", args=[1])
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_edit_game_returns_200(self):
|
||||
url = reverse("edit_game", args=[1])
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_list_sessions_returns_200(self):
|
||||
url = reverse("list_sessions")
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 200)
|
|
@ -0,0 +1,38 @@
|
|||
import django
|
||||
import os
|
||||
from django.test import TestCase
|
||||
from django.db import models
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "timetracker.settings")
|
||||
django.setup()
|
||||
from django.conf import settings
|
||||
from games.models import Game, Edition, Purchase, Session
|
||||
|
||||
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",
|
||||
)
|
|
@ -150,5 +150,3 @@ if _csrf_trusted_origins:
|
|||
CSRF_TRUSTED_ORIGINS = _csrf_trusted_origins.split(",")
|
||||
else:
|
||||
CSRF_TRUSTED_ORIGINS = []
|
||||
|
||||
USE_L10N = False
|
||||
|
|
Loading…
Reference in New Issue