[Checkins] SVN: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/tests.py Beginning work on tests.

Jim Fulton jim at zope.com
Wed Sep 13 07:22:30 EDT 2006


Log message for revision 70143:
  Beginning work on tests.
  

Changed:
  A   zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/tests.py

-=-
Added: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/tests.py
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/tests.py	2006-09-13 11:21:59 UTC (rev 70142)
+++ zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/tests.py	2006-09-13 11:22:29 UTC (rev 70143)
@@ -0,0 +1,93 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os, sys
+
+import paramiko
+
+from zope.testing import doctest
+
+class Replace:
+
+    def __init__(self, module, **attrs):
+        self.module = module
+        self.original = original = {}
+
+        for name, value in attrs.iteritems():
+            original[name] = getattr(module, name)
+            setattr(module, name, value)
+
+    def restore(self):
+        for name, value in self.attrs.iteritems():
+            setattt(self.module, name, value)
+
+hkeys = [
+    ('foo.com', 'comkey'),
+    ('foo.org', 'orgkey'),
+    ('foo.net', 'netkey'),
+    ('foo.biz', 'bizkey'),
+    ]
+
+def setup(test):
+    # We're going to replace much of paramiko, and, if necessary, _winreg
+    # to try to control urllib2sftp's environment.
+
+    teardown = []
+    test.globs['__teardown'] = teardown
+
+    test.globs['__HOME'] = os.environ.get('HOME')
+    os.environ['HOME'] == '/testhome'
+
+    if sys.platform == 'win32':
+        import _winreg
+
+        key = object()
+
+        def OpenKey(*args):
+            if args != (_winreg.HKEY_CURENT_USER,
+                        r'Software\SimonTatham\PuTTY\SshHoskKeys'):
+                raise ValueError("Bad keys", *args)
+            return key
+
+        def EnumValue(k, index):
+            if k is not key:
+                raise ValueError('Bad key')
+            try:
+                host, hkey = hkeys[index]
+            except IndexError:
+                raise WindowsError(index)
+            
+            return 'rsa at 22:'+host, hkey, 0
+
+        HostKeys = paramiko.HostKeys
+
+        teardown.append(Replace(_winreg,
+                                OpenKey=OpenKey,
+                                EnumValue=EnumValue,
+                                ).restore
+                        )
+    else:
+        def HostKeys(path=None):
+            if path != '/testhome/.ssh/known_hosts':
+                raise IOError('No suh file', path)
+            return dict([
+                (host, {'ssh-rsa': paramiko.PKey(hkey)})
+                for (host, hkey) in hkeys
+                ])
+
+    
+
+def test_suite():
+    return doctest.DocTestSuite()
+


Property changes on: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list