1
|
|
|
from __future__ import unicode_literals |
2
|
|
|
from django.core.cache import cache |
3
|
|
|
from .utils import AppTestCase |
4
|
|
|
from .testapp.models import Level2 |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class ModelInheritanceTests(AppTestCase): |
8
|
|
|
""" |
9
|
|
|
Tests with model attributes for multiple object levels |
10
|
|
|
""" |
11
|
|
|
|
12
|
|
|
def test_init_args(self): |
13
|
|
|
""" |
14
|
|
|
Test whether passing translated attributes to __init__() works. |
15
|
|
|
""" |
16
|
|
|
x = Level2(l1_title='LEVEL1', l2_title='LEVEL2', id=1) |
17
|
|
|
self.assertEqual(x.l1_title, "LEVEL1") |
18
|
|
|
self.assertEqual(x.l2_title, "LEVEL2") |
19
|
|
|
|
20
|
|
|
def test_save_two_levels(self): |
21
|
|
|
x = Level2(l1_title='LEVEL1', l2_title='LEVEL2', id=2) |
22
|
|
|
x.save() |
23
|
|
|
cache.clear() |
24
|
|
|
|
25
|
|
|
# See if fetching the object again works |
26
|
|
|
x = Level2.objects.get(pk=x.pk) |
27
|
|
|
self.assertEqual(x.l1_title, "LEVEL1") |
28
|
|
|
self.assertEqual(x.l2_title, "LEVEL2") |
29
|
|
|
|
30
|
|
|
# check that the translations exist after saving |
31
|
|
|
translation = Level2._parler_meta[-1].model.objects.get(master=x) |
32
|
|
|
self.assertEqual(translation.l2_title, "LEVEL2") |
33
|
|
|
|
34
|
|
|
def test_prefetch_levels(self): |
35
|
|
|
x = Level2(l1_title='LEVEL1', l2_title='LEVEL2', id=3) |
36
|
|
|
x.save() |
37
|
|
|
|
38
|
|
|
x = Level2.objects.prefetch_related('l1_translations').get(pk=x.pk) |
39
|
|
|
self.assertEqual(x.l1_title, "LEVEL1") |
40
|
|
|
self.assertEqual(x.l2_title, "LEVEL2") |
41
|
|
|
|