Passed
Push — master ( 1c2e01...05bcd8 )
by Swen
01:37 queued 14s
created

LocalizedFieldFormTestCase.test_init()   F

Complexity

Conditions 15

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 32
rs 2.7451
cc 15

How to fix   Complexity   

Complexity

Complex classes like LocalizedFieldFormTestCase.test_init() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
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...
2
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...
3
4
from localized_fields.forms import LocalizedFieldForm
5
6
7
class LocalizedFieldFormTestCase(TestCase):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
8
    """Tests the workings of the :see:LocalizedFieldForm class."""
9
10
    @staticmethod
11
    def test_init():
12
        """Tests whether the constructor correctly
13
        creates a field for every language."""
14
        # case required for specific language
15
        form = LocalizedFieldForm(required=[settings.LANGUAGE_CODE])
16
17
        for (lang_code, _), field in zip(settings.LANGUAGES, form.fields):
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named fields.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
18
            assert field.label == lang_code
19
20
            if lang_code == settings.LANGUAGE_CODE:
21
                assert field.required
22
            else:
23
                assert not field.required
24
25
        # case required for all languages
26
        form = LocalizedFieldForm(required=True)
27
        assert form.required
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named required.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
28
        for field in form.fields:
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named fields.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
29
            assert field.required
30
31
        # case optional filling
32
        form = LocalizedFieldForm(required=False)
33
        assert not form.required
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named required.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
34
        for field in form.fields:
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named fields.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
35
            assert not field.required
36
37
        # case required for any language
38
        form = LocalizedFieldForm(required=[])
39
        assert form.required
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named required.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
40
        for field in form.fields:
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFieldForm does not seem to have a member named fields.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
41
            assert not field.required
42
43
44
    @staticmethod
45
    def test_compress():
46
        """Tests whether the :see:compress function
47
        is working properly."""
48
49
        input_value = [lang_name for _, lang_name in settings.LANGUAGES]
50
        output_value = LocalizedFieldForm().compress(input_value)
51
52
        for lang_code, lang_name in settings.LANGUAGES:
53
            assert output_value.get(lang_code) == lang_name
54