[py-svn] r51424 - in py/branch/guido-svn-auth/py: . path/svn path/svn/testing
guido at codespeak.net
guido at codespeak.net
Tue Feb 12 21:41:48 CET 2008
Author: guido
Date: Tue Feb 12 21:41:45 2008
New Revision: 51424
Added:
py/branch/guido-svn-auth/py/path/svn/auth.py
py/branch/guido-svn-auth/py/path/svn/testing/test_auth.py
Modified:
py/branch/guido-svn-auth/py/__init__.py
py/branch/guido-svn-auth/py/path/svn/wccommand.py
Log:
First bits of svn auth support - added a class called SvnAuth to hold
credentials and some auth-related information, and made that svnwc's
constructor and its commit and checkout methods accept the class as argument.
Modified: py/branch/guido-svn-auth/py/__init__.py
==============================================================================
--- py/branch/guido-svn-auth/py/__init__.py (original)
+++ py/branch/guido-svn-auth/py/__init__.py Tue Feb 12 21:41:45 2008
@@ -67,6 +67,7 @@
'path.svnwc' : ('./path/svn/wccommand.py', 'SvnWCCommandPath'),
'path.svnurl' : ('./path/svn/urlcommand.py', 'SvnCommandPath'),
'path.local' : ('./path/local/local.py', 'LocalPath'),
+ 'path.SvnAuth' : ('./path/svn/auth.py', 'SvnAuth'),
# some nice slightly magic APIs
'magic.__doc__' : ('./magic/__init__.py', '__doc__'),
Added: py/branch/guido-svn-auth/py/path/svn/auth.py
==============================================================================
--- (empty file)
+++ py/branch/guido-svn-auth/py/path/svn/auth.py Tue Feb 12 21:41:45 2008
@@ -0,0 +1,14 @@
+class SvnAuth(object):
+ """ container for auth information for Subversion """
+ def __init__(self, username, password, auth_cache=True):
+ self.username = username
+ self.password = password
+ self.auth_cache = auth_cache
+
+ def __str__(self):
+ uname = self.username.replace('"', '\\"')
+ passwd = self.password.replace('"', '\\"')
+ ret = '--username="%s" --password="%s"' % (uname, passwd)
+ if not self.auth_cache:
+ ret += ' --no-auth-cache'
+ return ret
Added: py/branch/guido-svn-auth/py/path/svn/testing/test_auth.py
==============================================================================
--- (empty file)
+++ py/branch/guido-svn-auth/py/path/svn/testing/test_auth.py Tue Feb 12 21:41:45 2008
@@ -0,0 +1,58 @@
+import py
+from py.path import SvnAuth
+
+class TestSvnAuth(object):
+ def test_uname_pw(self):
+ auth = py.path.SvnAuth('foo', 'bar')
+ assert auth.username == 'foo'
+ assert auth.password == 'bar'
+
+ def test_uname_pw_str(self):
+ auth = py.path.SvnAuth('foo', 'bar')
+ assert str(auth) == '--username="foo" --password="bar"'
+
+ def test_quote_escape(self):
+ auth = py.path.SvnAuth('fo"o', '"ba\'r"')
+ assert str(auth) == '--username="fo\\"o" --password="\\"ba\'r\\""'
+
+ def test_no_auth_cache(self):
+ auth = py.path.SvnAuth('foo', 'bar', auth_cache=False)
+ assert str(auth) == '--username="foo" --password="bar" --no-auth-cache'
+
+class svnwc_no_svn(py.path.svnwc):
+ def __init__(self, *args, **kwargs):
+ self.commands = []
+ super(svnwc_no_svn, self).__init__(*args, **kwargs)
+
+ def _svn(self, *args):
+ self.commands.append(args)
+
+class TestSvnWCAuth(object):
+ def test_checkout(self):
+ wc = svnwc_no_svn('foo')
+ auth = SvnAuth('user', 'pass')
+ wc.checkout('url', auth=auth)
+ assert wc.commands == [('co', 'url',
+ '--username="user" --password="pass"')]
+
+ def test_commit(self):
+ wc = svnwc_no_svn('foo')
+ auth = SvnAuth('user', 'pass')
+ wc.commit('msg', auth=auth)
+ assert wc.commands == [('commit -m "msg" --force-log',
+ '--username="user" --password="pass"')]
+
+ def test_checkout_no_cache_auth(self):
+ wc = svnwc_no_svn('foo')
+ auth = SvnAuth('user', 'pass', auth_cache=False)
+ wc.checkout('url', auth=auth)
+ assert wc.commands == [('co', 'url',
+ ('--username="user" --password="pass" '
+ '--no-auth-cache'))]
+
+ def test_checkout_auth_from_constructor(self):
+ auth = SvnAuth('user', 'pass')
+ wc = svnwc_no_svn('foo', auth=auth)
+ wc.checkout('url')
+ assert wc.commands == [('co', 'url',
+ '--username="user" --password="pass"')]
Modified: py/branch/guido-svn-auth/py/path/svn/wccommand.py
==============================================================================
--- py/branch/guido-svn-auth/py/path/svn/wccommand.py (original)
+++ py/branch/guido-svn-auth/py/path/svn/wccommand.py Tue Feb 12 21:41:45 2008
@@ -25,7 +25,7 @@
"""
sep = os.sep
- def __new__(cls, wcpath=None):
+ def __new__(cls, wcpath=None, auth=None):
self = object.__new__(cls)
if isinstance(wcpath, cls):
if wcpath.__class__ == cls:
@@ -35,6 +35,7 @@
svncommon.ALLOWED_CHARS):
raise ValueError("bad char in wcpath %s" % (wcpath, ))
self.localpath = py.path.local(wcpath)
+ self._auth = auth
return self
strpath = property(lambda x: str(x.localpath), None, None, "string path")
@@ -105,7 +106,7 @@
""" switch to given URL. """
self._svn('switch', url)
- def checkout(self, url=None, rev=None):
+ def checkout(self, url=None, rev=None, auth=None):
""" checkout from url to local wcpath. """
args = []
if url is None:
@@ -119,6 +120,10 @@
url += "@%d" % rev
else:
args.append('-r' + str(rev))
+ if auth is not None:
+ args.append(str(auth))
+ elif self._auth is not None:
+ args.append(str(self._auth))
self._svn('co', url, *args)
def update(self, rev = 'HEAD'):
@@ -358,14 +363,19 @@
return result
_rex_commit = re.compile(r'.*Committed revision (\d+)\.$', re.DOTALL)
- def commit(self, msg='', rec=1):
+ def commit(self, msg='', rec=1, auth=None):
""" commit with support for non-recursive commits """
from py.__.path.svn import cache
# XXX i guess escaping should be done better here?!?
cmd = 'commit -m "%s" --force-log' % (msg.replace('"', '\\"'),)
if not rec:
cmd += ' -N'
- out = self._svn(cmd)
+ args = []
+ if auth is not None:
+ args.append(str(auth))
+ elif self._auth is not None:
+ args.append(str(self._auth))
+ out = self._svn(cmd, *args)
try:
del cache.info[self]
except KeyError:
More information about the pytest-commit
mailing list