view tests/test_urls.py @ 1512:6d0fe7ce9898

commands: fix command option registering A recent patch introduced svnopts as a way of sharing the svn command options between the old and the new way of registering a command. It turns out 'svnopts' was already used further up in the module to define the flags that should be added to *all* Mercurial commands. So our definition of it here cause us to add all of these options to all Mercurial commands. This was caught because it changes --rev to be '' instead of [], which breaks a number of assumptions in the other commands. Given that none of the subversion tests are command line tests, I'm not sure how to test this. It was caught in other extensions tests. (grafted from 3b1334407783a4379fd515e2ed9acc61e3f175ff) (grafted from 6db63ead5556f2bf72e423ca8c6df08ea3a5b009)
author Durham Goode <durham@fb.com>
date Wed, 24 May 2017 15:07:00 -0700
parents d890d8d4e168
children 7917abf6b456
line wrap: on
line source

import test_util

import unittest
import urllib

from hgsubversion.svnwrap import parse_url
from hgsubversion import svnrepo

class TestSubversionUrls(test_util.TestBase):
    def test_standard_url(self):
        self.check_parse_url((None, None, 'file:///var/svn/repo'),
                             ('file:///var/svn/repo', ))

    def test_user_url(self):
        self.check_parse_url(
            ('joe', None, 'https://svn.testurl.com/repo'),
            ('https://joe@svn.testurl.com/repo', ))
        self.check_parse_url(
            ('bob', None, 'https://svn.testurl.com/repo'),
            ('https://joe@svn.testurl.com/repo', 'bob', ))

    def test_password_url(self):
        self.check_parse_url(
            (None, 't3stpw', 'svn+ssh://svn.testurl.com/repo'),
            ('svn+ssh://:t3stpw@svn.testurl.com/repo', ))
        self.check_parse_url(
            (None, '123abc', 'svn+ssh://svn.testurl.com/repo'),
            ('svn+ssh://:t3stpw@svn.testurl.com/repo', None, '123abc', ))

    def test_svnssh_preserve_user(self):
        self.check_parse_url(
            ('user', 't3stpw', 'svn+ssh://user@svn.testurl.com/repo',),
            ('svn+ssh://user:t3stpw@svn.testurl.com/repo', ))
        self.check_parse_url(
            ('bob', '123abc', 'svn+ssh://bob@svn.testurl.com/repo',),
            ('svn+ssh://user:t3stpw@svn.testurl.com/repo', 'bob', '123abc', ))
        self.check_parse_url(
            ('user2', None, 'svn+ssh://user2@svn.testurl.com/repo',),
            ('svn+ssh://user2@svn.testurl.com/repo', ))
        self.check_parse_url(
            ('bob', None, 'svn+ssh://bob@svn.testurl.com/repo',),
            ('svn+ssh://user2@svn.testurl.com/repo', 'bob', ))

    def test_user_password_url(self):
        self.check_parse_url(
            ('joe', 't3stpw', 'https://svn.testurl.com/repo'),
            ('https://joe:t3stpw@svn.testurl.com/repo', ))
        self.check_parse_url(
            ('bob', '123abc', 'https://svn.testurl.com/repo'),
            ('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc', ))

    def test_url_rewriting(self):
        ui = test_util.ui.ui()
        ui.setconfig('hgsubversion', 'username', 'bob')
        repo = svnrepo.svnremoterepo(ui, 'svn+ssh://joe@foo/bar')
        self.assertEqual('svn+ssh://bob@foo/bar', repo.svnauth[0])
        self.assertEqual('svn+ssh://bob@foo/bar', repo.svnurl)

        repo = svnrepo.svnremoterepo(ui, 'svn+http://joe@foo/bar')
        self.assertEqual(('http://foo/bar', 'bob', None), repo.svnauth)
        self.assertEqual('http://foo/bar', repo.svnurl)

        repo = svnrepo.svnremoterepo(ui, 'svn+https://joe@foo/bar')
        self.assertEqual(('https://foo/bar', 'bob', None), repo.svnauth)
        self.assertEqual('https://foo/bar', repo.svnurl)

    def test_quoting(self):
        ui = self.ui()
        repo_path = self.load_svndump('non_ascii_path_1.svndump')

        repo_url = test_util.fileurl(repo_path)
        subdir = '/b\xC3\xB8b'
        quoted_subdir = urllib.quote(subdir)

        repo1 = svnrepo.svnremoterepo(ui, repo_url + subdir)
        repo2 = svnrepo.svnremoterepo(ui, repo_url + quoted_subdir)
        self.assertEqual(repo1.svnurl, repo2.svnurl)

    def check_parse_url(self, expected, args):
        self.assertEqual(expected, parse_url(*args))
        if len(args) == 1:
            repo = svnrepo.svnremoterepo(self.ui(), path=args[0])
            self.assertEqual(expected[2], repo.svnauth[0])
            self.assertEqual(expected[2], repo.svnurl)