Passed
Pull Request — master (#2)
by Emil
11:11
created

LocalizedModelTestCase.test_model_init_kwargs()   B

Complexity

Conditions 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 18
rs 8.5454
1
from django.test import TestCase
2
3
from localized_fields import LocalizedValue
4
5
from .fake_model import get_fake_model
6
7
8
class LocalizedModelTestCase(TestCase):
9
    """Tests whether the :see:LocalizedModel class."""
10
11
    TestModel = None
12
13
    @classmethod
14
    def setUpClass(cls):
15
        """Creates the test model in the database."""
16
17
        super(LocalizedModelTestCase, cls).setUpClass()
18
19
        cls.TestModel = get_fake_model()
20
21
    @classmethod
22
    def test_defaults(cls):
23
        """Tests whether all :see:LocalizedField
24
        fields are assigned an empty :see:LocalizedValue
25
        instance when the model is instanitiated."""
26
27
        obj = cls.TestModel()
28
29
        assert isinstance(obj.title, LocalizedValue)
30
31
32
    @classmethod
33
    def test_model_init_kwargs(cls):
34
        """Tests whether all :see:LocalizedField
35
        fields are assigned an empty :see:LocalizedValue
36
        instance when the model is instanitiated."""
37
        data = {
38
            'title': {
39
                'en': 'english_title',
40
                'ro': 'romanian_title',
41
                'nl': 'dutch_title'
42
            }
43
        }
44
        obj = cls.TestModel(**data)
45
46
        assert isinstance(obj.title, LocalizedValue)
47
        assert obj.title.en == 'english_title'
48
        assert obj.title.ro == 'romanian_title'
49
        assert obj.title.nl == 'dutch_title'