Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Kunitskiy <dkunitskiy@lyft.com>
  • Loading branch information
Dmitriy Kunitskiy committed Mar 10, 2021
1 parent e0c867c commit 5defb8e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion amundsen_common/log/http_header_caller_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions amundsen_common/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']},
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/log/test_http_header_caller_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')


Expand Down

0 comments on commit 5defb8e

Please sign in to comment.