def test_web_api_stats(self): # Test _handlestatrequest validator = self._create_validator() gossip = validator.gossip statistics_page = StatisticsPage(validator) request = self._create_get_request("/stat", {}) try: statistics_page.do_get(request) self.fail("This should cause an error") except: self.assertIsNotNone(statistics_page) dic = {} dic["journal"] = validator.stat_domains["journal"].get_stats() dic["journalconfig"] = validator.stat_domains["journalconfig"].\ get_stats() dic["message"] = validator.stat_domains["message"].get_stats() dic["packet"] = validator.stat_domains["packet"].get_stats() # GET /statistics/journal request = self._create_get_request("/statistics/journal", {}) self.assertEquals(yaml.load(statistics_page.do_get(request)), dic) # GET /statistics/node - with no peers request = self._create_get_request("/statistics/node", {}) self.assertEquals(yaml.load(statistics_page.do_get(request)), {}) node = self._create_node(8804) gossip.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(statistics_page.do_get(request)), dic2) request = self._create_get_request("AnythingElse", {}) dic3 = statistics_page.do_get(request) self.assertTrue('Invalid page name' in dic3)
def __init__(self, validator, static_dir=None): Resource.__init__(self) self.validator = validator if static_dir is not None and os.path.exists(static_dir): for f in os.listdir(static_dir): self.putChild(f, File(os.path.join(static_dir, f))) self.putChild('block', BlockPage(validator)) self.putChild('statistics', StatisticsPage(validator)) self.putChild('store', StorePage(validator)) self.putChild('status', StatusPage(validator)) self.putChild('transaction', TransactionPage(validator)) self.putChild('forward', ForwardPage(validator)) self.putChild('command', CommandPage(validator)) validator.web_thread_pool.start()
def test_web_api_stats(self): # Test _handlestatrequest local_node = self._create_node(8803) gossip = Gossip(local_node) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(gossip, data_directory=path, genesis_ledger=True) validator = TestValidator(ledger) statistics_page = StatisticsPage(validator) request = self._create_get_request("/stat", {}) try: statistics_page.do_get(request) self.fail("This should cause an error") except: self.assertIsNotNone(statistics_page) dic = {} dic["ledger"] = gossip.StatDomains["ledger"].get_stats() dic["ledgerconfig"] = gossip.StatDomains["ledgerconfig"].get_stats() dic["message"] = gossip.StatDomains["message"].get_stats() dic["packet"] = gossip.StatDomains["packet"].get_stats() # GET /statistics/ledger request = self._create_get_request("/statistics/ledger", {}) self.assertEquals(yaml.load(statistics_page.do_get(request)), dic) # GET /statistics/node - with no peers request = self._create_get_request("/statistics/node", {}) self.assertEquals(yaml.load(statistics_page.do_get(request)), {}) node = self._create_node(8804) gossip.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(statistics_page.do_get(request)), dic2) request = self._create_get_request("AnythingElse", {}) dic3 = statistics_page.do_get(request) self.assertTrue('Invalid page name' in dic3)
def test_web_api_stats(self): # Test _handlestatrequest local_node = self._create_node(8803) path = tempfile.mkdtemp() # Setup ledger and RootPage ledger = Journal(local_node, DataDirectory=path, GenesisLedger=True) validator = TestValidator(ledger) statistics_page = StatisticsPage(validator) request = self._create_get_request("/stat", {}) try: statistics_page.do_get(request) self.fail("This should cause an error") except: self.assertIsNotNone(statistics_page) 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(statistics_page.do_get(request)), dic) # GET /statistics/node - with no peers request = self._create_get_request("/statistics/node", {}) self.assertEquals(yaml.load(statistics_page.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(statistics_page.do_get(request)), dic2) request = self._create_get_request("AnythingElse", {}) dic3 = statistics_page.do_get(request) self.assertTrue('Invalid page name' in dic3)