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

LocalizedModelTestCase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 42
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpClass() 0 7 1
A test_defaults() 0 9 2
B test_model_init_kwargs() 0 18 5
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'