Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use django timezone util to avoid runtime warnings #34

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions field_audit/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import datetime
from enum import Enum
from functools import wraps
from itertools import islice

from django.conf import settings
from django.db import models, transaction
from django.db.models import Expression
from django.utils import timezone

from .const import BOOTSTRAP_BATCH_SIZE
from .utils import class_import_helper
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_date():
This is the "getter" for default values of the ``AuditEvent.event_date``
field.
"""
return datetime.utcnow()
return timezone.now()


class AuditEvent(models.Model):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import ContextDecorator
from datetime import datetime, timedelta
from datetime import timedelta
from enum import Enum
from unittest.mock import ANY, Mock, patch

Expand All @@ -10,6 +10,7 @@
from django.db.models import Case, When, Value
from django.db.utils import IntegrityError, DatabaseError
from django.test import TestCase, override_settings
from django.utils import timezone

from field_audit.auditors import audit_dispatcher
from field_audit.const import BOOTSTRAP_BATCH_SIZE
Expand Down Expand Up @@ -295,7 +296,7 @@ def test_get_manager_uses_default_if_no_setting(self):
def test_get_date(self):
then = get_date()
self.assertLess(
datetime.utcnow() - then,
timezone.now() - then,
timedelta(seconds=1),
)

Expand Down