Skip to content

Commit

Permalink
API V2: test that command is actually saved
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Dec 20, 2022
1 parent 9efe46e commit 2662bd9
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions readthedocs/rtd_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -460,26 +462,36 @@ 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',
)
self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
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)
Expand Down

0 comments on commit 2662bd9

Please sign in to comment.