-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests to ensure that created_on works as expected
- Loading branch information
1 parent
ed5d7c6
commit e6582b4
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.test import TestCase | ||
from django.utils import timezone | ||
from django.utils.timezone import timedelta | ||
|
||
from chats.apps.msgs.models import Message | ||
from chats.apps.rooms.models import Room | ||
|
||
|
||
class TestMessageModel(TestCase): | ||
def setUp(self): | ||
self.room = Room.objects.create() | ||
|
||
def test_message_passing_created_on(self): | ||
timestamp = timezone.now() - timedelta(days=2) | ||
|
||
msg = Message.objects.create(room=self.room, created_on=timestamp) | ||
|
||
self.assertEqual(msg.created_on.date(), timestamp.date()) | ||
self.assertEqual(msg.created_on.hour, timestamp.hour) | ||
self.assertEqual(msg.created_on.minute, timestamp.minute) | ||
self.assertEqual(msg.created_on.second, timestamp.second) | ||
|
||
def test_message_without_passing_created_on(self): | ||
msg = Message.objects.create(room=self.room) | ||
|
||
self.assertEqual(msg.created_on.date(), timezone.now().date()) |