From 06af7450241466efc393ba5af1e03772076704fb Mon Sep 17 00:00:00 2001 From: phaesler Date: Tue, 31 Aug 2021 14:50:28 +1000 Subject: [PATCH 1/3] misc coverage. --- tests/test_startup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_startup.py b/tests/test_startup.py index f6baf94cf..d1d7817db 100644 --- a/tests/test_startup.py +++ b/tests/test_startup.py @@ -53,12 +53,20 @@ def test_initialise_ign_warn(): initialise_ignorable_warnings() -def test_initialise_debugging(monkeypatch): +def test_initialise_nodebugging(monkeypatch): monkeypatch.setenv("PYDEV_DEBUG", "") from datacube_ows.startup_utils import initialise_debugging initialise_debugging() +def test_initialise_debugging(monkeypatch): + monkeypatch.setenv("PYDEV_DEBUG", "YES") + from datacube_ows.startup_utils import initialise_debugging + with patch("pydevd_pycharm.settrace") as set_trc: + initialise_debugging() + set_trc.assert_called() + + def test_initialise_sentry(monkeypatch): monkeypatch.setenv("SENTRY_KEY", "") monkeypatch.setenv("SENTRY_PROJECT", "") @@ -66,8 +74,9 @@ def test_initialise_sentry(monkeypatch): initialise_sentry() monkeypatch.setenv("SENTRY_KEY", "dummy_key") monkeypatch.setenv("SENTRY_PROJECT", "dummy_project") + log = MagicMock() try: - initialise_sentry() + initialise_sentry(log) except Exception: pass From 34cbf8d48969e812db210aeb9304e566b8a02a4c Mon Sep 17 00:00:00 2001 From: phaesler Date: Tue, 31 Aug 2021 15:34:30 +1000 Subject: [PATCH 2/3] renewable_creds_coverage --- tests/test_startup.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_startup.py b/tests/test_startup.py index d1d7817db..acb8860e7 100644 --- a/tests/test_startup.py +++ b/tests/test_startup.py @@ -31,6 +31,28 @@ def test_fake_creds(monkeypatch): initialise_aws_credentials() assert os.getenv("AWS_ACCESS_KEY_ID") == "fake" + +def test_renewable_creds(monkeypatch): + from datacube_ows.startup_utils import (CredentialManager, + RefreshableCredentials, + initialise_aws_credentials) + CredentialManager._instance = None + log = MagicMock() + monkeypatch.setenv("AWS_DEFAULT_REGION", "") + initialise_aws_credentials(log=log) + CredentialManager._instance = None + monkeypatch.setenv("AWS_DEFAULT_REGION", "us-west-1") + monkeypatch.setenv("AWS_NO_SIGN_REQUEST", "false") + monkeypatch.setenv("AWS_REQUEST_PAYER", "requester") + with patch("datacube_ows.startup_utils.configure_s3_access") as s3a: + mock_creds = MagicMock(spec=RefreshableCredentials) + s3a.return_value = mock_creds + initialise_aws_credentials(log=log) + CredentialManager.check_cred() + mock_creds.refresh_needed.return_value = True + CredentialManager.check_cred() + + def test_s3_endpoint_default(monkeypatch): from datacube_ows.startup_utils import (CredentialManager, initialise_aws_credentials) From d38ed4fccf9d8c5f49ea95995781f092068404dc Mon Sep 17 00:00:00 2001 From: phaesler Date: Tue, 31 Aug 2021 15:59:51 +1000 Subject: [PATCH 3/3] Make debug test pass when pydevd is not installed. --- tests/test_startup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_startup.py b/tests/test_startup.py index acb8860e7..3e923ad87 100644 --- a/tests/test_startup.py +++ b/tests/test_startup.py @@ -84,9 +84,10 @@ def test_initialise_nodebugging(monkeypatch): def test_initialise_debugging(monkeypatch): monkeypatch.setenv("PYDEV_DEBUG", "YES") from datacube_ows.startup_utils import initialise_debugging - with patch("pydevd_pycharm.settrace") as set_trc: + fake_mod = MagicMock() + with patch.dict("sys.modules", pydevd_pycharm=fake_mod) as set_trc: initialise_debugging() - set_trc.assert_called() + fake_mod.settrace.assert_called() def test_initialise_sentry(monkeypatch):