Skip to content

Commit

Permalink
[Fixes #36] tests for FTP uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
gioscarda committed Nov 5, 2019
1 parent 4f2ce39 commit c96f19f
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/continoustest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ python test_config_parser.py
python test_bus_independent_messages.py
python test_bot.py
python test_path.py
python test_ftp_uploads.py
python resource_cleaner.py

IF "%1"=="" GOTO exit
Expand Down
89 changes: 89 additions & 0 deletions test/test_ftp_uploads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# (c) 2019 Open Source Geospatial Foundation - all rights reserved
# (c) 2014 - 2015 Centre for Maritime Research and Experimentation (CMRE)
# (c) 2013 - 2014 German Aerospace Center (DLR)
# This code is licensed under the GPL 2.0 license, available at the root
# application directory.

import unittest
from wpsremote.path import path
from wpsremote.ftpUpload import EzFtp, FtpUpload
from wpsremote.sftpUpload import EzFtp as EzSFtp
from wpsremote.ftpsUpload import FtpsUpload
from mock import patch
from ftplib import FTP

__author__ = "Alessio Fabiani"
__copyright__ = "Copyright 2019 Open Source Geospatial Foundation - all rights reserved"
__license__ = "GPL"


class TestFtpUploads(unittest.TestCase):

@patch('ftplib.FTP', autospec=True)
def test_EzFtp(self, mock_ftp):
mockFTP = mock_ftp.return_value
ezFtp = EzFtp(mockFTP)
self.assertEqual(ezFtp.cd("test_dir"), 1)
try:
ezFtp.setRoot("root_dir")
ezFtp.putasc(
"./src/wpsremote/xmpp_data/test/test_file",
"/tmp/test_asc"
)
ezFtp.putbin(
"./src/wpsremote/xmpp_data/test/test_file",
"/tmp/test_bin"
)
ezFtp.delete("/tmp/test_bin")
ezFtp.quit()
except Exception as e:
self.fail(e)

@patch('ftplib.FTP', autospec=True)
def test_FtpUpload(self, mock_ftp):
mockFTP = mock_ftp.return_value
try:
ftpUpload = FtpUpload("host", "username", "password")
ftpUpload.ftp = mockFTP
ftpUpload.setHost("host:port", "username", "password")
ftpUpload.setMd5File("./src/wpsremote/xmpp_data/test/test_upload")
ftpUpload.Upload()
ftpUpload.deleteOldFiles()
ftpUpload.finish()
path("./src/wpsremote/xmpp_data/test/test_upload").remove()
except Exception as e:
self.fail(e)

@patch('ftplib.FTP', autospec=FTP())
def test_EzSFtp(self, mock_ftp):
mockFTP = mock_ftp.return_value
ezSFtp = EzSFtp(mockFTP)
self.assertEqual(ezSFtp.cd("test_dir"), 1)
try:
ezSFtp.setRoot("root_dir")
ezSFtp.putasc(
"./src/wpsremote/xmpp_data/test/test_file",
"/tmp/test_asc"
)
ezSFtp.putbin(
"./src/wpsremote/xmpp_data/test/test_file",
"/tmp/test_bin"
)
ezSFtp.delete("/tmp/test_bin")
ezSFtp.quit()
except Exception as e:
self.fail(e)

@patch('ftplib.FTP', autospec=True)
def test_FtpsUpload(self, mock_ftp):
mockFTP = mock_ftp.return_value
try:
ftpsUpload = FtpsUpload("host", "username", "password")
ftpsUpload.ftp = mockFTP
ftpsUpload.setHost("host:port", "username", "password")
except Exception as e:
self.fail(e)


if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions test_suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ coverage run --source=src test/test_bot.py

echo "Running... test_path"
coverage run --source=src test/test_path.py

echo "Running... test_ftp_uploads"
coverage run --source=src test/test_ftp_uploads.py

0 comments on commit c96f19f

Please sign in to comment.