Fix additional tests
This commit is contained in:
@@ -614,7 +614,7 @@ class EnableCacheTest(unittest.TestCase):
|
|||||||
self.assertEqual(params["maxsize"], 4096)
|
self.assertEqual(params["maxsize"], 4096)
|
||||||
|
|
||||||
|
|
||||||
class ModelDependentComponentsTest(unittest.TestCase):
|
class ModelDependentComponentsTest(django.test.TestCase):
|
||||||
"""Test components that depend on Django models."""
|
"""Test components that depend on Django models."""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -775,7 +775,7 @@ class PurchaseTruncatedTest(unittest.TestCase):
|
|||||||
self.assertIn("data-popover-target", result)
|
self.assertIn("data-popover-target", result)
|
||||||
|
|
||||||
|
|
||||||
class NameWithIconPlatformTest(unittest.TestCase):
|
class NameWithIconPlatformTest(django.test.TestCase):
|
||||||
"""Test NameWithIcon platform icon rendering."""
|
"""Test NameWithIcon platform icon rendering."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ class FormatDurationTest(TestCase):
|
|||||||
g = Game(name="The Test Game")
|
g = Game(name="The Test Game")
|
||||||
g.save()
|
g.save()
|
||||||
p = Purchase(
|
p = Purchase(
|
||||||
game=g, date_purchased=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO)
|
date_purchased=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO)
|
||||||
)
|
)
|
||||||
p.save()
|
p.save()
|
||||||
|
p.games.add(g)
|
||||||
|
p.save()
|
||||||
s = Session(
|
s = Session(
|
||||||
purchase=p,
|
game=g,
|
||||||
timestamp_start=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO),
|
timestamp_start=datetime(2022, 9, 26, 14, 58, tzinfo=ZONEINFO),
|
||||||
timestamp_end=datetime(2022, 9, 26, 17, 38, tzinfo=ZONEINFO),
|
timestamp_end=datetime(2022, 9, 26, 17, 38, tzinfo=ZONEINFO),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from common.time import daterange, streak_bruteforce
|
|||||||
|
|
||||||
|
|
||||||
class StreakTest(unittest.TestCase):
|
class StreakTest(unittest.TestCase):
|
||||||
streak = streak_bruteforce
|
|
||||||
|
|
||||||
def test_daterange_exclusive(self):
|
def test_daterange_exclusive(self):
|
||||||
d = daterange(date(2024, 8, 1), date(2024, 8, 3))
|
d = daterange(date(2024, 8, 1), date(2024, 8, 3))
|
||||||
@@ -22,14 +21,14 @@ class StreakTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_1day_streak(self):
|
def test_1day_streak(self):
|
||||||
self.assertEqual(streak([date(2024, 8, 1)])["days"], 1)
|
self.assertEqual(streak_bruteforce([date(2024, 8, 1)])["days"], 1)
|
||||||
|
|
||||||
def test_2day_streak(self):
|
def test_2day_streak(self):
|
||||||
self.assertEqual(streak([date(2024, 8, 1), date(2024, 8, 2)])["days"], 2)
|
self.assertEqual(streak_bruteforce([date(2024, 8, 1), date(2024, 8, 2)])["days"], 2)
|
||||||
|
|
||||||
def test_31day_streak(self):
|
def test_31day_streak(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
streak(daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True))[
|
streak_bruteforce(daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True))[
|
||||||
"days"
|
"days"
|
||||||
],
|
],
|
||||||
31,
|
31,
|
||||||
@@ -39,14 +38,14 @@ class StreakTest(unittest.TestCase):
|
|||||||
d = daterange(
|
d = daterange(
|
||||||
date(2024, 8, 1), date(2024, 8, 5), end_inclusive=True
|
date(2024, 8, 1), date(2024, 8, 5), end_inclusive=True
|
||||||
) + daterange(date(2024, 8, 7), date(2024, 8, 10), end_inclusive=True)
|
) + daterange(date(2024, 8, 7), date(2024, 8, 10), end_inclusive=True)
|
||||||
self.assertEqual(streak(d)["days"], 5)
|
self.assertEqual(streak_bruteforce(d)["days"], 5)
|
||||||
|
|
||||||
def test_10day_streak_in_31_days(self):
|
def test_10day_streak_in_31_days(self):
|
||||||
d = daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True)
|
d = daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True)
|
||||||
d.remove(date(2024, 8, 8))
|
d.remove(date(2024, 8, 8))
|
||||||
d.remove(date(2024, 8, 15))
|
d.remove(date(2024, 8, 15))
|
||||||
d.remove(date(2024, 8, 21))
|
d.remove(date(2024, 8, 21))
|
||||||
self.assertEqual(streak(d)["days"], 10)
|
self.assertEqual(streak_bruteforce(d)["days"], 10)
|
||||||
|
|
||||||
def test_10day_streak_in_31_days_with_consecutive_missing(self):
|
def test_10day_streak_in_31_days_with_consecutive_missing(self):
|
||||||
d = daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True)
|
d = daterange(date(2024, 8, 1), date(2024, 8, 31), end_inclusive=True)
|
||||||
@@ -57,4 +56,4 @@ class StreakTest(unittest.TestCase):
|
|||||||
d.remove(date(2024, 8, 8))
|
d.remove(date(2024, 8, 8))
|
||||||
d.remove(date(2024, 8, 15))
|
d.remove(date(2024, 8, 15))
|
||||||
d.remove(date(2024, 8, 21))
|
d.remove(date(2024, 8, 21))
|
||||||
self.assertEqual(streak(d)["days"], 10)
|
self.assertEqual(streak_bruteforce(d)["days"], 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user