Skip to content

Commit

Permalink
Merge pull request #133 from mikegrima/datetime
Browse files Browse the repository at this point in the history
Corrected Deprecation Warnings
  • Loading branch information
mikegrima authored Apr 8, 2024
2 parents 8cb12e4 + 520aad3 commit c931fd5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:Author: Mike Grima <michael.grima@gemini.com>
"""

from datetime import datetime
from datetime import datetime, UTC
import json
from typing import Dict, Any, TypeVar

Expand Down Expand Up @@ -91,7 +91,7 @@ def execute(self, commit: bool = False) -> None:

# Save it to S3:
if commit:
dump_accounts = {"accounts": account_map, "generated": datetime.utcnow().replace(tzinfo=None, microsecond=0).isoformat() + "Z"}
dump_accounts = {"accounts": account_map, "generated": datetime.now(UTC).replace(tzinfo=None, microsecond=0).isoformat() + "Z"}
LOGGER.info(f"[🪣] Saving the report as {self.payload['inventory_object_prefix']} in {self.payload['account_inventory_bucket']}")
client = boto3.client("s3", region_name=self.payload["inventory_bucket_region"])
client.put_object(
Expand Down
12 changes: 6 additions & 6 deletions test_sam_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Resources:
Properties:
CodeUri: ./src
Handler: starfleet.starbase.entrypoints.eventbridge_timed_lambda_handler
Runtime: python3.10
Runtime: python3.12
Architectures:
- arm64
Events:
Expand Down Expand Up @@ -226,7 +226,7 @@ Resources:
Properties:
CodeUri: ./src
Handler: starfleet.worker_ships.plugins.account_index_generator.ship.lambda_handler
Runtime: python3.10
Runtime: python3.12
Architectures:
- arm64
MemorySize: 256
Expand Down Expand Up @@ -268,7 +268,7 @@ Resources:
# Properties:
# CodeUri: ./src
# Handler: starfleet.worker_ships.plugins.aws_config.ship.lambda_handler
# Runtime: python3.10
# Runtime: python3.12
# Architectures:
# - arm64
# MemorySize: 128
Expand Down Expand Up @@ -308,7 +308,7 @@ Resources:
# Properties:
# CodeUri: ./src
# Handler: starfleet.worker_ships.plugins.github_sync.ship.lambda_handler
# Runtime: python3.10
# Runtime: python3.12
# Architectures:
# - arm64
# MemorySize: 128
Expand Down Expand Up @@ -349,7 +349,7 @@ Resources:
# Properties:
# CodeUri: ./starfleet/src
# Handler: starfleet.worker_ships.plugins.iam.role_ship.lambda_handler
# Runtime: python3.10
# Runtime: python3.12
# Architectures:
# - arm64
# MemorySize: 128
Expand All @@ -376,7 +376,7 @@ Resources:
Properties:
CodeUri: ./src
Handler: starfleet.starbase.entrypoints.fanout_payload_lambda_handler
Runtime: python3.10
Runtime: python3.12
Architectures:
- arm64
Events:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# pylint: disable=redefined-outer-name,unused-argument,duplicate-code
import json
from datetime import datetime
from datetime import datetime, UTC
from typing import Any, Dict, Generator, Optional
from unittest import mock
from unittest.mock import MagicMock
Expand Down Expand Up @@ -96,7 +96,7 @@ def account_generator(paginator: Optional[str] = None) -> Dict[str, Any]:
"Name": f"Account {count + 1}",
"Status": "ACTIVE",
"JoinedMethod": "INVITED",
"JoinedTimestamp": datetime.utcnow(),
"JoinedTimestamp": datetime.now(UTC),
}
)

Expand Down
4 changes: 2 additions & 2 deletions tests/starfleet_included_plugins/github_sync/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import base64
from io import BytesIO
import os
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
import tempfile
import random
import string
Expand Down Expand Up @@ -102,7 +102,7 @@ class MockedResult:
def json(self) -> Dict[str, Any]:
"""Mocked out the JSON function to return a fake token back out."""
# Make expiration 1 hour from now:
time_stamp = (datetime.utcnow().replace(tzinfo=None, microsecond=0) + timedelta(minutes=60)).isoformat() + "Z"
time_stamp = (datetime.now(UTC).replace(tzinfo=None, microsecond=0) + timedelta(minutes=60)).isoformat() + "Z"
return {"expires_at": time_stamp, "token": "lolsometoken"}

mocked_requests = MagicMock()
Expand Down
4 changes: 2 additions & 2 deletions tests/starfleet_included_plugins/github_sync/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

# pylint: disable=unused-argument,too-many-arguments,too-many-locals
from datetime import datetime, timezone
from datetime import datetime, timezone, UTC
from typing import Any, Dict
from unittest import mock
from unittest.mock import MagicMock
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_make_installation_token(mock_installation_token: MagicMock) -> None:
auth_manager._make_installation_token("fakeorg", "987654")

assert auth_manager._installation_tokens["fakeorg"]["token"] == "lolsometoken"
assert auth_manager._installation_tokens["fakeorg"]["expiration"] > int(datetime.utcnow().timestamp())
assert auth_manager._installation_tokens["fakeorg"]["expiration"] > int(datetime.now(UTC).timestamp())

# Test with an invalid status code:
mock_installation_token.post.return_value.status_code = 401
Expand Down
2 changes: 1 addition & 1 deletion tests/worker_ship_utils/test_niceties.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_unwrap_json() -> None:
assert un_wrap_json(test_nested) == should_equal

# And values that are non-JSON:
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.UTC)
assert un_wrap_json(now) == str(now)
assert un_wrap_json(19) == 19
assert un_wrap_json(3.14) == 3.14
Expand Down

0 comments on commit c931fd5

Please sign in to comment.