From 5defb8e7f06ed38896fe4f0b802d2c0767599932 Mon Sep 17 00:00:00 2001 From: Dmitriy Kunitskiy Date: Tue, 9 Mar 2021 19:29:13 -0800 Subject: [PATCH] fixes Signed-off-by: Dmitriy Kunitskiy --- amundsen_common/log/http_header_caller_retrieval.py | 2 +- amundsen_common/models/user.py | 4 ++-- setup.py | 2 +- tests/unit/log/test_http_header_caller_retrieval.py | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/amundsen_common/log/http_header_caller_retrieval.py b/amundsen_common/log/http_header_caller_retrieval.py index 3b2c489..b1546fe 100644 --- a/amundsen_common/log/http_header_caller_retrieval.py +++ b/amundsen_common/log/http_header_caller_retrieval.py @@ -12,4 +12,4 @@ class HttpHeaderCallerRetrieval(BaseCallerRetriever): def get_caller(self) -> str: header_key = flask_app.config.get(CALLER_HEADER_KEY, 'user-agent') - return request.headers.get(header_key, 'UNKNOWN') + return request.headers.get(header_key) or 'UNKNOWN' diff --git a/amundsen_common/models/user.py b/amundsen_common/models/user.py index 61428ea..b8d76b5 100644 --- a/amundsen_common/models/user.py +++ b/amundsen_common/models/user.py @@ -57,7 +57,7 @@ def _str_no_value(self, s: Optional[str]) -> bool: return False @pre_load - def preprocess_data(self, data: Dict[str, Any], **kwargs) -> Dict[str, Any]: + def preprocess_data(self, data: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]: if self._str_no_value(data.get('user_id')): data['user_id'] = data.get('email') @@ -81,7 +81,7 @@ def preprocess_data(self, data: Dict[str, Any], **kwargs) -> Dict[str, Any]: return data @validates_schema - def validate_user(self, data: Dict[str, Any], **kwargs) -> None: + def validate_user(self, data: Dict[str, Any], **kwargs: Any) -> None: if self._str_no_value(data.get('display_name')): raise ValidationError('"display_name", "full_name", or "email" must be provided') diff --git a/setup.py b/setup.py index cfd8044..1213920 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ 'Flask>=1.0.2', 'attrs>=19.0.0', 'marshmallow>=3.0,<=3.6', - 'marshmallow-annotations @ git+https://www.github.com/hilearn/marshmallow-annotations.git@a7a2dc96932430369bdef36555082df990ed9bef#egg=marshmallow-annotations' + 'marshmallow-annotations @ git+https://www.github.com/hilearn/marshmallow-annotations.git@a7a2dc96932430369bdef36555082df990ed9bef#egg=marshmallow-annotations' # noqa ], python_requires=">=3.6", package_data={'amundsen_common': ['py.typed']}, diff --git a/tests/unit/log/test_http_header_caller_retrieval.py b/tests/unit/log/test_http_header_caller_retrieval.py index ad6d140..15ed7b1 100644 --- a/tests/unit/log/test_http_header_caller_retrieval.py +++ b/tests/unit/log/test_http_header_caller_retrieval.py @@ -5,6 +5,7 @@ import flask from mock import patch +from mock import MagicMock from amundsen_common.log import http_header_caller_retrieval from amundsen_common.log.http_header_caller_retrieval import HttpHeaderCallerRetrieval @@ -13,12 +14,11 @@ class ActionLogTest(unittest.TestCase): - def test(self) -> None: - with app.test_request_context(), patch.object(http_header_caller_retrieval, 'request') as mock_request: + with app.test_request_context(), \ + patch.object(http_header_caller_retrieval, 'request', new=MagicMock()) as mock_request: mock_request.headers.get.return_value = 'foo' actual = HttpHeaderCallerRetrieval().get_caller() - self.assertEqual(actual, 'foo')