comparison tests/test_urls.py @ 1453:d890d8d4e168

svnrepo: change svnurl to not use self.svn Before this patch, svnremoterepo uses self.svn.svn_url to answer svnurl. Accessing svnremoterepo.svn will create an svn ra object, which can be expensive because it involves network i/o. This patch changes it to use self.svnauth, which is a local operation. It speeds up "hg svn info" a lot. The old behavior is hard to test since instantiating a svn ra object requires a real URL. The change does not seem worth to set up SSH and HTTP servers to test. Therefore the tests are added only for the new behavior.
author Jun Wu <quark@fb.com>
date Sat, 11 Jun 2016 22:36:57 +0100
parents d741f536f23a
children 7917abf6b456
comparison
equal deleted inserted replaced
1452:4217a050a088 1453:d890d8d4e168
6 from hgsubversion.svnwrap import parse_url 6 from hgsubversion.svnwrap import parse_url
7 from hgsubversion import svnrepo 7 from hgsubversion import svnrepo
8 8
9 class TestSubversionUrls(test_util.TestBase): 9 class TestSubversionUrls(test_util.TestBase):
10 def test_standard_url(self): 10 def test_standard_url(self):
11 self.assertEqual((None, None, 'file:///var/svn/repo'), 11 self.check_parse_url((None, None, 'file:///var/svn/repo'),
12 parse_url('file:///var/svn/repo')) 12 ('file:///var/svn/repo', ))
13 13
14 def test_user_url(self): 14 def test_user_url(self):
15 self.assertEqual( 15 self.check_parse_url(
16 ('joe', None, 'https://svn.testurl.com/repo'), 16 ('joe', None, 'https://svn.testurl.com/repo'),
17 parse_url('https://joe@svn.testurl.com/repo')) 17 ('https://joe@svn.testurl.com/repo', ))
18 self.assertEqual( 18 self.check_parse_url(
19 ('bob', None, 'https://svn.testurl.com/repo'), 19 ('bob', None, 'https://svn.testurl.com/repo'),
20 parse_url('https://joe@svn.testurl.com/repo', 'bob')) 20 ('https://joe@svn.testurl.com/repo', 'bob', ))
21 21
22 def test_password_url(self): 22 def test_password_url(self):
23 self.assertEqual( 23 self.check_parse_url(
24 (None, 't3stpw', 'svn+ssh://svn.testurl.com/repo'), 24 (None, 't3stpw', 'svn+ssh://svn.testurl.com/repo'),
25 parse_url('svn+ssh://:t3stpw@svn.testurl.com/repo')) 25 ('svn+ssh://:t3stpw@svn.testurl.com/repo', ))
26 self.assertEqual( 26 self.check_parse_url(
27 (None, '123abc', 'svn+ssh://svn.testurl.com/repo'), 27 (None, '123abc', 'svn+ssh://svn.testurl.com/repo'),
28 parse_url('svn+ssh://:t3stpw@svn.testurl.com/repo', None, '123abc')) 28 ('svn+ssh://:t3stpw@svn.testurl.com/repo', None, '123abc', ))
29 29
30 def test_svnssh_preserve_user(self): 30 def test_svnssh_preserve_user(self):
31 self.assertEqual( 31 self.check_parse_url(
32 ('user', 't3stpw', 'svn+ssh://user@svn.testurl.com/repo',), 32 ('user', 't3stpw', 'svn+ssh://user@svn.testurl.com/repo',),
33 parse_url('svn+ssh://user:t3stpw@svn.testurl.com/repo')) 33 ('svn+ssh://user:t3stpw@svn.testurl.com/repo', ))
34 self.assertEqual( 34 self.check_parse_url(
35 ('bob', '123abc', 'svn+ssh://bob@svn.testurl.com/repo',), 35 ('bob', '123abc', 'svn+ssh://bob@svn.testurl.com/repo',),
36 parse_url('svn+ssh://user:t3stpw@svn.testurl.com/repo', 'bob', '123abc')) 36 ('svn+ssh://user:t3stpw@svn.testurl.com/repo', 'bob', '123abc', ))
37 self.assertEqual( 37 self.check_parse_url(
38 ('user2', None, 'svn+ssh://user2@svn.testurl.com/repo',), 38 ('user2', None, 'svn+ssh://user2@svn.testurl.com/repo',),
39 parse_url('svn+ssh://user2@svn.testurl.com/repo')) 39 ('svn+ssh://user2@svn.testurl.com/repo', ))
40 self.assertEqual( 40 self.check_parse_url(
41 ('bob', None, 'svn+ssh://bob@svn.testurl.com/repo',), 41 ('bob', None, 'svn+ssh://bob@svn.testurl.com/repo',),
42 parse_url('svn+ssh://user2@svn.testurl.com/repo', 'bob')) 42 ('svn+ssh://user2@svn.testurl.com/repo', 'bob', ))
43 43
44 def test_user_password_url(self): 44 def test_user_password_url(self):
45 self.assertEqual( 45 self.check_parse_url(
46 ('joe', 't3stpw', 'https://svn.testurl.com/repo'), 46 ('joe', 't3stpw', 'https://svn.testurl.com/repo'),
47 parse_url('https://joe:t3stpw@svn.testurl.com/repo')) 47 ('https://joe:t3stpw@svn.testurl.com/repo', ))
48 self.assertEqual( 48 self.check_parse_url(
49 ('bob', '123abc', 'https://svn.testurl.com/repo'), 49 ('bob', '123abc', 'https://svn.testurl.com/repo'),
50 parse_url('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc')) 50 ('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc', ))
51 51
52 def test_url_rewriting(self): 52 def test_url_rewriting(self):
53 ui = test_util.ui.ui() 53 ui = test_util.ui.ui()
54 ui.setconfig('hgsubversion', 'username', 'bob') 54 ui.setconfig('hgsubversion', 'username', 'bob')
55 repo = svnrepo.svnremoterepo(ui, 'svn+ssh://joe@foo/bar') 55 repo = svnrepo.svnremoterepo(ui, 'svn+ssh://joe@foo/bar')
56 self.assertEqual('svn+ssh://bob@foo/bar', repo.svnauth[0]) 56 self.assertEqual('svn+ssh://bob@foo/bar', repo.svnauth[0])
57 self.assertEqual('svn+ssh://bob@foo/bar', repo.svnurl)
57 58
58 repo = svnrepo.svnremoterepo(ui, 'svn+http://joe@foo/bar') 59 repo = svnrepo.svnremoterepo(ui, 'svn+http://joe@foo/bar')
59 self.assertEqual(('http://foo/bar', 'bob', None), repo.svnauth) 60 self.assertEqual(('http://foo/bar', 'bob', None), repo.svnauth)
61 self.assertEqual('http://foo/bar', repo.svnurl)
60 62
61 repo = svnrepo.svnremoterepo(ui, 'svn+https://joe@foo/bar') 63 repo = svnrepo.svnremoterepo(ui, 'svn+https://joe@foo/bar')
62 self.assertEqual(('https://foo/bar', 'bob', None), repo.svnauth) 64 self.assertEqual(('https://foo/bar', 'bob', None), repo.svnauth)
65 self.assertEqual('https://foo/bar', repo.svnurl)
63 66
64 def test_quoting(self): 67 def test_quoting(self):
65 ui = self.ui() 68 ui = self.ui()
66 repo_path = self.load_svndump('non_ascii_path_1.svndump') 69 repo_path = self.load_svndump('non_ascii_path_1.svndump')
67 70
70 quoted_subdir = urllib.quote(subdir) 73 quoted_subdir = urllib.quote(subdir)
71 74
72 repo1 = svnrepo.svnremoterepo(ui, repo_url + subdir) 75 repo1 = svnrepo.svnremoterepo(ui, repo_url + subdir)
73 repo2 = svnrepo.svnremoterepo(ui, repo_url + quoted_subdir) 76 repo2 = svnrepo.svnremoterepo(ui, repo_url + quoted_subdir)
74 self.assertEqual(repo1.svnurl, repo2.svnurl) 77 self.assertEqual(repo1.svnurl, repo2.svnurl)
78
79 def check_parse_url(self, expected, args):
80 self.assertEqual(expected, parse_url(*args))
81 if len(args) == 1:
82 repo = svnrepo.svnremoterepo(self.ui(), path=args[0])
83 self.assertEqual(expected[2], repo.svnauth[0])
84 self.assertEqual(expected[2], repo.svnurl)
85