Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing slashes on svn checkout #4951

Merged
merged 8 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions readthedocs/rtd_tests/tests/test_backend_svn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""Tests For SVN"""

from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)

from mock import patch
from django_dynamic_fixture import get

from readthedocs.rtd_tests.base import RTDTestCase
from readthedocs.projects.models import Project
from readthedocs.builds.models import Version
from readthedocs.vcs_support.backends.svn import Backend as SvnBackend

class TestSvnBackend(RTDTestCase):

def test_get_url(self):
project = get(Project)
version = get(Version, project=project)
backend_obj = SvnBackend(project, version.slug)

base = 'http://example.com/'
tag = 'xyz/'
self.assertEqual(backend_obj.get_url(base, tag), 'http://example.com/xyz/')

base = 'http://example.com/'
tag = '/xyz/'
self.assertEqual(backend_obj.get_url(base, tag), 'http://example.com/xyz/')

base = 'http://example.com'
tag = '/xyz/'
self.assertEqual(backend_obj.get_url(base, tag), 'http://example.com/xyz/')
8 changes: 7 additions & 1 deletion readthedocs/vcs_support/backends/svn.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def up(self):
def co(self, identifier=None):
self.make_clean_working_dir()
if identifier:
url = self.base_url + identifier
url = self.get_url(self.base_url, identifier)
else:
url = self.repo_url
retcode, out, err = self.run('svn', 'checkout', url, '.')
Expand Down Expand Up @@ -104,3 +104,9 @@ def commit(self):
def checkout(self, identifier=None):
super(Backend, self).checkout()
return self.co(identifier)

def get_url(self, base_url, identifier):
base = base_url.rstrip('/')
tag = identifier.lstrip('/')
url = '{}/{}'.format(base, tag)
return url