From bc7871e2f94b2ff0a8309f4f96cfcc27f0436c3d Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Wed, 3 Nov 2010 13:26:05 +0200 Subject: [PATCH] doc ftp: some assertions, close ftp sessions at YML tests bzr revid: p_christ@hol.gr-20101103112605-dq8jthkma78ccmcj --- .../document_ftp/ftpserver/abstracted_fs.py | 2 ++ addons/document_ftp/ftpserver/ftpserver.py | 1 + .../document_ftp/test/document_ftp_test2.yml | 31 +++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/addons/document_ftp/ftpserver/abstracted_fs.py b/addons/document_ftp/ftpserver/abstracted_fs.py index 9c16e7dde55..5eddffef4cb 100644 --- a/addons/document_ftp/ftpserver/abstracted_fs.py +++ b/addons/document_ftp/ftpserver/abstracted_fs.py @@ -146,6 +146,7 @@ class abstracted_fs(object): ret = child.open_data(cr, mode) cr.commit() + assert ret, "Cannot create descriptor for %r: %r" % (child, ret) return ret except EnvironmentError: raise @@ -156,6 +157,7 @@ class abstracted_fs(object): try: child = node.create_child(cr, objname, data=None) ret = child.open_data(cr, mode) + assert ret, "cannot create descriptor for %r" % child cr.commit() return ret except EnvironmentError: diff --git a/addons/document_ftp/ftpserver/ftpserver.py b/addons/document_ftp/ftpserver/ftpserver.py index 710494bb9db..bd727427541 100644 --- a/addons/document_ftp/ftpserver/ftpserver.py +++ b/addons/document_ftp/ftpserver/ftpserver.py @@ -2223,6 +2223,7 @@ class FTPHandler(asynchat.async_chat): if self.restart_position: mode = 'r+' fd = self.try_as_current_user(self.fs.create, (datacr, datacr[2], mode + 'b')) + assert fd except FTPExceptionSent: self.fs.close_cr(datacr) return diff --git a/addons/document_ftp/test/document_ftp_test2.yml b/addons/document_ftp/test/document_ftp_test2.yml index da55c353767..5da4bcd83ef 100644 --- a/addons/document_ftp/test/document_ftp_test2.yml +++ b/addons/document_ftp/test/document_ftp_test2.yml @@ -7,6 +7,7 @@ from document_ftp import test_easyftp as te ftp = te.get_plain_ftp(timeout=2.0) assert ftp.sock and (ftp.lastresp == '220'), ftp.lastresp + ftp.close() - I read the list of databases at port 8021 and confirm our db is there @@ -15,6 +16,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_login(cr, uid, self) assert cr.dbname in ftp.nlst("/") + ftp.close() - I try to locate the default "Documents" folder in the db. - @@ -22,6 +24,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_login(cr, uid, self) ftp.cwd('Documents') + ftp.close() - I create a "test.txt" file at the server (directly). The file should have the "abcd" content @@ -32,6 +35,7 @@ ftp = te.get_ftp_folder(cr, uid, self, 'Documents') fdata = StringIO('abcd') ftp.storbinary('STOR test.txt', fdata) + ftp.close() - I look for the "test.txt" file at the server - @@ -39,6 +43,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents') assert ftp.nlst("test.txt") == ['test.txt'] + ftp.close() - I check that the content of "test.txt" is "abcd" - @@ -46,7 +51,9 @@ from document_ftp import test_easyftp as te from cStringIO import StringIO ftp = te.get_ftp_folder(cr, uid, self, 'Documents') - assert te.get_ftp_fulldata(ftp, "test.txt") == 'abcd' + gotdata = te.get_ftp_fulldata(ftp, "test.txt") + ftp.close() + assert gotdata == 'abcd', 'Data: %r' % gotdata - I append the string 'defgh' to "test.txt" - @@ -56,6 +63,7 @@ ftp = te.get_ftp_folder(cr, uid, self, 'Documents') fdata = StringIO('defgh') ftp.storbinary('APPE test.txt', fdata) + ftp.close() - I check that the content of "text.txt" is 'abcddefgh' - @@ -63,7 +71,9 @@ from document_ftp import test_easyftp as te from cStringIO import StringIO ftp = te.get_ftp_folder(cr, uid, self, 'Documents') - assert te.get_ftp_fulldata(ftp, "test.txt") == 'abcddefgh' + gotdata = te.get_ftp_fulldata(ftp, "test.txt") + ftp.close() + assert gotdata == 'abcddefgh', 'Data: %r' % gotdata - I try to cd into an non-existing folder 'Not-This' - @@ -77,7 +87,9 @@ except ftplib.error_perm: pass except OSError, err: + ftp.close() assert err.errno == 2, err.errno + ftp.close() - I create a "test2.txt" file through FTP. - @@ -87,6 +99,7 @@ ftp = te.get_ftp_folder(cr, uid, self, 'Documents') fdata = StringIO('abcd') ftp.storbinary('STOR test2.txt', fdata) + ftp.close() - I look for the "test2.txt" file at the server - @@ -101,6 +114,7 @@ from cStringIO import StringIO ftp = te.get_ftp_folder(cr, uid, self, 'Documents') ftp.delete('test2.txt') + ftp.close() - I check at the server that test2.txt is deleted - @@ -116,6 +130,7 @@ ftp = te.get_ftp_folder(cr, uid, self, 'Documents') fdata = StringIO('abcd') ftp.storbinary('STOR test2.txt', fdata) + ftp.close() - I delete the test2.txt from the server (RPC). - @@ -137,6 +152,7 @@ except ftplib.error_perm: # 550 error: 'path not exists' nlst_result = [] assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result + ftp.close() - I create a "test-name.txt" file - @@ -146,6 +162,7 @@ ftp = te.get_ftp_folder(cr, uid, self, 'Documents') fdata = StringIO('abcd') ftp.storbinary('STOR test-name.txt', fdata) + ftp.close() - I rename the "test-name.txt" file through ftp. - @@ -153,6 +170,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents') ftp.rename("test-name.txt", "test-renamed.txt") + ftp.close() - I check that test-name.txt has been renamed. - @@ -166,6 +184,7 @@ except error_perm, e: pass assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt'] + ftp.close() - I create a new folder 'Test-Folder2' through FTP - @@ -173,6 +192,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents') ftp.mkd("Test-Folder2") + ftp.close() - I create a file 'test3.txt' at the 'Test-Folder2' - @@ -182,6 +202,7 @@ ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2') fdata = StringIO('abcd') ftp.storbinary('STOR test3.txt', fdata) + ftp.close() - I try to retrieve test3.txt - @@ -189,6 +210,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2') assert ftp.nlst("test3.txt") == ['test3.txt'], "File test3.txt is not there!" + ftp.close() - I create a new folder, 'Test-Folder3', through FTP I try to move test3.txt to 'Test-Folder3' @@ -197,6 +219,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents') ftp.mkd("Test-Folder3") + ftp.close() # TODO move - I remove the 'Test-Folder3' @@ -205,6 +228,7 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents') ftp.rmd("Test-Folder3") + ftp.close() - I check that test3.txt is removed. - @@ -219,6 +243,7 @@ for i in range(0, 200): fdata.seek(0) ftp.storbinary('STOR test-name%s.txt' %i, fdata) + ftp.close() - I list the 200 files, check speed - @@ -245,6 +270,7 @@ ftp.delete('test3.txt') for i in range(0, 200): ftp.delete('test-name%s.txt' %i) + ftp.close() - I remove the 'Test-Folder2' - @@ -252,3 +278,4 @@ from document_ftp import test_easyftp as te ftp = te.get_ftp_folder(cr, uid, self, 'Documents') ftp.rmd("Test-Folder2") + ftp.close()