Skip to content

Commit

Permalink
feat: add tests to ensure that created_on works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
kallilsouza committed Jan 6, 2025
1 parent ed5d7c6 commit e6582b4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions chats/apps/msgs/tests/test_models.py
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())

0 comments on commit e6582b4

Please sign in to comment.