Doc ftp: improve yaml tests, assert messages
[odoo/odoo.git] / addons / document_ftp / test / document_ftp_test2.yml
index 8b7d538..5a4df87 100644 (file)
@@ -5,7 +5,7 @@
 -
     !python {model: ir.attachment}: |
         from document_ftp import test_easyftp as te
-        ftp = te.get_plain_ftp()
+        ftp = te.get_plain_ftp(timeout=2.0)
         assert ftp.sock and (ftp.lastresp == '220'), ftp.lastresp
 -
     I read the list of databases at port 8021 and confirm our db is
 -
     !delete { model: ir.attachment, id:,  search: "[('name','=','test2.txt')]" }
 -
+    I also commit, because ftp would run in a different transaction.
+-
+    !python {model: ir.attachment}: |
+        cr.commit()
+-
     I check through FTP that test2.txt does not appear.
 -
     !python {model: ir.attachment}: |
         from document_ftp import test_easyftp as te
+        import ftplib
         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
-        assert ftp.nlst("test2.txt") == []
+        try:
+            nlst_result = ftp.nlst("test2.txt")
+        except ftplib.error_perm: # 550 error: 'path not exists'
+            nlst_result = []
+        assert "test2.txt" not in nlst_result, "Files: %r" % nlst_result
 -
     I create a "test-name.txt" file
 -
         ftp = te.get_ftp_folder(cr, uid, self, 'Documents')
         try:
             res = ftp.nlst("test-name.txt")
-            assert res == []
+            assert res == [], "File has not been renamed!"
         except error_perm, e:
             pass
         assert ftp.nlst("test-renamed.txt") == ['test-renamed.txt']
     !python {model: ir.attachment}: |
         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']
+        assert ftp.nlst("test3.txt") == ['test3.txt'], "File test3.txt is not there!"
 -
     I create a new folder, 'Test-Folder3', through FTP
     I try to move test3.txt to 'Test-Folder3'
 -
     I check that test3.txt is removed.
 -
-    I create 1000 files through FTP
+    I create 200 files through FTP
 -
     !python {model: ir.attachment}: |
         from document_ftp import test_easyftp as te
         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
         fdata = StringIO('abcd')
         # TODO speed
-        for i in range(0, 1000):
+        for i in range(0, 200):
             fdata.seek(0)
             ftp.storbinary('STOR test-name%s.txt' %i, fdata)
 -
-    I list the 1000 files, check speed
+    I list the 200 files, check speed
 -
     !python {model: ir.attachment}: |
         from document_ftp import test_easyftp as te
         ftp = te.get_ftp_folder(cr, uid, self, 'Documents/Test-Folder2')
         # TODO speed
-        assert len(ftp.nlst()) > 1000
+        assert len(ftp.nlst()) >= 200, "We haven't managed to store 200 files!"
 -
-    I read the 1000 files, check speed
+    I read the 200 files, check speed
     # TODO
 -
-    I move the 1000 files to 'Test-Folder2'
+    I move the 200 files to 'Test-Folder2'
     # TODO
--
\ No newline at end of file