This repository has been archived by the owner on Sep 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48fe4f8
commit 5cef327
Showing
10 changed files
with
101 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "key" : "E9K4A1AC8H1V3ZIR1DAIKZ6B961CRXF2DR" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from unittest import mock | ||
|
||
from etherollapp.etheroll.utils import get_etherscan_api_key | ||
|
||
|
||
class TestUtils: | ||
def test_get_etherscan_api_key(self): | ||
""" | ||
Verifies the key can be retrieved from either: | ||
1) environment | ||
2) file | ||
3) or fallbacks on default key | ||
""" | ||
expected_key = "0102030405060708091011121314151617" | ||
# 1) environment | ||
with mock.patch.dict( | ||
"os.environ", {"ETHERSCAN_API_KEY": expected_key} | ||
): | ||
actual_key = get_etherscan_api_key() | ||
assert actual_key == expected_key | ||
# 2) file | ||
read_data = '{ "key" : "%s" }' % (expected_key) | ||
api_key_path = "api_key.json" | ||
with mock.patch( | ||
"builtins.open", mock.mock_open(read_data=read_data) | ||
) as m_open: | ||
actual_key = get_etherscan_api_key(api_key_path=api_key_path) | ||
assert expected_key == actual_key | ||
# verifies the file was read | ||
assert m_open.call_args_list == [mock.call(api_key_path, mode="r")] | ||
# 3) or fallbacks on default key | ||
with mock.patch("builtins.open") as m_open, mock.patch( | ||
"etherollapp.etheroll.utils.logger" | ||
) as m_logger: | ||
m_open.side_effect = FileNotFoundError | ||
actual_key = get_etherscan_api_key(api_key_path) | ||
assert "YourApiKeyToken" == actual_key | ||
# verifies the fallback warning was logged | ||
assert m_logger.warning.call_args_list == [ | ||
mock.call( | ||
"Cannot get Etherscan API key. " | ||
"File api_key.json not found, " | ||
"defaulting to YourApiKeyToken." | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters