Test Failed
Pull Request — master (#50)
by
unknown
01:52
created

LocalizedIntegerFieldTestCase.test_from_db_value()   B

Complexity

Conditions 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 13
rs 8
cc 6
1
from django.test import TestCase
0 ignored issues
show
Configuration introduced by
The import django.test could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2
from django.conf import settings
0 ignored issues
show
Configuration introduced by
The import django.conf could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
3
from localized_fields.fields import LocalizedIntegerField
4
5
from .data import get_init_integer_values
6
from .fake_model import get_fake_model
7
8
class LocalizedIntegerFieldTestCase(TestCase):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
9
10
    @staticmethod
11
    def test_from_db_value():
12
        """Tests whether the :see:from_db_value function
13
        produces the expected :see:LocalizedValue."""
14
15
        input_data = get_init_integer_values()
16
        localized_value = LocalizedIntegerField().from_db_value(input_data)
17
18
        for lang_code, _ in settings.LANGUAGES:
19
            assert getattr(localized_value, lang_code) == input_data[lang_code]
20
            assert isinstance((getattr(localized_value, lang_code)), int) is True
21
            assert localized_value.get(lang_code) == input_data[lang_code]
22
            assert isinstance(localized_value.get(lang_code), int) is True
23
24
    @staticmethod
25
    def test_default_value():
26
        """Tests whether default language value is returned correctly"""
27
28
        input_data = get_init_integer_values()
29
        Model = get_fake_model(dict(
30
            score=LocalizedIntegerField(required=True)
31
        ))
32
33
        inst = Model()
34
        inst.score = dict(en=0, ro=1, nl = 2)
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
inst.score = dict(en=0, ro=1, nl = 2)
^
Loading history...
35
        inst.score = LocalizedIntegerField
36
        inst.save()
37
38
        inst = Model.objects.get(pk=inst.pk)
39
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
40
        settings.LANGUAGE_CODE = 'ro'
41
        assert int(inst.score) == input_data['ro']
42
        settings.LANGUAGE_CODE = 'en'
43