Skip to content

Commit

Permalink
Fix name for cached_json_rest_api_get
Browse files Browse the repository at this point in the history
  • Loading branch information
tonynguyen-ccl committed Aug 26, 2024
1 parent 0f4f178 commit 94d4148
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,17 @@ def alive(self):
"""Returns true if endpoint is alive, false if not."""
# Run cached query because we can also fetch client version from this
# later on. This will save us an RPC call per run.
return self.interface.cached_rest_api_get() is not None
return self.interface.cached_json_rest_api_get() is not None

def block_height(self):
"""Runs a cached query to return block height"""
blockchain_info = self.interface.cached_rest_api_get()
blockchain_info = self.interface.cached_json_rest_api_get()
return validate_dict_and_return_key_value(
blockchain_info, 'block_height', self._logger_metadata, to_number=True)

def client_version(self):
"""Runs a cached query to return client version."""
blockchain_info = self.interface.cached_rest_api_get()
blockchain_info = self.interface.cached_json_rest_api_get()
version = validate_dict_and_return_key_value(
blockchain_info, 'git_hash', self._logger_metadata, stringify=True)
if version is None:
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def json_rest_api_get(self, params: dict = None):
return result
return None

def cached_rest_api_get(self, params: dict = None):
def cached_json_rest_api_get(self, params: dict = None):
"""Calls json_rest_api_get and stores the result in in-memory cache."""
cache_key = f"rest:{str(params)}"

Expand Down
20 changes: 10 additions & 10 deletions src/test_collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,47 +686,47 @@ def test_interface_attribute_exists(self):
def test_alive_call(self):
"""Tests the alive function uses the correct call"""
self.aptos_collector.alive()
self.mocked_connection.return_value.cached_rest_api_get.assert_called_once()
self.mocked_connection.return_value.cached_json_rest_api_get.assert_called_once()

def test_alive_false(self):
"""Tests the alive function returns false when get returns None"""
self.mocked_connection.return_value.cached_rest_api_get.return_value = None
self.mocked_connection.return_value.cached_json_rest_api_get.return_value = None
result = self.aptos_collector.alive()
self.assertFalse(result)

def test_block_height(self):
"""Tests the block_height function uses the correct call to get block height"""
self.aptos_collector.block_height()
self.mocked_connection.return_value.cached_rest_api_get.assert_called_once()
self.mocked_connection.return_value.cached_json_rest_api_get.assert_called_once()

def test_block_height_returns_none(self):
"""Tests that the block height returns None if cached_rest_api_get returns None"""
self.mocked_connection.return_value.cached_rest_api_get.return_value = None
"""Tests that the block height returns None if cached_json_rest_api_get returns None"""
self.mocked_connection.return_value.cached_json_rest_api_get.return_value = None
result = self.aptos_collector.block_height()
self.assertIsNone(result)

def test_client_version(self):
"""Tests the client_version function uses the correct call to get client version"""
self.aptos_collector.client_version()
self.mocked_connection.return_value.cached_rest_api_get.assert_called_once()
self.mocked_connection.return_value.cached_json_rest_api_get.assert_called_once()

def test_client_version_get_git_hash(self):
"""Tests that the client version is returned as a string with the git_hash key"""
self.mocked_connection.return_value.cached_rest_api_get.return_value = {
self.mocked_connection.return_value.cached_json_rest_api_get.return_value = {
"git_hash": "abcdef123"}
result = self.aptos_collector.client_version()
self.assertEqual({"client_version": "abcdef123"}, result)

def test_client_version_key_error_returns_none(self):
"""Tests that the client_version returns None on KeyError"""
self.mocked_connection.return_value.cached_rest_api_get.return_value = {
self.mocked_connection.return_value.cached_json_rest_api_get.return_value = {
"dummy_key": "value"}
result = self.aptos_collector.client_version()
self.assertIsNone(result)

def test_client_version_returns_none(self):
"""Tests that the client_version returns None if cached_rest_api_get returns None"""
self.mocked_connection.return_value.cached_rest_api_get.return_value = None
"""Tests that the client_version returns None if cached_json_rest_api_get returns None"""
self.mocked_connection.return_value.cached_json_rest_api_get.return_value = None
result = self.aptos_collector.client_version()
self.assertIsNone(result)

Expand Down

0 comments on commit 94d4148

Please sign in to comment.