From 5a16e7bfc9754076facae53ab95ccae7f3d65673 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 18 Feb 2019 20:07:10 -0500 Subject: [PATCH] Rstrip repo url Close #5303 --- readthedocs/projects/forms.py | 4 ++++ .../rtd_tests/tests/test_project_forms.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/readthedocs/projects/forms.py b/readthedocs/projects/forms.py index ca55e456606..5825c218fe6 100644 --- a/readthedocs/projects/forms.py +++ b/readthedocs/projects/forms.py @@ -131,6 +131,10 @@ def clean_name(self): return name + def clean_repo(self): + repo = self.cleaned_data.get('repo', '') + return repo.rstrip('/') + def clean_remote_repository(self): remote_repo = self.cleaned_data.get('remote_repository', None) if not remote_repo: diff --git a/readthedocs/rtd_tests/tests/test_project_forms.py b/readthedocs/rtd_tests/tests/test_project_forms.py index 12bb452f703..20fced77f86 100644 --- a/readthedocs/rtd_tests/tests/test_project_forms.py +++ b/readthedocs/rtd_tests/tests/test_project_forms.py @@ -1,12 +1,9 @@ -# -*- coding: utf-8 -*- - import mock from django.contrib.auth.models import User from django.test import TestCase from django.test.utils import override_settings from django_dynamic_fixture import get from textclassifier.validators import ClassifierValidator -from django.core.exceptions import ValidationError from readthedocs.builds.constants import LATEST from readthedocs.builds.models import Version @@ -180,6 +177,18 @@ def test_length_of_tags(self): error_msg = 'Length of each tag must be less than or equal to 100 characters.' self.assertDictEqual(form.errors, {'tags': [error_msg]}) + def test_strip_repo_url(self): + form = ProjectBasicsForm({ + 'name': 'foo', + 'repo_type': 'git', + 'repo': 'https://github.com/rtfd/readthedocs.org/' + }) + self.assertTrue(form.is_valid()) + self.assertEqual( + form.cleaned_data['repo'], + 'https://github.com/rtfd/readthedocs.org' + ) + class TestProjectAdvancedForm(TestCase): @@ -514,7 +523,7 @@ class TestNotificationForm(TestCase): def setUp(self): self.project = get(Project) - + def test_webhookform(self): self.assertEqual(self.project.webhook_notifications.all().count(), 0)