Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/bioblend/_tests/TestCloudmanMock.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 """ | |
2 Tests the functionality of the BioBlend CloudMan API, without actually making | |
3 calls to a remote CloudMan instance/server. These don't actually ensure | |
4 that BioBlend is integrated with CloudMan correctly. They only ensure that | |
5 if you refactor the BioBlend CloudMan API code, that it will maintain its | |
6 current behaviour. | |
7 """ | |
8 try: | |
9 from unittest.mock import MagicMock | |
10 except ImportError: | |
11 # Python < 3.3 | |
12 from mock import MagicMock | |
13 | |
14 from bioblend import cloudman | |
15 from .test_util import unittest | |
16 | |
17 | |
18 class TestCloudmanMock(unittest.TestCase): | |
19 | |
20 def setUp(self): | |
21 url = "http://127.0.0.1:42284" | |
22 password = "password" | |
23 self.cm = cloudman.CloudManInstance(url, password) | |
24 | |
25 # def test_initialize(self): | |
26 # self.cm._make_get_request = MagicMock(return_value="{}") | |
27 # | |
28 # ## Set cluster type | |
29 # self.cm.initialize(type="Galaxy") | |
30 # | |
31 # params = {'startup_opt': 'Galaxy'} | |
32 # self.cm._make_get_request.assert_called_with("initialize_cluster", parameters=params) | |
33 | |
34 def test_get_status(self): | |
35 # Set return value of call | |
36 self.cm._make_get_request = MagicMock(return_value={}) | |
37 | |
38 status = self.cm.get_status() | |
39 self.assertNotEqual(status, None) | |
40 self.assertEqual(status, {}) | |
41 | |
42 # Check that the correct URL was called | |
43 self.cm._make_get_request.assert_called_with("instance_state_json") | |
44 | |
45 def test_get_nodes(self): | |
46 # Set return value of call | |
47 self.cm._make_get_request = MagicMock(return_value={'instances': []}) | |
48 | |
49 nodes = self.cm.get_nodes() | |
50 self.assertIsNotNone(nodes) | |
51 self.assertEqual(len(nodes), 0) | |
52 | |
53 # Check that the correct URL was called | |
54 self.cm._make_get_request.assert_called_with("instance_feed_json") | |
55 | |
56 def test_add_nodes(self): | |
57 self.cm._make_get_request = MagicMock(return_value="{}") | |
58 num_nodes = 10 | |
59 status = self.cm.add_nodes(num_nodes) | |
60 self.assertIsNotNone(status) | |
61 | |
62 # Check that the correct URL was called | |
63 params = {'number_nodes': 10, 'instance_type': '', 'spot_price': ''} | |
64 self.cm._make_get_request.assert_called_with("add_instances", parameters=params) | |
65 | |
66 def test_remove_nodes(self): | |
67 self.cm._make_get_request = MagicMock(return_value="{}") | |
68 num_nodes = 10 | |
69 status = self.cm.remove_nodes(num_nodes, force=True) | |
70 self.assertIsNotNone(status) | |
71 | |
72 # Check that the correct URL was called | |
73 params = {'number_nodes': 10, 'force_termination': True} | |
74 self.cm._make_get_request.assert_called_with("remove_instances", parameters=params) | |
75 | |
76 def test_remove_node(self): | |
77 self.cm._make_get_request = MagicMock(return_value="{}") | |
78 instance_id = "abcdef" | |
79 self.cm.remove_node(instance_id, force=True) | |
80 | |
81 # Check that the correct URL was called | |
82 params = {'instance_id': "abcdef"} | |
83 self.cm._make_get_request.assert_called_with("remove_instance", parameters=params) | |
84 | |
85 def test_reboot_node(self): | |
86 self.cm._make_get_request = MagicMock(return_value="{}") | |
87 instance_id = "abcdef" | |
88 self.cm.reboot_node(instance_id) | |
89 | |
90 # Check that the correct URL was called | |
91 params = {'instance_id': "abcdef"} | |
92 self.cm._make_get_request.assert_called_with("reboot_instance", parameters=params) | |
93 | |
94 def test_autoscaling_enabled_true(self): | |
95 return_json_string = {"autoscaling": {"use_autoscaling": True, "as_max": "3", "as_min": "1"}} | |
96 self.cm._make_get_request = MagicMock(return_value=return_json_string) | |
97 self.assertTrue(self.cm.autoscaling_enabled()) | |
98 | |
99 def test_autoscaling_enabled_false(self): | |
100 return_json_string = {"autoscaling": {"use_autoscaling": False, "as_max": "3", "as_min": "1"}} | |
101 self.cm._make_get_request = MagicMock(return_value=return_json_string) | |
102 self.assertFalse(self.cm.autoscaling_enabled()) | |
103 | |
104 def test_enable_autoscaling(self): | |
105 return_json_string = {"autoscaling": {"use_autoscaling": False, "as_max": "N/A", "as_min": "N/A"}} | |
106 self.cm._make_get_request = MagicMock(return_value=return_json_string) | |
107 self.assertFalse(self.cm.autoscaling_enabled()) | |
108 self.cm.enable_autoscaling(minimum_nodes=0, maximum_nodes=19) | |
109 | |
110 # Check that the correct URL was called | |
111 params = {'as_min': 0, 'as_max': 19} | |
112 self.cm._make_get_request.assert_called_with("toggle_autoscaling", parameters=params) | |
113 | |
114 return_json_string = {"autoscaling": {"use_autoscaling": True, "as_max": "19", "as_min": "0"}} | |
115 self.cm.enable_autoscaling(minimum_nodes=0, maximum_nodes=19) | |
116 | |
117 # Check that the correct URL was called | |
118 params = {'as_min': 0, 'as_max': 19} | |
119 self.cm._make_get_request.assert_called_with("toggle_autoscaling", parameters=params) | |
120 | |
121 def test_disable_autoscaling(self): | |
122 return_json_string = {"autoscaling": {"use_autoscaling": True, "as_max": "3", "as_min": "1"}} | |
123 self.cm._make_get_request = MagicMock(return_value=return_json_string) | |
124 self.cm.disable_autoscaling() | |
125 | |
126 self.cm._make_get_request.assert_called_with("toggle_autoscaling") | |
127 | |
128 def test_adjust_autoscaling(self): | |
129 return_json_string = {"autoscaling": {"use_autoscaling": True, "as_max": "3", "as_min": "1"}} | |
130 self.cm._make_get_request = MagicMock(return_value=return_json_string) | |
131 self.cm.adjust_autoscaling(minimum_nodes=3, maximum_nodes=4) | |
132 params = {'as_min_adj': 3, 'as_max_adj': 4} | |
133 self.cm._make_get_request.assert_called_with("adjust_autoscaling", parameters=params) | |
134 | |
135 def test_get_galaxy_state_stopped(self): | |
136 return_json = {"status": "'Galaxy' is not running", "srvc": "Galaxy"} | |
137 self.cm._make_get_request = MagicMock(return_value=return_json) | |
138 | |
139 self.assertEqual(self.cm.get_galaxy_state()['status'], "'Galaxy' is not running") | |
140 params = {'srvc': "Galaxy"} | |
141 self.cm._make_get_request.assert_called_with("get_srvc_status", parameters=params) |