4udak / pyftpdlib

Automatically exported from code.google.com/p/pyftpdlib
Other
1 stars 1 forks source link

Unit tests for demo scripts #224

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Still provisional and it won't probably get in anyway. 
Just needed a place where to put this without loosing it.

import subprocess

class TestDemoScripts(unittest.TestCase):

    def setUp(self):
        self.subp = None
        self.client = None

    def tearDown(self):
        self.subp.terminate()
        self.subp.wait()
        self.client.close()

    def run_script(self, name):
        DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../demo'))
        exe = os.path.join(DIR, name)
        self.subp = subprocess.Popen([sys.executable, exe])

    def connect_ftp(self, client):
        for x in range(100):
            try:
                client.connect('localhost', 2121)
            except socket.error:
                time.sleep(.01)
            else:
                return client
        else:
            raise

    def test_base_ftpd(self):
        self.run_script('basic_ftpd.py')
        self.client = ftplib.FTP()
        self.connect_ftp(self.client)
        self.client.login('user', '12345')
        self.client.dir(lambda x: 0)

    def test_basic_ftpd(self):
        self.run_script('basic_ftpd.py')
        self.client = ftplib.FTP()
        self.connect_ftp(self.client)
        self.client.login('user', '12345')
        self.client.dir(lambda x: 0)

    def test_md5_ftpd(self):
        self.run_script('md5_ftpd.py')
        self.client = ftplib.FTP()
        self.connect_ftp(self.client)
        self.client.login('user', '12345')
        self.client.dir(lambda x: 0)

    #def test_unix_ftpd(self):
    #def test_unix_daemon(self):

Original issue reported on code.google.com by g.rodola on 2 Nov 2012 at 8:35