|
1 | 1 | from unittest import TestCase |
2 | | -from common.utilites.command_result import get_result_from_command_output |
| 2 | +from common.utilites.command_result import get_result_from_command_output, set_command_result |
| 3 | +from models.ConnectionResult import ConnectionResult |
3 | 4 |
|
4 | 5 |
|
5 | 6 | class TestCommandResult(TestCase): |
6 | 7 |
|
7 | | - def test_command_result_with_result(self): |
8 | | - result = get_result_from_command_output('command_json_result=MY RESULT=command_json_result_end') |
9 | | - self.assertEqual(result, 'MY RESULT') |
| 8 | + def test_get_result_from_command_output_with_result(self): |
| 9 | + result = get_result_from_command_output('command_json_result={"result":"MY RESULT"}=command_json_result_end') |
| 10 | + self.assertEqual(result["result"], 'MY RESULT') |
10 | 11 |
|
11 | 12 | def test_command_result_empty(self): |
12 | 13 | result = get_result_from_command_output('') |
13 | 14 | self.assertEqual(result, None) |
| 15 | + |
| 16 | + def test_get_result_from_command_output_with_result_unpickable_true(self): |
| 17 | + |
| 18 | + connection_result = ConnectionResult(mac_address='AA', vm_uuid='BB', network_name='CC') |
| 19 | + output_result = set_command_result(result=connection_result, unpicklable=True) |
| 20 | + result = get_result_from_command_output(output_result) |
| 21 | + |
| 22 | + self.assertEqual(result.mac_address, 'AA') |
| 23 | + self.assertEqual(result.vm_uuid, 'BB') |
| 24 | + self.assertEqual(result.network_name, 'CC') |
| 25 | + |
| 26 | + def test_get_result_from_command_output_with_result_unpickable_false(self): |
| 27 | + |
| 28 | + connection_result = ConnectionResult(mac_address='AA', vm_uuid='BB', network_name='CC') |
| 29 | + output_result = set_command_result(result=[connection_result], unpicklable=False) |
| 30 | + results = get_result_from_command_output(output_result) |
| 31 | + |
| 32 | + self.assertEqual(results[0]['mac_address'], 'AA') |
| 33 | + self.assertEqual(results[0]['vm_uuid'], 'BB') |
| 34 | + self.assertEqual(results[0]['network_name'], 'CC') |
| 35 | + |
| 36 | + def test_get_result_from_command_output_with_result(self): |
| 37 | + |
| 38 | + output_result = 'command_json_result=[{"py/object": "models.ConnectionResult.ConnectionResult", "vm_uuid": "422258ab-47e9-d57c-3741-6832a432bc3a", "network_name": "QualiSB/anetwork", "mac_address": "00:50:56:a2:23:76"}]=command_json_result_end' |
| 39 | + results = get_result_from_command_output(output_result) |
| 40 | + |
| 41 | + self.assertEqual(results[0].mac_address, '00:50:56:a2:23:76') |
| 42 | + |
| 43 | + def test_get_result_from_command_output_with_result_unpickable_false(self): |
| 44 | + |
| 45 | + output_result = 'command_json_result=[{"vm_uuid": "422258c6-15d0-0646-d5e7-f2cb411eee94", "network_name": "QualiSB/anetwork", "mac_address": "00:50:56:a2:6c:04"}]=command_json_result_end' |
| 46 | + results = get_result_from_command_output(output_result) |
| 47 | + |
| 48 | + for result in results: |
| 49 | + v = dict(result) |
| 50 | + self.assertEqual(result['mac_address'], '00:50:56:a2:6c:04') |
0 commit comments