|
| 1 | +import unittest |
| 2 | +from unittest.mock import Mock |
| 3 | + |
| 4 | +from easy_manage.tools import RedfishTools |
| 5 | + |
| 6 | + |
| 7 | +class TestRedfishTools(unittest.TestCase): |
| 8 | + @classmethod |
| 9 | + def setUpClass(cls): |
| 10 | + cls.data = { |
| 11 | + 'System': { |
| 12 | + 'SerialNumber': 'S4ATJ171', |
| 13 | + }, |
| 14 | + 'Very': { |
| 15 | + 'NestedWrong': { |
| 16 | + 'specialKey': 'looseVal' |
| 17 | + }, |
| 18 | + 'Nested': { |
| 19 | + 'specialKey': 'strictVal' |
| 20 | + }, |
| 21 | + }, |
| 22 | + 'CPUs': [ |
| 23 | + { |
| 24 | + 'Name': 'CPU1', |
| 25 | + 'Temp': '100', |
| 26 | + }, |
| 27 | + { |
| 28 | + 'Name': 'CPU2', |
| 29 | + 'Temp': '30', |
| 30 | + }, |
| 31 | + ], |
| 32 | + } |
| 33 | + cls.rf_tools = RedfishTools() |
| 34 | + |
| 35 | + def test_find(self): |
| 36 | + found_val = self.rf_tools.find( |
| 37 | + ['SerialNumber'], |
| 38 | + data=self.data) |
| 39 | + self.assertEqual('S4ATJ171', found_val) |
| 40 | + |
| 41 | + def test_find_not_strict(self): |
| 42 | + found_val = self.rf_tools.find( |
| 43 | + ['Very', 'Nested', 'specialKey'], |
| 44 | + strict=False, |
| 45 | + data=self.data) |
| 46 | + self.assertEqual('looseVal', found_val) |
| 47 | + |
| 48 | + def test_find_strict(self): |
| 49 | + found_val = self.rf_tools.find( |
| 50 | + ['Very', 'Nested', 'specialKey'], |
| 51 | + strict=True, |
| 52 | + data=self.data) |
| 53 | + self.assertEqual('strictVal', found_val) |
| 54 | + |
| 55 | + def test_get_dict_containing(self): |
| 56 | + found_dict = self.rf_tools._get_dict_containing( |
| 57 | + 'CPU1', |
| 58 | + self.data) |
| 59 | + self.assertEqual(self.data['CPUs'][0], found_dict) |
| 60 | + |
| 61 | + def test_snake_case_dict(self): |
| 62 | + snake_cased = self.rf_tools.snake_case_dict(self.data) |
| 63 | + self.assertTrue('serial_number' in snake_cased['system'].keys()) |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == '__main__': |
| 67 | + unittest.main() |
0 commit comments