Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Aug 21, 2023
1 parent 0bd55e8 commit b5fe97a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.test import TestCase

from lemarche.conversations.factories import ConversationFactory
from lemarche.conversations.models import Conversation


class ConversationModelTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.conversation = ConversationFactory(title="Je souhaite me renseigner")

def test_count(self):
self.assertEqual(Conversation.objects.count(), 1)

def test_uuid_field(self):
self.assertEqual(len(self.conversation.uuid), 22)

def test_str(self):
self.assertEqual(str(self.conversation), "Je souhaite me renseigner")


class ConversationQuerysetTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.conversation = ConversationFactory()
cls.conversation_with_answer = ConversationFactory(
data=[{"items": [{"To": [{"Name": "buyer"}], "From": {"Name": "siae"}}]}]
)

def test_has_answer(self):
self.assertEqual(Conversation.objects.has_answer().count(), 1)

def test_with_answer_count(self):
conversation_queryset = Conversation.objects.with_answer_count()
self.assertEqual(conversation_queryset.get(id=self.conversation.id).answer_count, 0)
self.assertEqual(conversation_queryset.get(id=self.conversation_with_answer.id).answer_count, 1)

0 comments on commit b5fe97a

Please sign in to comment.