adding tests to ftpserver
import logging
import os
-from ftplib import FTP
+import ftplib
+
+from pyftpdlib.test import unittest
+from pyftpdlib.test import MProcessTestFTPd
from django.test import TestCase
@@ -33,29 +36,42 @@ class DownloadTest(TestCase):
pass
-class UploadTest(TestCase):
-
-
- def setUp(self):
- from biostar.accounts.models import User
-
- self.address = ('lvh.me', 8021)
-
- self.pswd = "1234"
- self.user = User.objects.create_user(username="test", email="test", password=self.pswd, is_staff=True)
-
-
- def test_mkdir(self):
-
- with FTP(user=self.user.email, passwd=self.pswd, source_address=self.address) as ftp:
- ftp.connect(host=self.address[0], port=self.address[1], timeout=10)
- ftp.login(user=self.user.email, passwd=self.pswd)
- print(ftp.dir())
- 1/0
- return
-
+class TestFtpFsOperations(unittest.TestCase):
+ "test: PWD, CWD, CDUP, SIZE, RNFR, RNTO, DELE, MKD, RMD, MDTM, STAT, MFMT"
+ server_class = MProcessTestFTPd
+ client_class = ftplib.FTP
-
- pass
\ No newline at end of file
+ def setUp(self):
+ self.server = self.server_class()
+ self.server.start()
+ self.client = self.client_class(timeout=TIMEOUT)
+ self.client.connect(self.server.host, self.server.port)
+ self.client.login(USER, PASSWD)
+ self.tempfile = os.path.basename(touch(TESTFN))
+ self.tempdir = os.path.basename(tempfile.mkdtemp(dir=HOME))
+
+ def tearDown(self):
+ self.client.close()
+ self.server.stop()
+ safe_remove(self.tempfile)
+ if os.path.exists(self.tempdir):
+ shutil.rmtree(self.tempdir)
+
+
+ def test_mkd(self):
+ tempdir = os.path.basename(tempfile.mktemp(dir=HOME))
+ dirname = self.client.mkd(tempdir)
+ # the 257 response is supposed to include the absolute dirname
+ self.assertEqual(dirname, '/' + tempdir)
+ # make sure we can't create directories which already exist
+ # (probably not really necessary);
+ # let's use a try/except statement to avoid leaving behind
+ # orphaned temporary directory in the event of a test failure.
+ try:
+ self.client.mkd(tempdir)
+ except ftplib.error_perm:
+ os.rmdir(tempdir) # ok
+ else:
+ self.fail('ftplib.error_perm not raised.')
\ No newline at end of file
