Skip to content

Commit

Permalink
Merge pull request #98 from bklynhlth/1.8.x
Browse files Browse the repository at this point in the history
1.8.x to main
  • Loading branch information
vjbytes102 authored Jul 11, 2024
2 parents b12c27f + c62e6b1 commit 781c791
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from willisapi_client.services.auth.login_manager import login

from unittest.mock import patch
from datetime import timedelta, datetime
from datetime import timedelta, datetime, timezone


class TestLoginFunction:
def setup_method(self):
self.dt = datetime.now()
self.dt = datetime.now(timezone.utc)
self.username = "dummy"
self.password = "password"
self.id_token = "dummy_token"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_re_upload_success(
mocked_df.return_value = pd.DataFrame([self.df_row], columns=self.df_cols)
mock_row_validation.return_value = True, None
mocked_upload.return_value = True, None
df = upload(self.key, self.metadata, reupload="force")
df = upload(self.key, self.metadata, force_upload="true")
num = len(df[df["upload_status"] == "success"])
assert num == 1
assert list(df.columns) == self.response_df_cols
Expand Down
2 changes: 1 addition & 1 deletion willisapi_client/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Version details for willisapi_client
"""
__client__ = "willisapi_client"
__latestVersion__ = "1.7"
__latestVersion__ = "1.8"
__url__ = "https://github.com/bklynhlth/willsiapi_client"
__short_description__ = "A Python client for willisapi"
__content_type__ = "text/markdown"
6 changes: 3 additions & 3 deletions willisapi_client/services/auth/login_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from http import HTTPStatus

# import datetime
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from willisapi_client.willisapi_client import WillisapiClient
from willisapi_client.services.auth.auth_utils import AuthUtils
Expand Down Expand Up @@ -41,10 +41,10 @@ def login(username: str, password: str, **kwargs) -> Tuple[str, int]:
):
logger.info("Login Successful; Key acquired")
logger.info(
f"Key expiration: {datetime.now() + timedelta(seconds=response['result']['expires_in'])}"
f"Key expiration: {datetime.now(timezone.utc) + timedelta(seconds=response['result']['expires_in'])}"
)
required_format = (
f"{datetime.now() + timedelta(seconds=response['result']['expires_in'])}"
f"{datetime.now(timezone.utc) + timedelta(seconds=response['result']['expires_in'])}"
)
return (response["result"]["id_token"], required_format)
else:
Expand Down
4 changes: 2 additions & 2 deletions willisapi_client/services/upload/multipart_upload_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def upload(key, data, **kwargs):
logger.info(f'{datetime.now().strftime("%H:%M:%S")}: csv check passed')
dataframe = csv.get_dataframe()
wc = WillisapiClient(env=kwargs.get("env"))
reupload = "true" if kwargs.get("reupload") == "force" else "false"
force_upload = "true" if kwargs.get("force_upload") == True else False
url = wc.get_upload_url()
headers = wc.get_headers()
headers["Authorization"] = key
Expand All @@ -43,7 +43,7 @@ def upload(key, data, **kwargs):
(is_valid_row, error) = csv.validate_row(row)
if is_valid_row:
(uploaded, error) = UploadUtils.upload(
index, row, url, headers, reupload
index, row, url, headers, force_upload
)
if uploaded:
summary.append([row.file_path, "success", None])
Expand Down
9 changes: 5 additions & 4 deletions willisapi_client/services/upload/upload_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_file_size_and_parts(file_path: str) -> int:
return number_of_parts

def initiate_multi_part_upload(
index: int, row, url: str, headers: dict, reupload: str
index: int, row, url: str, headers: dict, force_upload: str
) -> Tuple[str, str]:
"""
------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -146,7 +146,7 @@ def initiate_multi_part_upload(

try:
response = requests.post(
f"{url}?type=initiate&reupload={reupload}", json=data, headers=headers
f"{url}?type=initiate&force_upload={force_upload}", json=data, headers=headers
)
res_json = response.json()
except Exception as ex:
Expand All @@ -171,6 +171,7 @@ def initiate_multi_part_upload(

else:
if "message" in res_json and res_json["message"] == "Unauthorized":
error = res_json["message"]
logger.error(
"Your Key is expired. Login again to generate a new key"
)
Expand Down Expand Up @@ -279,7 +280,7 @@ async def async_upload(presigned_urls, file):
return SORTED_PARTS

@staticmethod
def upload(index, row, url, headers, reupload) -> Tuple[bool, str]:
def upload(index, row, url, headers, force_upload) -> Tuple[bool, str]:
"""
------------------------------------------------------------------------------------------------------
Class: UploadUtils
Expand All @@ -302,7 +303,7 @@ def upload(index, row, url, headers, reupload) -> Tuple[bool, str]:
------------------------------------------------------------------------------------------------------
"""
(upload_id, record_id, error) = UploadUtils.initiate_multi_part_upload(
index, row, url, headers, reupload
index, row, url, headers, force_upload
)
uploaded = False
if upload_id and record_id:
Expand Down

0 comments on commit 781c791

Please sign in to comment.