mirror of
https://github.com/nicolargo/glances.git
synced 2025-01-06 01:35:47 +03:00
Unittest OK
This commit is contained in:
parent
60d6be1718
commit
c61d10bec7
@ -156,35 +156,13 @@ class GlancesInstance:
|
||||
return json.dumps(self.stats.getAllViewsAsDict())
|
||||
|
||||
def getPlugin(self, plugin):
|
||||
# Update and return the system stats
|
||||
# Update and return the plugin stat
|
||||
self.__update__()
|
||||
return json.dumps(self.stats.get_plugin(plugin).get_raw())
|
||||
|
||||
# ['alert', 'ports', 'diskio', 'containers', 'processcount', 'gpu',
|
||||
# 'percpu', 'system', 'network', 'cpu', 'amps', 'processlist',
|
||||
# 'load', 'sensors', 'uptime', 'now', 'fs', 'wifi', 'ip', 'help',
|
||||
# 'version', 'psutilversion', 'core', 'mem', 'folders', 'quicklook', 'memswap', 'raid']
|
||||
|
||||
# It works...
|
||||
# def getSystem(self):
|
||||
# return self._get_plugin('system')
|
||||
|
||||
# Do not work...
|
||||
# def __getattr__(self, item):
|
||||
# """Overwrite the getattr method in case of attribute is not found.
|
||||
# The goal is to dynamically generate the API get'Stats'() methods.
|
||||
# """
|
||||
# header = 'get'
|
||||
# # Check if the attribute starts with 'get'
|
||||
# if item.startswith(header):
|
||||
# try:
|
||||
# return self._get_plugin(item[len(header):])
|
||||
# except Exception:
|
||||
# # The method is not found for the plugin
|
||||
# raise AttributeError(item)
|
||||
# else:
|
||||
# # Default behavior
|
||||
# raise AttributeError(item)
|
||||
def getPluginView(self, plugin):
|
||||
# Update and return the plugin view
|
||||
return json.dumps(self.stats.get_plugin(plugin).get_views())
|
||||
|
||||
|
||||
class GlancesServer:
|
||||
|
@ -358,11 +358,17 @@ class GlancesStats:
|
||||
return self._plugins
|
||||
|
||||
def get_plugin(self, plugin_name):
|
||||
"""Return the plugin name."""
|
||||
"""Return the plugin stats."""
|
||||
if plugin_name in self._plugins:
|
||||
return self._plugins[plugin_name]
|
||||
return None
|
||||
|
||||
def get_plugin_view(self, plugin_name):
|
||||
"""Return the plugin views."""
|
||||
if plugin_name in self._plugins:
|
||||
return self._plugins[plugin_name].get_views()
|
||||
return None
|
||||
|
||||
def end(self):
|
||||
"""End of the Glances stats."""
|
||||
# Close export modules
|
||||
|
@ -185,7 +185,7 @@ class TestGlances(unittest.TestCase):
|
||||
"""IRQS"""
|
||||
method = "getIrqs()"
|
||||
print(f'INFO: [TEST_012] Method: {method}')
|
||||
req = json.loads(client.getIrq())
|
||||
req = json.loads(client.getPlugin('irq'))
|
||||
self.assertIsInstance(req, list)
|
||||
|
||||
def test_013_plugin_views(self):
|
||||
@ -193,7 +193,7 @@ class TestGlances(unittest.TestCase):
|
||||
method = "getViewsCpu()"
|
||||
print(f'INFO: [TEST_013] Method: {method}')
|
||||
|
||||
req = json.loads(client.getViewsCpu())
|
||||
req = json.loads(client.getPluginView('cpu'))
|
||||
self.assertIsInstance(req, dict)
|
||||
|
||||
def test_999_stop_server(self):
|
||||
|
Loading…
Reference in New Issue
Block a user