Test Failed
Push — master ( 6736b3...c75c17 )
by Swen
01:56
created

LocalizedBulkTestCase.test_localized_bulk_insert()   B

Complexity

Conditions 6

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 6
c 4
b 0
f 0
dl 0
loc 33
rs 7.5384
1
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...
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.fields import LocalizedField, LocalizedUniqueSlugField
5
6
from .fake_model import get_fake_model
7
8
9
class LocalizedBulkTestCase(TestCase):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
10
    """Tests bulk operations with data structures provided
11
    by the django-localized-fields library."""
12
13
    @staticmethod
14
    def test_localized_bulk_insert():
15
        """Tests whether bulk inserts work properly when using
16
        a :see:LocalizedUniqueSlugField in the model."""
17
18
        model = get_fake_model(
19
            'BulkSlugInsertModel',
20
            {
21
                'name': LocalizedField(),
22
                'slug': LocalizedUniqueSlugField(populate_from='name', include_time=True),
23
                'score': models.IntegerField()
24
            }
25
        )
26
27
        to_create = [
28
            model(name={'en': 'english name 1', 'ro': 'romanian name 1'}, score=1),
29
            model(name={'en': 'english name 2', 'ro': 'romanian name 2'}, score=2),
30
            model(name={'en': 'english name 3', 'ro': 'romanian name 3'}, score=3)
31
        ]
32
33
        model.objects.bulk_create(to_create)
34
        assert model.objects.all().count() == 3
35
36
        for obj in to_create:
37
            obj_db = model.objects.filter(
38
                name__en=obj.name.en,
39
                name__ro=obj.name.ro,
40
                score=obj.score
41
            ).first()
42
43
            assert obj_db
44
            assert len(obj_db.slug.en) >= len(obj_db.name.en)
45
            assert len(obj_db.slug.ro) >= len(obj_db.name.ro)
46