Skip to content

Commit

Permalink
feat: add tests for MessageMediaModel creation with and without passi…
Browse files Browse the repository at this point in the history
…ng created_on
  • Loading branch information
kallilsouza committed Jan 6, 2025
1 parent 2af4956 commit 0b3ce1f
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions chats/apps/msgs/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
from django.utils import timezone
from django.utils.timezone import timedelta

from chats.apps.msgs.models import Message
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_message_passing_created_on(self):
def test_create_message_passing_created_on(self):
timestamp = timezone.now() - timedelta(days=2)

msg = Message.objects.create(room=self.room, created_on=timestamp)
Expand All @@ -20,7 +20,28 @@ def test_message_passing_created_on(self):
self.assertEqual(msg.created_on.minute, timestamp.minute)
self.assertEqual(msg.created_on.second, timestamp.second)

def test_message_without_passing_created_on(self):
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())

0 comments on commit 0b3ce1f

Please sign in to comment.