Completed
Pull Request — master (#132)
by
unknown
01:07
created

test_related_objects_in_translation_model()   B

Complexity

Conditions 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 39
rs 8.8571
1
from .utils import AppTestCase
2
3
from .testapp.models import TranslationRelated, TranslationRelatedRelation
4
5
6
class TranslationRelationTestCase(AppTestCase):
7
8
    def test_related_objects_in_translation_model(self):
9
        instance = TranslationRelated()
10
        instance.set_current_language(self.other_lang1)
11
12
        # This should not raise errors
13
        instance.title = 'Title Lang1'
14
        instance.save()
15
16
        instance.set_current_language(self.other_lang2)
17
18
        # This should not raise errors
19
        instance.title = 'Title Lang2'
20
        instance.save()
21
22
        translation1 = instance.get_translation(self.other_lang1)
23
24
        translation1.translation_relations.create(name='relation 1.1')
25
        translation1.translation_relations.create(name='relation 1.2')
26
27
        translation2 = instance.get_translation(self.other_lang2)
28
        translation2.translation_relations.create(name='relation 2.1')
29
30
        total_related_objects = TranslationRelatedRelation.objects.filter(
31
            translation__master=instance
32
        ).count()
33
34
        lang1_related_object = TranslationRelatedRelation.objects.filter(
35
            translation__language_code=self.other_lang1,
36
            translation__master=instance,
37
        ).count()
38
39
        lang2_related_objects = TranslationRelatedRelation.objects.filter(
40
            translation__language_code=self.other_lang2,
41
            translation__master=instance,
42
        ).count()
43
44
        self.assertEqual(3, total_related_objects)
45
        self.assertEqual(2, lang1_related_object)
46
        self.assertEqual(1, lang2_related_objects)
47