-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 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,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) |