-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fixes #28] Add BusIndependentMessage tests
- Loading branch information
gioscarda
committed
Oct 25, 2019
1 parent
49d1a77
commit d5fe88f
Showing
7 changed files
with
357 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ twine==1.15.0 | |
urllib3==1.25.6 | ||
webencodings==0.5.1 | ||
wrapt==1.10.10 | ||
mock==3.0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# (c) 2016 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. | ||
|
||
[DEFAULT] | ||
|
||
bus_class_name = xmppBus.XMPPBus | ||
|
||
port = 5223 | ||
address = 127.0.0.1 | ||
domain = geoserver.org | ||
|
||
# . Those are the connection parameters to the XMPP Server. | ||
# . The user must exists on the Server and its name must be | ||
# . equal to the service name. | ||
user = default.GdalContour | ||
password = R3m0T3wP5 | ||
|
||
mucService = conference.%(domain)s | ||
mucServicePassword = geoserver | ||
|
||
resource_file_dir = ./xmpp_data/resource_dir | ||
|
||
# . Configure this option (along with 'backup_on_wps_execution_shared_dir' | ||
# . on single outputs of 'service.config') in order to make a copy | ||
# . of the results into a shared folder before sending messages to XMPP | ||
# . WARNING: this option takes precedence on "UPLOADER" option | ||
# wps_execution_shared_dir = /share/xmpp_data/share | ||
|
||
# . This section is used to configure the uploader class and connection | ||
# . parameters. | ||
# . This is necessary in order to let the 'upload_data' option work on | ||
# . single outputs of 'service.config' | ||
[UPLOADER] | ||
# There are different implementations of the FTP Uploader available right now: | ||
# . Plain standard FTP Protocol (based on ftplib) | ||
# ftpUpload.FtpUpload | ||
# . FTP over TLS (FTPS) Protocol (based on ftplib) | ||
# ftpsUpload.FtpsUpload | ||
# . S-FTP Protocol (based on paramiko Python lib) | ||
# sftpUpload.SFtpUpload | ||
#uploader_class_name = ftpUpload.FtpUpload | ||
#uploader_host = ftp.<your_host_here>:<your_port_here_default_21> | ||
#uploader_username = <ftp_username> | ||
#uploader_password = <ftp_password_encrypted> | ||
|
||
# . "encryptor" you can use encrypted passwords with a private/public key couple | ||
# | ||
# . To generate a new private key use the following command: | ||
# openssl genrsa -out myTestKey.pem -passout pass:"f00bar" -des3 2048 | ||
# | ||
# . To generate a new public key use the following command: | ||
# openssl rsa -pubout -in myTestKey.pem -passin pass:"f00bar" -out myTestKey.pub | ||
# | ||
# . To encrypt your password use the following utility | ||
# python encrypt.py password path/to/rsakey.pub passphrase | ||
# | ||
# . To double check the password is correct use the following utility | ||
# python decrypt.py password path/to/rsakey.pem passphrase | ||
uploader_private_rsa_key = ./xmpp_data/ssl/myTestKey.pem | ||
uploader_passphrase = f00bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
# (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 os | ||
import unittest | ||
import mock | ||
import pickle | ||
import wpsremote.configInstance as configInstance | ||
from wpsremote.busIndipendentMessages import ( | ||
RegisterMessage, ProgressMessage, LogMessage, CompletedMessage, ErrorMessage, AbortMessage, | ||
LoadAverageMessage, InviteMessage, GetLoadAverageMessage, ExecuteMessage, FinishMessage | ||
) | ||
from wpsremote.xmppBus import XMPPBus | ||
from wpsremote.xmppMessages import ( | ||
XMPPRegisterMessage, XMPPProgressMessage, XMPPLogMessage, | ||
XMPPCompletedMessage, XMPPErrorMessage, XMPPLoadAverageMessage | ||
) | ||
|
||
__author__ = "Alessio Fabiani" | ||
__copyright__ = "Copyright 2019 Open Source Geospatial Foundation - all rights reserved" | ||
__license__ = "GPL" | ||
|
||
# due to xmppMessages chdir | ||
os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
||
|
||
class TestBusIndependentMessages(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.remote_config = configInstance.create( | ||
"./src/wpsremote/xmpp_data/test/test_remote.config" | ||
) | ||
self.xmpp_bus = XMPPBus(self.remote_config, "service_name", "service_name_namespace") | ||
self.xep_0045_plugin = self.xmpp_bus.xmpp.plugin["xep_0045"] | ||
self.from_obj_mock = mock.Mock() | ||
|
||
def test_invite_message(self): | ||
rooms = { | ||
self.xmpp_bus._get_MUC_JId(): { | ||
"resource": { | ||
"role": "not_visitor" | ||
} | ||
} | ||
} | ||
self.xep_0045_plugin.rooms = rooms | ||
self.from_obj_mock.resource = "resource" | ||
msg = { | ||
"type": "normal", | ||
"body": "topic=invite", | ||
"from": self.from_obj_mock | ||
} | ||
# InviteMessage | ||
message = self.xmpp_bus.CreateIndipendentMessage(msg) | ||
self.assertIsInstance(message, InviteMessage) | ||
self.assertEqual(message.originator(), self.from_obj_mock) | ||
|
||
def test_convert_register_message(self): | ||
input_DLR = [ | ||
( | ||
'Input1', | ||
'{' | ||
'"class": param, ' | ||
'"name": "interval", ' | ||
'"title": Elevation Interval, ' | ||
'"type": application/json, ' | ||
'"description": Elevation interval between contours, ' | ||
'"min": 1, ' | ||
'"max": 1, ' | ||
'"default": 200' | ||
'}' | ||
) | ||
] | ||
output_DLR = [ | ||
( | ||
'result1', | ||
'{' | ||
'"publish_layer_name": null, ' | ||
'"description": "WPS Resource Plain Text", ' | ||
'"title": null, ' | ||
'"output_mime_type": null, ' | ||
'"publish_default_style": null, ' | ||
'"publish_as_layer": null, ' | ||
'"type": "string", ' | ||
'"publish_target_workspace": null' | ||
'}' | ||
) | ||
] | ||
# RegisterMessage | ||
r_msg = RegisterMessage( | ||
originator=self.from_obj_mock, | ||
service="test_service", | ||
namespace="test_namespace", | ||
descritpion="test_description", | ||
par=input_DLR, | ||
output=output_DLR | ||
) | ||
c_msg = self.xmpp_bus.Convert(r_msg) | ||
self.assertIsInstance(c_msg, XMPPRegisterMessage) | ||
self.assertEqual(c_msg.title(), "test_namespace.test_service") | ||
|
||
def test_execute_message(self): | ||
rooms = { | ||
self.xmpp_bus._get_MUC_JId(): { | ||
"resource": { | ||
"role": "not_visitor" | ||
} | ||
} | ||
} | ||
self.xep_0045_plugin.rooms = rooms | ||
from_obj_mock = mock.Mock() | ||
from_obj_mock.resource = "resource" | ||
test_msg = pickle.dumps("test_message") | ||
msg = { | ||
"type": "normal", | ||
"body": "topic=request&id=123&baseURL=test_base_url&message={}".format(test_msg), | ||
"from": from_obj_mock | ||
} | ||
# ExecuteMessage | ||
message = self.xmpp_bus.CreateIndipendentMessage(msg) | ||
self.assertIsInstance(message, ExecuteMessage) | ||
|
||
def test_progress_message(self): | ||
# ProgressMessage | ||
r_msg = ProgressMessage(self.from_obj_mock, 1.34) | ||
c_msg = self.xmpp_bus.Convert(r_msg) | ||
self.assertIsInstance(c_msg, XMPPProgressMessage) | ||
self.assertEqual(c_msg.originator, self.from_obj_mock) | ||
self.assertEqual(c_msg.progress, 1.34) | ||
self.assertEqual(c_msg.xmppChannel, self.xmpp_bus) | ||
|
||
def test_covert_log_message(self): | ||
# LogMessage | ||
r_msg = LogMessage(self.from_obj_mock, "INFO", "test_message_text") | ||
c_msg = self.xmpp_bus.Convert(r_msg) | ||
self.assertIsInstance(c_msg, XMPPLogMessage) | ||
self.assertEqual(c_msg.originator, self.from_obj_mock) | ||
self.assertEqual(c_msg.level, "INFO") | ||
self.assertEqual(c_msg.msg, "test_message_text") | ||
|
||
def test_convert_completed_message(self): | ||
outputs = { | ||
'result1': { | ||
"publish_layer_name": None, | ||
"description": "WPS Resource Plain Text", | ||
"title": None, | ||
"output_mime_type": None, | ||
"publish_default_style": None, | ||
"publish_as_layer": None, | ||
"type": "string", | ||
"publish_target_workspace": None | ||
} | ||
} | ||
# CompletedMessage | ||
r_msg = CompletedMessage(self.from_obj_mock, "test_base_url", outputs) | ||
c_msg = self.xmpp_bus.Convert(r_msg) | ||
self.assertIsInstance(c_msg, XMPPCompletedMessage) | ||
self.assertEqual(c_msg.originator, self.from_obj_mock) | ||
self.assertEqual(c_msg._base_url, "test_base_url") | ||
self.assertEqual(c_msg._outputs, outputs) | ||
|
||
def test_finish_message(self): | ||
rooms = { | ||
self.xmpp_bus._get_MUC_JId(): { | ||
"resource": { | ||
"role": "not_visitor" | ||
} | ||
} | ||
} | ||
self.xep_0045_plugin.rooms = rooms | ||
self.from_obj_mock.resource = "resource" | ||
msg = { | ||
"type": "normal", | ||
"body": "topic=finish", | ||
"from": self.from_obj_mock | ||
} | ||
# FinishMessage | ||
message = self.xmpp_bus.CreateIndipendentMessage(msg) | ||
self.assertIsInstance(message, FinishMessage) | ||
|
||
def test_convert_error_message(self): | ||
# ErrorMessage | ||
r_msg = ErrorMessage(self.from_obj_mock, "test_error_message_text") | ||
c_msg = self.xmpp_bus.Convert(r_msg) | ||
self.assertIsInstance(c_msg, XMPPErrorMessage) | ||
self.assertEqual(c_msg.originator, self.from_obj_mock) | ||
self.assertEqual(c_msg.xmppChannel, self.xmpp_bus) | ||
self.assertEqual(c_msg.id, self.xmpp_bus.id) | ||
self.assertEqual(c_msg.msg, "test_error_message_text") | ||
|
||
def test_abort_message(self): | ||
rooms = { | ||
self.xmpp_bus._get_MUC_JId(): { | ||
"resource": { | ||
"role": "not_visitor" | ||
} | ||
} | ||
} | ||
self.xep_0045_plugin.rooms = rooms | ||
self.from_obj_mock.resource = "resource" | ||
msg = { | ||
"type": "normal", | ||
"body": "topic=abort", | ||
"from": self.from_obj_mock | ||
} | ||
# AbortMessage | ||
message = self.xmpp_bus.CreateIndipendentMessage(msg) | ||
self.assertIsInstance(message, AbortMessage) | ||
|
||
def test_get_load_average_message(self): | ||
rooms = { | ||
self.xmpp_bus._get_MUC_JId(): { | ||
"resource": { | ||
"role": "not_visitor" | ||
} | ||
} | ||
} | ||
self.xep_0045_plugin.rooms = rooms | ||
self.from_obj_mock.resource = "resource" | ||
msg = { | ||
"type": "normal", | ||
"body": "topic=getloadavg", | ||
"from": self.from_obj_mock | ||
} | ||
# GetLoadAverageMessage | ||
message = self.xmpp_bus.CreateIndipendentMessage(msg) | ||
self.assertIsInstance(message, GetLoadAverageMessage) | ||
self.assertEqual(message.originator(), self.from_obj_mock) | ||
|
||
def test_covert_load_average_message(self): | ||
outputs = { | ||
'result1': { | ||
"publish_layer_name": None, | ||
"description": "WPS Resource Plain Text", | ||
"title": None, | ||
"output_mime_type": None, | ||
"publish_default_style": None, | ||
"publish_as_layer": None, | ||
"type": "string", | ||
"publish_target_workspace": None | ||
} | ||
} | ||
# LoadAverageMessage | ||
r_msg = LoadAverageMessage(self.from_obj_mock, outputs) | ||
c_msg = self.xmpp_bus.Convert(r_msg) | ||
self.assertIsInstance(c_msg, XMPPLoadAverageMessage) | ||
self.assertEqual(c_msg.originator, self.from_obj_mock) | ||
self.assertEqual(c_msg._outputs, outputs) | ||
|
||
def test_clone_for_process(self): | ||
clone = self.xmpp_bus.clone_for_process("not_master") | ||
self.assertEqual(clone.config, self.xmpp_bus.config) | ||
self.assertEqual(clone.address, self.xmpp_bus.address) | ||
self.assertEqual(clone.domain, self.xmpp_bus.domain) | ||
self.assertEqual(clone.MUC_name, self.xmpp_bus.MUC_name) | ||
self.assertEqual(clone.username, self.xmpp_bus.username) | ||
self.assertEqual(clone.password, self.xmpp_bus.password) | ||
self.assertEqual(clone.nameSpacePassword, self.xmpp_bus.nameSpacePassword) | ||
self.assertEqual(clone._service_name, self.xmpp_bus._service_name) | ||
self.assertEqual(clone._service_name_namespace, self.xmpp_bus._service_name_namespace) | ||
self.assertEqual( | ||
clone._fully_qualified_service_name, | ||
self.xmpp_bus._fully_qualified_service_name | ||
) | ||
|
||
def test_get_MUC_JId(self): | ||
self.assertEqual( | ||
"[email protected]", | ||
self.xmpp_bus._get_MUC_JId() | ||
) | ||
|
||
def test_get_fully_qualified_service_name(self): | ||
self.assertEqual( | ||
"service_name_namespace.service_name", | ||
self.xmpp_bus.get_fully_qualified_service_name() | ||
) | ||
|
||
def test_state(self): | ||
self.assertEqual("disconnected", self.xmpp_bus.state()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters