-
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.
Merge pull request #435 from weni-ai/fix/chat-messages-timestamps
Fix/chat messages timestamps
- Loading branch information
Showing
4 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
chats/apps/msgs/migrations/0008_alter_message_created_on_and_more.py
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,32 @@ | ||
# Generated by Django 4.1.2 on 2025-01-06 19:32 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("msgs", "0007_alter_message_options"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="message", | ||
name="created_on", | ||
field=models.DateTimeField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="Created on", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="messagemedia", | ||
name="created_on", | ||
field=models.DateTimeField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="Created on", | ||
), | ||
), | ||
] |
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
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,47 @@ | ||
from django.test import TestCase | ||
from django.utils import timezone | ||
from django.utils.timezone import timedelta | ||
|
||
from chats.apps.msgs.models import Message, MessageMedia | ||
from chats.apps.rooms.models import Room | ||
|
||
|
||
class TestMessageModel(TestCase): | ||
def setUp(self): | ||
self.room = Room.objects.create() | ||
|
||
def test_create_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_create_message_without_passing_created_on(self): | ||
msg = Message.objects.create(room=self.room) | ||
|
||
self.assertEqual(msg.created_on.date(), timezone.now().date()) | ||
|
||
|
||
class TestMessageMediaModel(TestCase): | ||
def setUp(self): | ||
self.room = Room.objects.create() | ||
self.msg = Message.objects.create(room=self.room) | ||
|
||
def test_create_message_media_passing_created_on(self): | ||
timestamp = timezone.now() - timedelta(days=2) | ||
|
||
msg_media = MessageMedia.objects.create(message=self.msg, created_on=timestamp) | ||
|
||
self.assertEqual(msg_media.created_on.date(), timestamp.date()) | ||
self.assertEqual(msg_media.created_on.hour, timestamp.hour) | ||
self.assertEqual(msg_media.created_on.minute, timestamp.minute) | ||
self.assertEqual(msg_media.created_on.second, timestamp.second) | ||
|
||
def test_create_message_media_without_passing_created_on(self): | ||
msg_media = MessageMedia.objects.create(message=self.msg) | ||
|
||
self.assertEqual(msg_media.created_on.date(), timezone.now().date()) |
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