[Zope3-checkins] CVS: Zope3/src/zope/server/ftp/tests - test_osemulators.py:1.1 test_ftpserver.py:1.3

Jim Fulton jim@zope.com
Thu, 30 Jan 2003 11:01:13 -0500


Update of /cvs-repository/Zope3/src/zope/server/ftp/tests
In directory cvs.zope.org:/tmp/cvs-serv19284/tests

Modified Files:
	test_ftpserver.py 
Added Files:
	test_osemulators.py 
Log Message:
Added support for -l, -a, and -d options to list command handling.


=== Added File Zope3/src/zope/server/ftp/tests/test_osemulators.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""XXX short summary goes here.

XXX longer description goes here.

$Id: test_osemulators.py,v 1.1 2003/01/30 16:01:11 jim Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite
from datetime import datetime, timedelta, tzinfo
from zope.server.ftp.osemulators import ls_date

class tzinfo(tzinfo):
    def utcoffset(self, dt):
        return 300
    def dst(self, dt):
        pass
    def tsname(self, dt):
        pass

class Test(TestCase):

    def test_ls_date(self):
        # test recent dates
        now = datetime(2003, 1, 27, 15, 56, 37)
        t = now - timedelta(hours=1, minutes=23, seconds=14,
                            milliseconds=123)
        t = t.replace(tzinfo = tzinfo())

        self.assertEqual(ls_date(now, t), 'Jan 27 14:33')

        # test less recent dates
        t = t - timedelta(days=175, hours=1, minutes=23, seconds=14,
                          milliseconds=123)
        self.assertEqual(ls_date(now, t), 'Aug 05 13:10')

        # test non recent dates
        t = t - timedelta(days=10, hours=1, minutes=23, seconds=14,
                          milliseconds=123)
        self.assertEqual(ls_date(now, t), 'Jul 26 2002')

        # test really old dates
        t = t - timedelta(days=20000, hours=1, minutes=23, seconds=14,
                          milliseconds=123)
        self.assertEqual(ls_date(now, t), 'Oct 23 1947')
    

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Zope3/src/zope/server/ftp/tests/test_ftpserver.py 1.2 => 1.3 ===
--- Zope3/src/zope/server/ftp/tests/test_ftpserver.py:1.2	Wed Dec 25 09:15:24 2002
+++ Zope3/src/zope/server/ftp/tests/test_ftpserver.py	Thu Jan 30 11:01:11 2003
@@ -204,6 +204,26 @@
             self.assertRaises(ftplib.Error, retrlines, conn, 'LIST /foo')
             listing = retrlines(conn, 'LIST')
             self.assert_(len(listing) > 0)
+            listing = retrlines(conn, 'LIST -la')
+            self.assert_(len(listing) > 0)
+        finally:
+            conn.close()
+        # Make sure no garbage was left behind.
+        self.testNOOP()
+
+    def testMKDLIST(self):
+        self.execute(['MKD f1', 'MKD f2'], 1)
+        conn = ftplib.FTP()
+        try:
+            conn.connect(LOCALHOST, self.port)
+            conn.login('foo', 'bar')
+            listing = []
+            conn.retrlines('LIST', listing.append)
+            self.assert_(len(listing) > 2)
+            listing = []
+            conn.retrlines('LIST -lad f1', listing.append)
+            self.assertEqual(len(listing), 1)
+            self.assertEqual(listing[0][0], 'd')
         finally:
             conn.close()
         # Make sure no garbage was left behind.