diff --git a/api/scpca_portal/test/test_utils.py b/api/scpca_portal/test/test_utils.py index a4cb17d2..00367228 100644 --- a/api/scpca_portal/test/test_utils.py +++ b/api/scpca_portal/test/test_utils.py @@ -1,3 +1,6 @@ +from datetime import date +from unittest.mock import patch + from django.test import TestCase from scpca_portal import utils @@ -37,3 +40,10 @@ def test_join_multiple_items(self): def test_join_single_item(self): items = ("single item",) self.assertEqual(utils.join_workflow_versions(items), items[0]) + + +class TestGetToday(TestCase): + @patch("scpca_portal.utils.datetime") + def test_format(self, mock_date): + mock_date.today.return_value = date(2022, 10, 8) + self.assertEqual(utils.get_today_string(), "2022-10-08") diff --git a/api/scpca_portal/utils.py b/api/scpca_portal/utils.py index ded5868c..be3b46ca 100644 --- a/api/scpca_portal/utils.py +++ b/api/scpca_portal/utils.py @@ -25,6 +25,6 @@ def join_workflow_versions(workflow_versions): return ", ".join(sorted(set(workflow_versions))) -def get_today_string(format: str = "%Y-%M-%d"): +def get_today_string(format: str = "%Y-%m-%d"): """Returns today's date formatted. Defaults to ISO 8601.""" return datetime.today().strftime(format)