MT#56231 gerrit: fix default today format

task expects YYYY-MM-DD format

> (venv_prod) root@repoapi2:/usr/share/repoapi# ./manage.py gerrit cleanup --weeks=4
> [...]
>   File "/usr/share/repoapi/gerrit/tasks.py", line 35, in cleanup
>     today = date.fromisoformat(today)
> ValueError: Invalid isoformat string: '2023-12-19T12:39:58.364626'

Change-Id: If635b36d6fb579a7823522aef6e41f2d53eb1823
master
Victor Seva 1 year ago
parent 2e01ca44a3
commit dd8ee06ca4

@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from datetime import date
from datetime import datetime
from django.core.management.base import BaseCommand
@ -35,7 +34,7 @@ class Command(BaseCommand):
parser.add_argument(
"--today",
type=date.fromisoformat,
default=datetime.today(),
default=date.today(),
help="set today value in isoformat 'YYYY-MM-DD'",
)

@ -18,6 +18,7 @@ from unittest.mock import call
from unittest.mock import patch
from django.core.management import call_command
from django.core.management.base import CommandError
from django.test import TestCase
from repoapi.models.gri import GerritRepoInfo
@ -86,3 +87,19 @@ class refreshTest(TestCase):
]
self.assertListEqual(jrp.mock_calls, calls)
self.assertEqual(qs.count(), 1)
@patch("gerrit.management.commands.gerrit.tasks")
def test_today_format(self, tasks):
from datetime import datetime
val = datetime.today().strftime("%Y-%m-%d")
call_command("gerrit", "cleanup")
tasks.cleanup.assert_called_with(6, False, val)
@patch("gerrit.management.commands.gerrit.tasks")
def test_today_format_ko(self, tasks):
with self.assertRaisesRegexp(
CommandError, "invalid fromisoformat value"
):
call_command("gerrit", "cleanup", "--today=2023-12-19T12:39:58")
tasks.cleanup.assert_not_called()

Loading…
Cancel
Save