Skip to content

Commit

Permalink
Fix future deprecate warning of django.utils.timezone.utc (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique committed Aug 15, 2022
1 parent 81f487f commit a657de6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
- Remove warning for future Django deprecation [PR #339](https://github.com/model-bakers/model_bakery/pull/339)

### Removed

Expand Down
5 changes: 2 additions & 3 deletions model_bakery/timezone.py
@@ -1,14 +1,13 @@
"""Utility functions to manage timezone code."""

from datetime import datetime
from datetime import datetime, timezone

from django.conf import settings
from django.utils.timezone import utc


def tz_aware(value: datetime) -> datetime:
"""Return an UTC-aware datetime in case of USE_TZ=True."""
if settings.USE_TZ:
value = value.replace(tzinfo=utc)
value = value.replace(tzinfo=timezone.utc)

return value
3 changes: 1 addition & 2 deletions tests/test_utils.py
Expand Up @@ -3,7 +3,6 @@
from inspect import getmodule

import pytest
from django.utils.timezone import utc

from model_bakery.utils import get_calling_module, import_from_str, seq
from tests.generic.models import User
Expand Down Expand Up @@ -145,7 +144,7 @@ def test_time(self):
@pytest.mark.parametrize("use_tz", [False, True])
def test_datetime(self, settings, use_tz):
settings.USE_TZ = use_tz
tzinfo = utc if use_tz else None
tzinfo = datetime.timezone.utc if use_tz else None

sequence = seq(
datetime.datetime(2021, 2, 11, 15, 39, 58, 457698),
Expand Down

0 comments on commit a657de6

Please sign in to comment.