Test Failed
Push — master ( e5214b...06f7ee )
by Swen
02:16
created

LocalizedExpressionsTestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B test_localized_ref() 0 26 5
A setUpClass() 0 18 1
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.db import models
0 ignored issues
show
Configuration introduced by
The import django.db 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 django.utils import translation
0 ignored issues
show
Configuration introduced by
The import django.utils 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...
4
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...
5
6
from localized_fields.fields import LocalizedField
7
from localized_fields.value import LocalizedValue
8
from localized_fields.expressions import LocalizedRef
9
10
from .fake_model import get_fake_model
11
12
13
class LocalizedExpressionsTestCase(TestCase):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
14
    """Tests whether expressions properly work with :see:LocalizedField."""
15
16
    TestModel1 = None
17
    TestModel2 = None
18
19
    @classmethod
20
    def setUpClass(cls):
21
        """Creates the test model in the database."""
22
23
        super(LocalizedExpressionsTestCase, cls).setUpClass()
24
25
        cls.TestModel1 = get_fake_model(
26
            'LocalizedExpressionsTestCase2',
27
            {
28
                'name': models.CharField(null=False, blank=False, max_length=255),
29
            }
30
        )
31
32
        cls.TestModel2 = get_fake_model(
33
            'LocalizedExpressionsTestCase1',
34
            {
35
                'text': LocalizedField(),
36
                'other': models.ForeignKey(cls.TestModel1, related_name='features')
37
            }
38
        )
39
40
    @classmethod
41
    def test_localized_ref(cls):
42
        """Tests whether the :see:LocalizedRef expression properly works."""
43
44
        obj = cls.TestModel1.objects.create(name='bla bla')
45
        for i in range(0, 10):
46
            cls.TestModel2.objects.create(
47
                text=LocalizedValue(dict(en='text_%d_en' % i, ro='text_%d_ro' % i, nl='text_%d_nl' % i)),
48
                other=obj
49
            )
50
51
        for lang_code, _ in settings.LANGUAGES:
52
            translation.activate(lang_code)
53
54
            queryset = (
55
                cls.TestModel1.objects
56
                .annotate(
57
                    mytexts=LocalizedRef('features__text')
58
                )
59
                .values_list(
60
                    'mytexts', flat=True
61
                )
62
            )
63
64
            for index, value in enumerate(queryset):
65
                assert str(index) in value
66