From 28989c6ba2780bae56e53d55d5bf2a1345e19ce6 Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 08:58:32 +0100 Subject: [PATCH 1/7] Update documentation --- CHANGELOG.md | 18 ++++++++++++++++++ README.md | 2 ++ docs/source/index.rst | 13 +++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daad989..517fb93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +* Add [CONTRIBUTING.md] and [SECURITY.md] [#92] +* This project is now following the [Best Practices] set forth by the +Core Infrastructure Initiative! See [CII badge details]. [#92] + +[CONTRIBUTING.md]: /CONTRIBUTING.md +[SECURITY.md]: /SECURITY.md +[Best Practices]: https://www.coreinfrastructure.org/programs/best-practices-program/ +[CII badge details]: https://bestpractices.coreinfrastructure.org/en/projects/4514 + +[#92]: https://github.com/SAP/data-attribute-recommendation-python-sdk/pull/92 + +### Changed + +* Documentation updated to include reference to TechED 2020 workshop [#93] + +[#93]: https://github.com/SAP/data-attribute-recommendation-python-sdk/pull/93 ## [0.7.1] diff --git a/README.md b/README.md index 1ceba82..d7ad24f 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ pay attention to the [CHANGELOG.md]. ## Resources +* NEW: [TechED 2020 workshop materials], including a Jupyter notebook! * [Tutorials on Data Attribute Recommendation] - **Free Trial Available** * [Tutorials on this SDK][SDK tutorials] * [Data Attribute Recommendation documentation] @@ -156,6 +157,7 @@ Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file and all other files in this repository are licensed under the Apache License, v 2.0 except as noted otherwise in the [LICENSE] file. +[TechED 2020 workshop materials]: https://github.com/SAP-samples/teched2020-INT260 [Tutorials on Data Attribute Recommendation]: https://developers.sap.com/mission.cp-aibus-data-attribute.html [SDK tutorials]: https://developers.sap.com/group.cp-aibus-data-attribute-sdk.html [SAP AI Business Services]: https://help.sap.com/viewer/product/SAP_AI_BUS/SHIP/en-US diff --git a/docs/source/index.rst b/docs/source/index.rst index cfebfe2..95810a5 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -26,8 +26,17 @@ pay attention to the `Changelog`_. Getting Started --------------- -In addition to the guide below, a more comprehensive `tutorial is available -at developers.sap.com`_. + +**News 2020-12:** Materials from the `TechED 2020 workshop`_ are online! We have +prepared a `Jupyter notebook`_ with a full tutorial and lots of additional information. +This is the most comprehensive end-to-end example available so far. + +.. _TechED 2020 workshop: https://github.com/SAP-samples/teched2020-INT260/tree/master/exercises/ex1-DAR +.. _Jupyter notebook: https://github.com/SAP-samples/teched2020-INT260/blob/master/exercises/ex1-DAR/teched2020-INT260_Data_Attribute_Recommendation.ipynb + + +The sections below in this document will help you get started. In addition to the guide +below, a more comprehensive `tutorial is available at developers.sap.com`_. .. _tutorial is available at developers.sap.com: https://developers.sap.com/group.cp-aibus-data-attribute-sdk.html From 96551f8140843eba655c9837d3b38506f41d5f8c Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 08:59:31 +0100 Subject: [PATCH 2/7] Report branch coverage --- CHANGELOG.md | 1 + tox.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 517fb93..5a09333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Core Infrastructure Initiative! See [CII badge details]. [#92] ### Changed * Documentation updated to include reference to TechED 2020 workshop [#93] +* Tests: report branch coverage [#93] [#93]: https://github.com/SAP/data-attribute-recommendation-python-sdk/pull/93 diff --git a/tox.ini b/tox.ini index 46c9813..5ee8d03 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,7 @@ commands = --cov=sap \ --cov-fail-under=96 \ --cov-report= \ + --cov-branch \ --junitxml=test_results/{envname}/unit_xunit.xml \ --junit-prefix={envname} \ -o junit_suite_name={envname} \ From 171b90c171c4622820cac5dda5767f5973274527 Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 09:01:23 +0100 Subject: [PATCH 3/7] Fix formatting --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a09333..f650b65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add [CONTRIBUTING.md] and [SECURITY.md] [#92] * This project is now following the [Best Practices] set forth by the -Core Infrastructure Initiative! See [CII badge details]. [#92] + Core Infrastructure Initiative! See [CII badge details]. [#92] [CONTRIBUTING.md]: /CONTRIBUTING.md [SECURITY.md]: /SECURITY.md From 20f3dc61d0b9828dc1c7b5d7012d70ff6959e778 Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 09:02:01 +0100 Subject: [PATCH 4/7] Formatting --- docs/source/index.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 95810a5..aa23ad1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -34,7 +34,6 @@ This is the most comprehensive end-to-end example available so far. .. _TechED 2020 workshop: https://github.com/SAP-samples/teched2020-INT260/tree/master/exercises/ex1-DAR .. _Jupyter notebook: https://github.com/SAP-samples/teched2020-INT260/blob/master/exercises/ex1-DAR/teched2020-INT260_Data_Attribute_Recommendation.ipynb - The sections below in this document will help you get started. In addition to the guide below, a more comprehensive `tutorial is available at developers.sap.com`_. From c1391cf13d11af4b0a2cf1157d3bebd2364d1580 Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 11:32:29 +0100 Subject: [PATCH 5/7] Raise test coverage again The introduction of branch coverage metrics reduced test coverage by 0.3%, which caused the coveralls PR checker to fail. --- sap/aibus/dar/client/util/credentials.py | 2 ++ tests/sap/aibus/dar/util/test_credentials.py | 16 ++++++++++++++++ tests/sap/aibus/dar/util/test_logging.py | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/sap/aibus/dar/client/util/credentials.py b/sap/aibus/dar/client/util/credentials.py index 8d9ca3d..25709de 100644 --- a/sap/aibus/dar/client/util/credentials.py +++ b/sap/aibus/dar/client/util/credentials.py @@ -148,6 +148,8 @@ def token(self) -> str: # add a 5m grace period: retrieve token earlier. self._token_expires_at = self._token_expires_at - 300 if self._token is None: + # This check mainly exists to signal to the mypy type checker + # that the return value cannot be None raise ValueError("Token not found in authentication server response!") return self._token diff --git a/tests/sap/aibus/dar/util/test_credentials.py b/tests/sap/aibus/dar/util/test_credentials.py index 93d5115..8e77af5 100644 --- a/tests/sap/aibus/dar/util/test_credentials.py +++ b/tests/sap/aibus/dar/util/test_credentials.py @@ -142,6 +142,22 @@ def test_token_retrieval(self, online_credentials_source_with_mock_session): assert mock_response.raise_for_status.call_count == 1 assert observed_token == "the-token" + def test_token_retrieval_raises_if_access_token_is_none( + self, online_credentials_source_with_mock_session + ): + mock_response = online_credentials_source_with_mock_session.session.get() + mock_response.json.side_effect = [ + { + "access_token": None, + "token_type": "bearer", + "expires_in": 43199, + "scope": "scope1 scope2 scope3", + } + ] + + with pytest.raises(ValueError): + online_credentials_source_with_mock_session.token() + def test_token_caching(self, online_credentials_source_with_mock_session): mock_session = online_credentials_source_with_mock_session.session diff --git a/tests/sap/aibus/dar/util/test_logging.py b/tests/sap/aibus/dar/util/test_logging.py index cfa3642..2a6b846 100644 --- a/tests/sap/aibus/dar/util/test_logging.py +++ b/tests/sap/aibus/dar/util/test_logging.py @@ -1,4 +1,6 @@ from logging import Logger +import sys +from unittest.mock import patch, call from sap.aibus.dar.client.util.logging import LoggerMixin @@ -16,3 +18,19 @@ def test(self): assert isinstance(instance.log, Logger) assert instance.log.name == "tests.sap.aibus.dar.util.test_logging.ExampleClass" + + @patch("sap.aibus.dar.client.util.logging.logging", autospec=True) + def setup_basic_logging(self, logging_mock): + LoggerMixin.setup_basic_logging() + + assert logging_mock.call_args_list == [ + call(level=logging_mock.INFO, stream=sys.stdout) + ] + + @patch("sap.aibus.dar.client.util.logging.logging", autospec=True) + def setup_basic_logging_debug(self, logging_mock): + LoggerMixin.setup_basic_logging(debug=True) + + assert logging_mock.call_args_list == [ + call(level=logging_mock.DEBUG, stream=sys.stdout) + ] From 5259f814220f8d06887c17632fd1c6dec434f554 Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 11:43:29 +0100 Subject: [PATCH 6/7] Fix test method names --- tests/sap/aibus/dar/util/test_logging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sap/aibus/dar/util/test_logging.py b/tests/sap/aibus/dar/util/test_logging.py index 2a6b846..b3aa2d7 100644 --- a/tests/sap/aibus/dar/util/test_logging.py +++ b/tests/sap/aibus/dar/util/test_logging.py @@ -20,7 +20,7 @@ def test(self): assert instance.log.name == "tests.sap.aibus.dar.util.test_logging.ExampleClass" @patch("sap.aibus.dar.client.util.logging.logging", autospec=True) - def setup_basic_logging(self, logging_mock): + def test_setup_basic_logging(self, logging_mock): LoggerMixin.setup_basic_logging() assert logging_mock.call_args_list == [ @@ -28,7 +28,7 @@ def setup_basic_logging(self, logging_mock): ] @patch("sap.aibus.dar.client.util.logging.logging", autospec=True) - def setup_basic_logging_debug(self, logging_mock): + def test_setup_basic_logging_debug(self, logging_mock): LoggerMixin.setup_basic_logging(debug=True) assert logging_mock.call_args_list == [ From aeff8df279b107b634f785333bf4b152935ee873 Mon Sep 17 00:00:00 2001 From: Michael Haas Date: Wed, 16 Dec 2020 11:58:59 +0100 Subject: [PATCH 7/7] Fix tests --- tests/sap/aibus/dar/util/test_logging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sap/aibus/dar/util/test_logging.py b/tests/sap/aibus/dar/util/test_logging.py index b3aa2d7..59878e9 100644 --- a/tests/sap/aibus/dar/util/test_logging.py +++ b/tests/sap/aibus/dar/util/test_logging.py @@ -23,7 +23,7 @@ def test(self): def test_setup_basic_logging(self, logging_mock): LoggerMixin.setup_basic_logging() - assert logging_mock.call_args_list == [ + assert logging_mock.basicConfig.call_args_list == [ call(level=logging_mock.INFO, stream=sys.stdout) ] @@ -31,6 +31,6 @@ def test_setup_basic_logging(self, logging_mock): def test_setup_basic_logging_debug(self, logging_mock): LoggerMixin.setup_basic_logging(debug=True) - assert logging_mock.call_args_list == [ + assert logging_mock.basicConfig.call_args_list == [ call(level=logging_mock.DEBUG, stream=sys.stdout) ]