From 2662bd9ed14daa773b971e48de51157f30f6ed94 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 20 Dec 2022 12:29:27 -0500 Subject: [PATCH] API V2: test that command is actually saved --- readthedocs/rtd_tests/tests/test_api.py | 32 +++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_api.py b/readthedocs/rtd_tests/tests/test_api.py index 8ee068b7d5e..f0c04de70c0 100644 --- a/readthedocs/rtd_tests/tests/test_api.py +++ b/readthedocs/rtd_tests/tests/test_api.py @@ -3,11 +3,13 @@ import json from unittest import mock +import dateutil from allauth.socialaccount.models import SocialAccount from django.contrib.auth.models import User from django.http import QueryDict from django.test import TestCase from django.urls import reverse +from django.utils import timezone from django_dynamic_fixture import get from rest_framework import status from rest_framework.test import APIClient @@ -460,16 +462,18 @@ def test_make_build_commands(self): ) self.assertEqual(resp.status_code, status.HTTP_201_CREATED) build = resp.data - now = datetime.datetime.utcnow() + now = timezone.now() + start_time = now - datetime.timedelta(seconds=5) + end_time = now resp = client.post( '/api/v2/command/', { - 'build': build['id'], - 'command': 'echo test', - 'description': 'foo', - 'exit_code': 0, - 'start_time': str(now - datetime.timedelta(seconds=5)), - 'end_time': str(now), + "build": build["id"], + "command": "echo test", + "description": "foo", + "exit_code": 0, + "start_time": start_time, + "end_time": end_time, }, format='json', ) @@ -477,9 +481,17 @@ def test_make_build_commands(self): resp = client.get('/api/v2/build/%s/' % build['id']) self.assertEqual(resp.status_code, 200) build = resp.data - self.assertEqual(len(build['commands']), 1) - self.assertEqual(build['commands'][0]['run_time'], 5) - self.assertEqual(build['commands'][0]['description'], 'foo') + self.assertEqual(len(build["commands"]), 1) + self.assertEqual(build["commands"][0]["command"], "echo test") + self.assertEqual(build["commands"][0]["run_time"], 5) + self.assertEqual(build["commands"][0]["description"], "foo") + self.assertEqual(build["commands"][0]["exit_code"], 0) + self.assertEqual( + dateutil.parser.parse(build["commands"][0]["start_time"]), start_time + ) + self.assertEqual( + dateutil.parser.parse(build["commands"][0]["end_time"]), end_time + ) def test_get_raw_log_success(self): project = Project.objects.get(pk=1)