Passed
Pull Request — master (#1)
by
unknown
01:52
created

LocalizedModelTestCase.test_set()   A

Complexity

Conditions 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 12
rs 9.2
1
from django.test import TestCase
2
from django.utils import translation
3
4
from localized_fields.fields import LocalizedValue
5
6
from .fake_model import get_fake_model
7
from .test_localized_field import get_init_values
8
9
10
class LocalizedModelTestCase(TestCase):
11
    """Tests whether the :see:LocalizedValueDescriptor class."""
12
13
    TestModel = None
14
15
    @classmethod
16
    def setUpClass(cls):
17
        """Creates the test model in the database."""
18
19
        super(LocalizedModelTestCase, cls).setUpClass()
20
21
        cls.TestModel = get_fake_model()
22
23
    @classmethod
24
    def test_defaults(cls):
25
        """Tests whether all :see:LocalizedField
26
        fields are assigned an empty :see:LocalizedValue
27
        instance when the model is instanitiated."""
28
29
        obj = cls.TestModel()
30
31
        assert isinstance(obj.title, LocalizedValue)
32
33
    @classmethod
34
    def test_set(cls):
35
        """Tests whether the :see:LocalizedValueDescriptor
36
        class's see:set function works properly."""
37
38
        obj = cls.TestModel()
39
40
        for language, value in get_init_values():
41
            translation.activate(language)
42
            obj.title = value
43
            assert obj.title.get(language) == value
44
            assert getattr(obj.title, language) == value
45