Passed
Pull Request — master (#34)
by Swen
02:27 queued 01:02
created

LocalizedFileWidgetTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 83.33 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 15
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_get_context() 15 15 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
3
from localized_fields.value import LocalizedFileValue
4
from localized_fields.widgets import LocalizedFileWidget
5
6
7
class LocalizedFileWidgetTestCase(TestCase):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
8
    """Tests the workings of the :see:LocalizedFiledWidget class."""
9
10 View Code Duplication
    @staticmethod
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    def test_get_context():
12
        """Tests whether the :see:get_context correctly
13
        handles 'required' attribute, separately for each subwidget."""
14
15
        widget = LocalizedFileWidget()
16
        widget.widgets[0].is_required = True
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFileWidget does not seem to have a member named widgets.

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...
17
        widget.widgets[1].is_required = True
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFileWidget does not seem to have a member named widgets.

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
        widget.widgets[2].is_required = False
0 ignored issues
show
Bug introduced by
The Instance of LocalizedFileWidget does not seem to have a member named widgets.

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...
19
        context = widget.get_context(name='test',
20
                                     value=LocalizedFileValue(dict(en='test')),
21
                                     attrs=dict(required=True))
22
        assert 'required' not in context['widget']['subwidgets'][0]['attrs']
23
        assert context['widget']['subwidgets'][1]['attrs']['required']
24
        assert 'required' not in context['widget']['subwidgets'][2]['attrs']
25