def test_web_api_stats(self): # Test _handlestatrequest LocalNode = self._create_node(8803) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(LocalNode, DataDirectory=path, GenesisLedger=True) validator = TestValidator(ledger) root = RootPage(validator) request = self._create_get_request("/stat", {}) try: root.do_get(request) self.fail("This should cause an error") except: self.assertIsNotNone(root) dic = {} dic["ledger"] = ledger.StatDomains["ledger"].get_stats() dic["ledgerconfig"] = ledger.StatDomains["ledgerconfig"].get_stats() dic["message"] = ledger.StatDomains["message"].get_stats() dic["packet"] = ledger.StatDomains["packet"].get_stats() # GET /statistics/ledger request = self._create_get_request("/statistics/ledger", {}) self.assertEquals(yaml.load(root.do_get(request)), dic) # GET /statistics/node - with no peers request = self._create_get_request("/statistics/node", {}) self.assertEquals(yaml.load(root.do_get(request)), {}) node = self._create_node(8804) ledger.add_node(node) dic2 = {} dic2[node.Name] = node.Stats.get_stats() dic2[node.Name]["IsPeer"] = node.is_peer # GET /stats/node - with one peer self.assertEquals(yaml.load(root.do_get(request)), dic2) request = self._create_get_request("AnythingElse", {}) dic3 = root.do_get(request) self.assertTrue('404 - No Such Resource' in dic3)
def test_web_api_forward(self): # Test _msgforward LocalNode = self._create_node(8807) path = tempfile.mkdtemp() ledger = Journal(LocalNode, DataDirectory=path, GenesisLedger=True) # Create peers for the message to be forwarded to node1 = self._create_node(8881) node2 = self._create_node(8882) node1.is_peer = True node2.is_peer = True ledger.add_node(node1) ledger.add_node(node2) validator = TestValidator(ledger) root = RootPage(validator) # Create message to use and the data to forward msg = shutdown_message.ShutdownMessage() msg.sign_from_node(LocalNode) data = msg.dump() # Post /forward request = self._create_post_request("forward", data) r = yaml.load(root.do_post(request)) self.assertEquals(r, data) self.assertIn(msg.Identifier, node1.MessageQ.Messages) self.assertIn(msg.Identifier, node2.MessageQ.Messages)