Skip to content

Commit

Permalink
Use django.utils.timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
hrichards committed Aug 27, 2024
1 parent 868a4bd commit 44b8ea5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions capone/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@
'django.contrib.messages.middleware.MessageMiddleware',
)
SESSION_ENGINE = 'django.contrib.sessions.backends.db'

USE_TZ = True
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import datetime
from datetime import timedelta
from decimal import Decimal

from django.test import TestCase
from django.utils import timezone

from capone.api.actions import credit
from capone.api.actions import debit
Expand All @@ -22,8 +22,8 @@ def test_transaction_fields(self):
"""
Test filtering by `posted_timestamp`, `notes`, `type`, and `user`.
"""
time = datetime.now()
wrong_time = datetime.now() - timedelta(days=1)
time = timezone.now()
wrong_time = timezone.now() - timedelta(days=1)
user1 = UserFactory()
user2 = UserFactory()
credit_card_transaction = CreditCardTransactionFactory()
Expand Down
4 changes: 2 additions & 2 deletions capone/tests/test_create_transaction.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import datetime
from decimal import Decimal as D
from unittest import mock

from django.test import TestCase
from django.utils import timezone

from capone.exceptions import ExistingLedgerEntriesException
from capone.exceptions import NoLedgerEntriesException
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_using_ledgers_for_reconciliation(self):
)

def test_setting_posted_timestamp(self):
POSTED_DATETIME = datetime(2016, 2, 7, 11, 59)
POSTED_DATETIME = timezone.now()
order = OrderFactory(amount=self.AMOUNT)

txn_recognize = create_transaction(
Expand Down
4 changes: 2 additions & 2 deletions capone/tests/test_factories.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from decimal import Decimal

from django.test import TestCase
from django.utils import timezone

from capone.api.actions import credit
from capone.api.actions import debit
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_custom_fields(self):
"""
Test setting fields `posted_timestamp`, `notes`, `type`, and `user`.
"""
time = datetime.now()
time = timezone.now()
FIELDS_TO_VALUES = [
('posted_timestamp', time),
('notes', 'booga'),
Expand Down
6 changes: 3 additions & 3 deletions capone/tests/test_transaction_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from decimal import Decimal

from django.test import TestCase
from django.utils import timezone

from capone.api.actions import create_transaction
from capone.api.actions import credit
Expand All @@ -27,7 +27,7 @@ class TransactionBase(TestCase):
def setUp(self):
self.user1 = UserFactory()
self.user2 = UserFactory()
self.posted_timestamp = datetime.now()
self.posted_timestamp = timezone.now()


class TestStrMethods(TestCase):
Expand Down Expand Up @@ -102,7 +102,7 @@ class TestSettingExplicitTimestampField(TransactionBase):
def test_setting_explicit_timestamp_field(self):
transaction = TransactionFactory()
old_posted_timestamp = transaction.posted_timestamp
transaction.posted_timestamp = datetime.now()
transaction.posted_timestamp = timezone.now()
transaction.save()
self.assertNotEqual(
old_posted_timestamp,
Expand Down
4 changes: 2 additions & 2 deletions capone/tests/test_void.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from decimal import Decimal as D

from django.test import TestCase
from django.utils import timezone

from capone.api.actions import create_transaction
from capone.api.actions import credit
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_given_timestamp(self):
LedgerEntry(amount=credit(amount), ledger=self.rev_ledger),
])

now = datetime.now()
now = timezone.now()
void_txn = void_transaction(
charge_txn, self.creation_user,
posted_timestamp=now)
Expand Down

0 comments on commit 44b8ea5

Please sign in to comment.