Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to check CfgNotFound exception #469

Merged
merged 3 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datadog/util/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_hostname(hostname_from_config):
hostname = None
config = None

# first, try the config
# first, try the config if hostname_from_config is set to True
try:
if hostname_from_config:
config = get_config()
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
HOST_NAME,
FAKE_PROXY
)
from datadog.util.hostname import CfgNotFound, get_hostname

from tests.util.contextmanagers import EnvVars


Expand Down Expand Up @@ -116,9 +118,15 @@ def test_get_hostname(self, mock_config_path):
initialize()
self.assertEqual(api._host_name, HOST_NAME, api._host_name)

def test_hostname_warning_not_present(self):
try:
get_hostname(hostname_from_config=False)
except CfgNotFound:
pytest.fail("Unexpected CfgNotFound Exception")

def test_errors_suppressed(self):
"""
API `errors` field ApiError supppressed when specified
API `errors` field ApiError suppressed when specified
"""
# Test API, application keys, API host, and some HTTP client options
initialize(api_key=API_KEY, app_key=APP_KEY, api_host=API_HOST)
Expand Down