| 
 | 1 | +# coding: utf-8  | 
 | 2 | + | 
 | 3 | +from django.test import TestCase  | 
 | 4 | + | 
 | 5 | +from zds.member.factories import ProfileFactory  | 
 | 6 | +from zds.mp.factories import PrivateTopicFactory, PrivatePostFactory  | 
 | 7 | +from zds.utils.templatetags.interventions import interventions_privatetopics  | 
 | 8 | + | 
 | 9 | + | 
 | 10 | +class InterventionsTest(TestCase):  | 
 | 11 | + | 
 | 12 | +    def setUp(self):  | 
 | 13 | +        self.author = ProfileFactory()  | 
 | 14 | +        self.user = ProfileFactory()  | 
 | 15 | +        self.topic = PrivateTopicFactory(author=self.author.user)  | 
 | 16 | +        self.topic.participants.add(self.user.user)  | 
 | 17 | +        self.post = PrivatePostFactory(  | 
 | 18 | +            privatetopic=self.topic,  | 
 | 19 | +            author=self.author.user,  | 
 | 20 | +            position_in_topic=1)  | 
 | 21 | + | 
 | 22 | +    def test_interventions_privatetopics(self):  | 
 | 23 | +        result = interventions_privatetopics(self.author)  | 
 | 24 | +        self.assertEqual(result['total'], 1)  | 
 | 25 | + | 
 | 26 | +        result = interventions_privatetopics(self.user)  | 
 | 27 | +        self.assertEqual(result['total'], 1)  | 
 | 28 | + | 
 | 29 | +    def test_interventions_privatetopics_author_leave(self):  | 
 | 30 | + | 
 | 31 | +        # profile1 (author) leave topic  | 
 | 32 | +        move = self.topic.participants.first()  | 
 | 33 | +        self.topic.author = move  | 
 | 34 | +        self.topic.participants.remove(move)  | 
 | 35 | +        self.topic.save()  | 
 | 36 | + | 
 | 37 | +        result = interventions_privatetopics(self.user)  | 
 | 38 | +        self.assertEqual(result['total'], 1)  | 
0 commit comments