Skip to content
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ 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]
* Tests: report branch coverage [#93]

[#93]: https://github.com/SAP/data-attribute-recommendation-python-sdk/pull/93

## [0.7.1]

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ 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

Expand Down
2 changes: 2 additions & 0 deletions sap/aibus/dar/client/util/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions tests/sap/aibus/dar/util/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/sap/aibus/dar/util/test_logging.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 test_setup_basic_logging(self, logging_mock):
LoggerMixin.setup_basic_logging()

assert logging_mock.basicConfig.call_args_list == [
call(level=logging_mock.INFO, stream=sys.stdout)
]

@patch("sap.aibus.dar.client.util.logging.logging", autospec=True)
def test_setup_basic_logging_debug(self, logging_mock):
LoggerMixin.setup_basic_logging(debug=True)

assert logging_mock.basicConfig.call_args_list == [
call(level=logging_mock.DEBUG, stream=sys.stdout)
]
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down