Skip to content

Commit

Permalink
Added check and test for empty API token
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Sep 15, 2023
1 parent 3e82961 commit 0d5c076
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions oppe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def request_header(api_token: str) -> dict:
:return: Authorization Header
:rtype: dict
"""
# Check if the API Token is empty
if not api_token:
raise ValueError('API Token cannot be empty')

return {
'Accept': 'application/json',
'Content-Type': 'application/json',
Expand Down
9 changes: 9 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def test_request_header():
assert header['Authorization'] == f'Bearer {api_token}'


def test_request_header_with_empty_api_token():
""" Test request header with empty api token """
api_token = ''
try:
request_header(api_token=api_token)
except ValueError as e:
assert str(e) == 'API Token cannot be empty'


def test_format_tag_name():
""" Test format tag name """
tag_name = '1.0.0'
Expand Down

0 comments on commit 0d5c076

Please sign in to comment.