-
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 #38] Added missing tests for actions and resource_cleaner
- Loading branch information
gioscarda
committed
Nov 5, 2019
1 parent
71394e0
commit 462205d
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
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,53 @@ | ||
# (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 | ||
import os | ||
from wpsremote.action import CopyFile, CopyINIFileAddParam | ||
import wpsremote.configInstance as configInstance | ||
|
||
__author__ = "Alessio Fabiani" | ||
__copyright__ = "Copyright 2019 Open Source Geospatial Foundation - all rights reserved" | ||
__license__ = "GPL" | ||
|
||
|
||
class TestAction(unittest.TestCase): | ||
|
||
def test_copy_file(self): | ||
copy_path = "./src/wpsremote/xmpp_data/test/test_dir/copy_of_test_file" | ||
param_dict = { | ||
"source": "./src/wpsremote/xmpp_data/test/test_dir/test_file", | ||
"target": copy_path | ||
} | ||
cf = CopyFile(param_dict) | ||
self.assertFalse(os.path.isfile(copy_path)) | ||
cf.execute("blah") | ||
self.assertTrue(os.path.isfile(copy_path)) | ||
os.remove(copy_path) | ||
|
||
def test_copy_INI_file_add_param(self): | ||
copy_path = "./src/wpsremote/xmpp_data/test/copy_of_test_service.config" | ||
param_dict = { | ||
"source": "./src/wpsremote/xmpp_data/test/test_service.config", | ||
"target": copy_path, | ||
"param_section": "Input3", | ||
"param_name": "another_param", | ||
"param_value_ref": "input3_another_param" | ||
} | ||
cifap = CopyINIFileAddParam(param_dict) | ||
input_values = { | ||
"input3_another_param": "Another value" | ||
} | ||
self.assertFalse(os.path.isfile(copy_path)) | ||
cifap.execute(input_values) | ||
self.assertTrue(os.path.isfile(copy_path)) | ||
config = configInstance.create(copy_path) | ||
self.assertEqual("Another value", config.get("Input3", "another_param")) | ||
os.remove(copy_path) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# (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 | ||
import random | ||
import os | ||
from wpsremote.path import path | ||
from wpsremote.resource_cleaner import Resource | ||
|
||
__author__ = "Alessio Fabiani" | ||
__copyright__ = "Copyright 2019 Open Source Geospatial Foundation - all rights reserved" | ||
__license__ = "GPL" | ||
|
||
|
||
class TestResourceCleaner(unittest.TestCase): | ||
|
||
def test_instance_methods(self): | ||
rc = Resource() | ||
self.assertIsNone(rc.start_time()) | ||
self.assertIsNone(rc.cmd_line()) | ||
self.assertIsNone(rc.unique_id()) | ||
self.assertIsNone(rc.set_unique_id(1)) | ||
self.assertIsNone(rc.sendbox_path()) | ||
self.assertIsNone(rc.processbot_pid()) | ||
self.assertIsNone(rc.set_processbot_pid(1)) | ||
self.assertIsNone(rc.spawned_process_pids()) | ||
self.assertIsNone(rc.spawned_process_cmd()) | ||
sendbox_root = path("./src/wpsremote/xmpp_data/test/test_dir") | ||
unique_id = str(random.randint(1, 1000)).zfill(5) | ||
sendbox_path = sendbox_root / str(unique_id) | ||
rc.set_from_servicebot(unique_id, sendbox_path) | ||
self.assertEqual(rc.sendbox_path(), sendbox_path) | ||
self.assertEqual(rc._unique_id, unique_id) | ||
rc.set_from_processbot(os.getpid(), [unique_id]) | ||
self.assertIn(unique_id, rc._spawned_process_pids) | ||
try: | ||
rc.read() | ||
except Exception as e: | ||
self.fail(e) | ||
|
||
|
||
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