summaryrefslogtreecommitdiffstats
path: root/engagements/tests/test_views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-07 15:40:13 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-07 15:40:13 +0100
commit222cd8c0737ea76f33b6a9337316b673f532bcc0 (patch)
treeeddb5ecc6723c541eae6348e0ce1380670d7f566 /engagements/tests/test_views.py
parentb821c337590e2653074f3f01c649c180918c1c32 (diff)
Nice engagement duration text for summary box on detail page
Diffstat (limited to 'engagements/tests/test_views.py')
-rw-r--r--engagements/tests/test_views.py33
1 files changed, 31 insertions, 2 deletions
diff --git a/engagements/tests/test_views.py b/engagements/tests/test_views.py
index 017b96f..01d73c7 100644
--- a/engagements/tests/test_views.py
+++ b/engagements/tests/test_views.py
@@ -6,12 +6,41 @@ from django.test import RequestFactory
from django.urls import reverse
from engagements import models, views
-from engagements.models import EngagementStrategy, RegulatoryCycle, Organisation
-from engagements.utils import populate_database
+from engagements.models import EngagementStrategy, Organisation, RegulatoryCycle
+from engagements.utils import duration_formatter, populate_database
pytestmark = pytest.mark.django_db
+def test_single_day_string():
+ """test date formatting for the summary box on the detail page"""
+ d1 = datetime.date(2024, 10, 10)
+ d2 = datetime.date(2024, 10, 10)
+ duration_str = duration_formatter(d1, d2)
+ assert duration_str == "10 October 2024 (1 day)"
+
+def test_multi_duration_string():
+ """test date formatting for the summary box on the detail page"""
+ d1 = datetime.date(2024, 10, 10)
+ d2 = datetime.date(2024, 10, 12)
+ duration_str = duration_formatter(d1, d2)
+ assert duration_str == "10-12 October 2024 (3 days)"
+
+def test_multi_duration_string_longer():
+ """test date formatting for the summary box on the detail page"""
+ d1 = datetime.date(2024, 10, 1)
+ d2 = datetime.date(2024, 10, 12)
+ duration_str = duration_formatter(d1, d2)
+ assert duration_str == "01-12 October 2024 (12 days)"
+
+def test_multi_duration_over_month_boundary_string():
+ """test date formatting for the summary box on the detail page"""
+ d1 = datetime.date(2024, 9, 30)
+ d2 = datetime.date(2024, 10, 1)
+ duration_str = duration_formatter(d1, d2)
+ assert duration_str == "30 September - 01 October 2024 (2 days)"
+
+
@pytest.fixture
def test_data():
return populate_database()