summaryrefslogtreecommitdiff
path: root/addons/document_ftp/test_easyftp.py
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2010-07-02 01:42:49 +0300
committerP. Christeas <p_christ@hol.gr>2010-07-02 01:42:49 +0300
commit35c932d76a63bed6210943efdbd1b7b162ca828d (patch)
treefab5a08cb13060475418b5b3aec50c597e549f69 /addons/document_ftp/test_easyftp.py
parentfb3f520268ce6437cdee1529b5bd974426af1e42 (diff)
Document FTP: write Yaml tests, have special helper module.
bzr revid: p_christ@hol.gr-20100701224249-fmble80t8nlg2azq
Diffstat (limited to 'addons/document_ftp/test_easyftp.py')
-rw-r--r--addons/document_ftp/test_easyftp.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/addons/document_ftp/test_easyftp.py b/addons/document_ftp/test_easyftp.py
new file mode 100644
index 00000000000..eb709c79e31
--- /dev/null
+++ b/addons/document_ftp/test_easyftp.py
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+""" This is a testing module, which exports some functions for the YAML tests.
+ Instead of repeating the same FTP code all over, we prefer to have
+ it in this file
+"""
+
+from ftplib import FTP
+from tools.misc import detect_ip_addr
+from tools import config
+
+def get_plain_ftp():
+ ftp = FTP()
+ host = config.get('ftp_server_host', '127.0.0.1')
+ port = config.get('ftp_server_port','8021')
+ ftp.connect(host,port)
+ return ftp
+
+def get_ftp_login(cr, uid, ormobj):
+ ftp = get_plain_ftp()
+ user = ormobj.pool.get('res.users').read(cr, uid, uid)
+ ftp.login(user.get('login',''),user.get('password',''))
+ ftp.cwd("/" + cr.dbname)
+ return ftp
+
+def get_ftp_anonymous(cr):
+ ftp = get_plain_ftp()
+ ftp.login('anonymous', 'the-test')
+ ftp.cwd("/")
+ return ftp
+
+def get_ftp_folder(cr, uid, ormobj, foldername):
+ ftp = get_ftp_login(cr, uid, ormobj)
+ ftp.cwd("/" + cr.dbname+"/"+foldername)
+ return ftp
+
+def get_ftp_fulldata(ftp, fname, limit=8192):
+ from functools import partial
+ data = []
+ def ffp(data, ndata):
+ if len(data)+ len(ndata) > limit:
+ raise IndexError('Data over the limit')
+ data.append(ndata)
+ ftp.retrbinary('RETR %s' % fname, partial(ffp,data))
+ return ''.join(data)
+
+#eof \ No newline at end of file