From 1b1d9fe39fa3de359fb13e9189c3f887b53dab7d Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 31 May 2023 12:52:20 +0200 Subject: [PATCH] Update tests with new Version.get_absolute_url implementation --- readthedocs/rtd_tests/tests/test_api.py | 30 +++++++++++++++-------- readthedocs/rtd_tests/tests/test_oauth.py | 2 ++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_api.py b/readthedocs/rtd_tests/tests/test_api.py index 5d6b0703ce6..e425a16e302 100644 --- a/readthedocs/rtd_tests/tests/test_api.py +++ b/readthedocs/rtd_tests/tests/test_api.py @@ -6,6 +6,7 @@ import dateutil from allauth.socialaccount.models import SocialAccount from django.contrib.auth.models import User +from django.core.validators import URLValidator from django.http import QueryDict from django.test import TestCase, override_settings from django.urls import reverse @@ -299,12 +300,17 @@ def test_response_building(self): 'version_slug': version.slug, }, ) + build = resp.data - self.assertEqual(build['state'], 'cloning') - self.assertEqual(build['error'], '') - self.assertEqual(build['exit_code'], 0) - self.assertEqual(build['success'], True) - self.assertEqual(build['docs_url'], dashboard_url) + self.assertEqual(build["state"], "cloning") + self.assertEqual(build["error"], "") + self.assertEqual(build["exit_code"], 0) + self.assertEqual(build["success"], True) + self.assertTrue(build["docs_url"].endswith(dashboard_url)) + + # Validate received URL (fails with ValidationError if incorrect value) + url_validator = URLValidator(schemes=["https"]) + url_validator(build["docs_url"]) @override_settings(DOCROOT="/home/docs/checkouts/readthedocs.org/user_builds") def test_response_finished_and_success(self): @@ -390,11 +396,15 @@ def test_response_finished_and_fail(self): }, ) build = resp.data - self.assertEqual(build['state'], 'finished') - self.assertEqual(build['error'], '') - self.assertEqual(build['exit_code'], 1) - self.assertEqual(build['success'], False) - self.assertEqual(build['docs_url'], dashboard_url) + self.assertEqual(build["state"], "finished") + self.assertEqual(build["error"], "") + self.assertEqual(build["exit_code"], 1) + self.assertEqual(build["success"], False) + self.assertTrue(build["docs_url"].endswith(dashboard_url)) + + # Validate received URL (fails with ValidationError if incorrect value) + url_validator = URLValidator(schemes=["https"]) + url_validator(build["docs_url"]) def test_make_build_without_permission(self): """Ensure anonymous/non-staff users cannot write the build endpoint.""" diff --git a/readthedocs/rtd_tests/tests/test_oauth.py b/readthedocs/rtd_tests/tests/test_oauth.py index 8e0a171526f..5759756b723 100644 --- a/readthedocs/rtd_tests/tests/test_oauth.py +++ b/readthedocs/rtd_tests/tests/test_oauth.py @@ -350,6 +350,8 @@ def test_send_build_status_value_error(self, session, mock_logger): commit_status='success', user_username=self.user.username, statuses_url='https://api.github.com/repos/pypa/pip/statuses/1234', + target_url=mock.ANY, + status="success", ) mock_logger.exception.assert_called_with( 'GitHub commit status creation failed for project.',