From fca76d6bc6c2e519cf9b362d2ea32a21271c5257 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 10 Aug 2024 16:42:03 +0700 Subject: [PATCH] Create test_node_selection.py --- .../PiFusion/tests/test_node_selection.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 blockchain_integration/pi_network/PiFusion/tests/test_node_selection.py diff --git a/blockchain_integration/pi_network/PiFusion/tests/test_node_selection.py b/blockchain_integration/pi_network/PiFusion/tests/test_node_selection.py new file mode 100644 index 000000000..ae18a7f7d --- /dev/null +++ b/blockchain_integration/pi_network/PiFusion/tests/test_node_selection.py @@ -0,0 +1,33 @@ +import unittest +from pi_fusion_dashboard.node_selection import NodeSelection + +class TestNodeSelection(unittest.TestCase): + def setUp(self): + self.node_selection = NodeSelection() + + def test_get_nodes(self): + nodes = self.node_selection.get_nodes() + self.assertIsInstance(nodes, list) + self.assertGreater(len(nodes), 0) + + def test_get_node_by_id(self): + node_id = 1 + node = self.node_selection.get_node_by_id(node_id) + self.assertIsInstance(node, dict) + self.assertEqual(node['id'], node_id) + + def test_get_node_by_name(self): + node_name = 'Node 1' + node = self.node_selection.get_node_by_name(node_name) + self.assertIsInstance(node, dict) + self.assertEqual(node['name'], node_name) + + def test_filter_nodes_by_reputation(self): + reputation_threshold = 0.5 + filtered_nodes = self.node_selection.filter_nodes_by_reputation(reputation_threshold) + self.assertIsInstance(filtered_nodes, list) + for node in filtered_nodes: + self.assertGreaterEqual(node['reputation'], reputation_threshold) + +if __name__ == '__main__': + unittest.main()