From 04e09af8a9e87643731136f943be0bf2d387c837 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Tue, 14 May 2024 13:03:32 -0500 Subject: [PATCH] provide next_level as a nice-looking string Signed-off-by: Brian S. Stephan --- idlerpg/models.py | 4 ++++ tests/test_idlerpg_character.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/idlerpg/models.py b/idlerpg/models.py index 0710a2d..c24b431 100644 --- a/idlerpg/models.py +++ b/idlerpg/models.py @@ -128,6 +128,10 @@ class Character(models.Model): """Provide a string representation for display, etc. purposes.""" return f"{self.name}, the level {self.level} {self.character_class}" + def next_level_str(self): + """Return a nicely-formatted version of next_level.""" + return self.next_level.strftime('%Y-%m-%d %H:%M:%S %Z') + def calculate_datetime_to_next_level(self): """Determine when the next level will be reached (barring no penalties or logoffs). diff --git a/tests/test_idlerpg_character.py b/tests/test_idlerpg_character.py index c324e6f..da43382 100644 --- a/tests/test_idlerpg_character.py +++ b/tests/test_idlerpg_character.py @@ -28,6 +28,11 @@ class CharacterTest(TestCase): logger.debug(str(char)) assert str(char) == "bss, the level 0 tester" + def test_next_level_str(self): + """Test the format of the readable next level string.""" + char = Character.objects.get(pk=1) + assert char.next_level_str() == "2024-05-05 05:20:45 UTC" + def test_log_out(self): """Test basic log out functionality and end result.""" char = Character.objects.get(pk=1)