Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_ftplib.TestTLS_FTPClassMixin Class Reference
Inheritance diagram for test.test_ftplib.TestTLS_FTPClassMixin:
Inheritance graph
[legend]
Collaboration diagram for test.test_ftplib.TestTLS_FTPClassMixin:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def tearDown
def test_getwelcome
def test_sanitize
def test_exceptions
def test_all_errors
def test_set_pasv
def test_voidcmd
def test_login
def test_acct
def test_rename
def test_delete
def test_size
def test_mkd
def test_rmd
def test_pwd
def test_quit
def test_abort
def test_retrbinary
def test_retrbinary_rest
def test_retrlines
def test_storbinary
def test_storbinary_rest
def test_storlines
def test_nlst
def test_dir
def test_makeport
def test_makepasv
def test_with_statement
def test_parse257

Public Attributes

 server
 client

Detailed Description

Repeat TestFTPClass tests starting the TLS layer for both control
and data connections first.

Definition at line 671 of file test_ftplib.py.


Member Function Documentation

Reimplemented from test.test_ftplib.TestFTPClass.

Definition at line 676 of file test_ftplib.py.

00676 
00677     def setUp(self):
00678         self.server = DummyTLS_FTPServer((HOST, 0))
00679         self.server.start()
00680         self.client = ftplib.FTP_TLS(timeout=10)
00681         self.client.connect(self.server.host, self.server.port)
00682         # enable TLS
00683         self.client.auth()
00684         self.client.prot_p()
00685 

Here is the caller graph for this function:

def test.test_ftplib.TestFTPClass.tearDown (   self) [inherited]

Definition at line 422 of file test_ftplib.py.

00422 
00423     def tearDown(self):
00424         self.client.close()
00425         self.server.stop()

Here is the caller graph for this function:

def test.test_ftplib.TestFTPClass.test_abort (   self) [inherited]

Definition at line 499 of file test_ftplib.py.

00499 
00500     def test_abort(self):
00501         self.client.abort()

def test.test_ftplib.TestFTPClass.test_acct (   self) [inherited]

Definition at line 467 of file test_ftplib.py.

00467 
00468     def test_acct(self):
00469         self.client.acct('passwd')

Definition at line 441 of file test_ftplib.py.

00441 
00442     def test_all_errors(self):
00443         exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
00444                       ftplib.error_proto, ftplib.Error, IOError, EOFError)
00445         for x in exceptions:
00446             try:
00447                 raise x('exception not included in all_errors set')
00448             except ftplib.all_errors:
00449                 pass

def test.test_ftplib.TestFTPClass.test_delete (   self) [inherited]

Definition at line 475 of file test_ftplib.py.

00475 
00476     def test_delete(self):
00477         self.client.delete('foo')
00478         self.server.handler_instance.next_response = '199'
00479         self.assertRaises(ftplib.error_reply, self.client.delete, 'foo')

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_dir (   self) [inherited]

Definition at line 556 of file test_ftplib.py.

00556 
00557     def test_dir(self):
00558         l = []
00559         self.client.dir(lambda x: l.append(x))
00560         self.assertEqual(''.join(l), LIST_DATA.replace('\r\n', ''))

Here is the call graph for this function:

Definition at line 434 of file test_ftplib.py.

00434 
00435     def test_exceptions(self):
00436         self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 400')
00437         self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 499')
00438         self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 500')
00439         self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 599')
00440         self.assertRaises(ftplib.error_proto, self.client.sendcmd, 'echo 999')

Here is the call graph for this function:

Definition at line 426 of file test_ftplib.py.

00426 
00427     def test_getwelcome(self):
00428         self.assertEqual(self.client.getwelcome(), '220 welcome')

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_login (   self) [inherited]

Definition at line 464 of file test_ftplib.py.

00464 
00465     def test_login(self):
00466         self.client.login()

def test.test_ftplib.TestFTPClass.test_makepasv (   self) [inherited]

Definition at line 567 of file test_ftplib.py.

00567 
00568     def test_makepasv(self):
00569         host, port = self.client.makepasv()
00570         conn = socket.create_connection((host, port), 10)
00571         conn.close()
00572         # IPv4 is in use, just make sure send_epsv has not been used
00573         self.assertEqual(self.server.handler_instance.last_received_cmd, 'pasv')

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_makeport (   self) [inherited]

Definition at line 561 of file test_ftplib.py.

00561 
00562     def test_makeport(self):
00563         with self.client.makeport():
00564             # IPv4 is in use, just make sure send_eprt has not been used
00565             self.assertEqual(self.server.handler_instance.last_received_cmd,
00566                                 'port')

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_mkd (   self) [inherited]

Definition at line 483 of file test_ftplib.py.

00483 
00484     def test_mkd(self):
00485         dir = self.client.mkd('/foo')
00486         self.assertEqual(dir, '/foo')

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_nlst (   self) [inherited]

Definition at line 552 of file test_ftplib.py.

00552 
00553     def test_nlst(self):
00554         self.client.nlst()
00555         self.assertEqual(self.client.nlst(), NLST_DATA.split('\r\n')[:-1])

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_parse257 (   self) [inherited]

Definition at line 619 of file test_ftplib.py.

00619 
00620     def test_parse257(self):
00621         self.assertEqual(ftplib.parse257('257 "/foo/bar"'), '/foo/bar')
00622         self.assertEqual(ftplib.parse257('257 "/foo/bar" created'), '/foo/bar')
00623         self.assertEqual(ftplib.parse257('257 ""'), '')
00624         self.assertEqual(ftplib.parse257('257 "" created'), '')
00625         self.assertRaises(ftplib.error_reply, ftplib.parse257, '250 "/foo/bar"')
00626         # The 257 response is supposed to include the directory
00627         # name and in case it contains embedded double-quotes
00628         # they must be doubled (see RFC-959, chapter 7, appendix 2).
00629         self.assertEqual(ftplib.parse257('257 "/foo/b""ar"'), '/foo/b"ar')
00630         self.assertEqual(ftplib.parse257('257 "/foo/b""ar" created'), '/foo/b"ar')
00631 

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_pwd (   self) [inherited]

Definition at line 490 of file test_ftplib.py.

00490 
00491     def test_pwd(self):
00492         dir = self.client.pwd()
00493         self.assertEqual(dir, 'pwd ok')

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_quit (   self) [inherited]

Definition at line 494 of file test_ftplib.py.

00494 
00495     def test_quit(self):
00496         self.assertEqual(self.client.quit(), '221 quit ok')
00497         # Ensure the connection gets closed; sock attribute should be None
00498         self.assertEqual(self.client.sock, None)

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_rename (   self) [inherited]

Definition at line 470 of file test_ftplib.py.

00470 
00471     def test_rename(self):
00472         self.client.rename('a', 'b')
00473         self.server.handler_instance.next_response = '200'
00474         self.assertRaises(ftplib.error_reply, self.client.rename, 'a', 'b')

Here is the call graph for this function:

Definition at line 502 of file test_ftplib.py.

00502 
00503     def test_retrbinary(self):
00504         def callback(data):
00505             received.append(data.decode('ascii'))
00506         received = []
00507         self.client.retrbinary('retr', callback)
00508         self.assertEqual(''.join(received), RETR_DATA)

Here is the call graph for this function:

Definition at line 509 of file test_ftplib.py.

00509 
00510     def test_retrbinary_rest(self):
00511         def callback(data):
00512             received.append(data.decode('ascii'))
00513         for rest in (0, 10, 20):
00514             received = []
00515             self.client.retrbinary('retr', callback, rest=rest)
00516             self.assertEqual(''.join(received), RETR_DATA[rest:],
00517                              msg='rest test case %d %d %d' % (rest,
00518                                                               len(''.join(received)),
00519                                                               len(RETR_DATA[rest:])))

Here is the call graph for this function:

Definition at line 520 of file test_ftplib.py.

00520 
00521     def test_retrlines(self):
00522         received = []
00523         self.client.retrlines('retr', received.append)
00524         self.assertEqual(''.join(received), RETR_DATA.replace('\r\n', ''))

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_rmd (   self) [inherited]

Definition at line 487 of file test_ftplib.py.

00487 
00488     def test_rmd(self):
00489         self.client.rmd('foo')

def test.test_ftplib.TestFTPClass.test_sanitize (   self) [inherited]

Definition at line 429 of file test_ftplib.py.

00429 
00430     def test_sanitize(self):
00431         self.assertEqual(self.client.sanitize('foo'), repr('foo'))
00432         self.assertEqual(self.client.sanitize('pass 12345'), repr('pass *****'))
00433         self.assertEqual(self.client.sanitize('PASS 12345'), repr('PASS *****'))

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_set_pasv (   self) [inherited]

Definition at line 450 of file test_ftplib.py.

00450 
00451     def test_set_pasv(self):
00452         # passive mode is supposed to be enabled by default
00453         self.assertTrue(self.client.passiveserver)
00454         self.client.set_pasv(True)
00455         self.assertTrue(self.client.passiveserver)
00456         self.client.set_pasv(False)
00457         self.assertFalse(self.client.passiveserver)

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_size (   self) [inherited]

Definition at line 480 of file test_ftplib.py.

00480 
00481     def test_size(self):
00482         self.client.size('foo')

Definition at line 525 of file test_ftplib.py.

00525 
00526     def test_storbinary(self):
00527         f = io.BytesIO(RETR_DATA.encode('ascii'))
00528         self.client.storbinary('stor', f)
00529         self.assertEqual(self.server.handler_instance.last_received_data, RETR_DATA)
00530         # test new callback arg
00531         flag = []
00532         f.seek(0)
00533         self.client.storbinary('stor', f, callback=lambda x: flag.append(None))
00534         self.assertTrue(flag)

Here is the call graph for this function:

Definition at line 535 of file test_ftplib.py.

00535 
00536     def test_storbinary_rest(self):
00537         f = io.BytesIO(RETR_DATA.replace('\r\n', '\n').encode('ascii'))
00538         for r in (30, '30'):
00539             f.seek(0)
00540             self.client.storbinary('stor', f, rest=r)
00541             self.assertEqual(self.server.handler_instance.rest, str(r))

Here is the call graph for this function:

Definition at line 542 of file test_ftplib.py.

00542 
00543     def test_storlines(self):
00544         f = io.BytesIO(RETR_DATA.replace('\r\n', '\n').encode('ascii'))
00545         self.client.storlines('stor', f)
00546         self.assertEqual(self.server.handler_instance.last_received_data, RETR_DATA)
00547         # test new callback arg
00548         flag = []
00549         f.seek(0)
00550         self.client.storlines('stor foo', f, callback=lambda x: flag.append(None))
00551         self.assertTrue(flag)

Here is the call graph for this function:

def test.test_ftplib.TestFTPClass.test_voidcmd (   self) [inherited]

Definition at line 458 of file test_ftplib.py.

00458 
00459     def test_voidcmd(self):
00460         self.client.voidcmd('echo 200')
00461         self.client.voidcmd('echo 299')
00462         self.assertRaises(ftplib.error_reply, self.client.voidcmd, 'echo 199')
00463         self.assertRaises(ftplib.error_reply, self.client.voidcmd, 'echo 300')

Here is the call graph for this function:

Definition at line 574 of file test_ftplib.py.

00574 
00575     def test_with_statement(self):
00576         self.client.quit()
00577 
00578         def is_client_connected():
00579             if self.client.sock is None:
00580                 return False
00581             try:
00582                 self.client.sendcmd('noop')
00583             except (socket.error, EOFError):
00584                 return False
00585             return True
00586 
00587         # base test
00588         with ftplib.FTP(timeout=10) as self.client:
00589             self.client.connect(self.server.host, self.server.port)
00590             self.client.sendcmd('noop')
00591             self.assertTrue(is_client_connected())
00592         self.assertEqual(self.server.handler_instance.last_received_cmd, 'quit')
00593         self.assertFalse(is_client_connected())
00594 
00595         # QUIT sent inside the with block
00596         with ftplib.FTP(timeout=10) as self.client:
00597             self.client.connect(self.server.host, self.server.port)
00598             self.client.sendcmd('noop')
00599             self.client.quit()
00600         self.assertEqual(self.server.handler_instance.last_received_cmd, 'quit')
00601         self.assertFalse(is_client_connected())
00602 
00603         # force a wrong response code to be sent on QUIT: error_perm
00604         # is expected and the connection is supposed to be closed
00605         try:
00606             with ftplib.FTP(timeout=10) as self.client:
00607                 self.client.connect(self.server.host, self.server.port)
00608                 self.client.sendcmd('noop')
00609                 self.server.handler_instance.next_response = '550 error on quit'
00610         except ftplib.error_perm as err:
00611             self.assertEqual(str(err), '550 error on quit')
00612         else:
00613             self.fail('Exception not raised')
00614         # needed to give the threaded server some time to set the attribute
00615         # which otherwise would still be == 'noop'
00616         time.sleep(0.1)
00617         self.assertEqual(self.server.handler_instance.last_received_cmd, 'quit')
00618         self.assertFalse(is_client_connected())

Here is the call graph for this function:


Member Data Documentation

Reimplemented from test.test_ftplib.TestFTPClass.

Definition at line 679 of file test_ftplib.py.

Reimplemented from test.test_ftplib.TestFTPClass.

Definition at line 677 of file test_ftplib.py.


The documentation for this class was generated from the following file: