From 5958cbf4a69eefaab73b4e52a028a82d98748626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Fri, 10 Nov 2023 21:34:36 +0100 Subject: [PATCH] Add more tests --- tests/test_paths_return_200.py | 89 ++++++++++++++++++++++++++++++++ tests/test_session_formatting.py | 38 ++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 tests/test_paths_return_200.py create mode 100644 tests/test_session_formatting.py diff --git a/tests/test_paths_return_200.py b/tests/test_paths_return_200.py new file mode 100644 index 0000000..c126bfb --- /dev/null +++ b/tests/test_paths_return_200.py @@ -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) diff --git a/tests/test_session_formatting.py b/tests/test_session_formatting.py new file mode 100644 index 0000000..f3b3a5c --- /dev/null +++ b/tests/test_session_formatting.py @@ -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", + )