Passed
Push — master ( 69fc36...a0d1a5 )
by Swen
02:02
created

test_hstore_f_ref()   A

Complexity

Conditions 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 17
rs 9.4285
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
3
from psqlextra.fields import HStoreField
4
from psqlextra.expressions import HStoreRef
5
6
from .fake_model import get_fake_model
7
8
9 View Code Duplication
def test_annotate_hstore_key_ref():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
    """Tests whether annotating using a :see:HStoreRef expression
11
    works correctly.
12
13
    This allows you to select an individual hstore key."""
14
15
    model_fk = get_fake_model({
16
        'title': HStoreField(),
17
    })
18
19
    model = get_fake_model({
20
        'fk': models.ForeignKey(model_fk, on_delete=models.CASCADE)
21
    })
22
23
    fk = model_fk.objects.create(title={'en': 'english', 'ar': 'arabic'})
24
    model.objects.create(fk=fk)
25
26
    queryset = (
27
        model.objects
28
        .annotate(english_title=HStoreRef('fk__title', 'en'))
29
        .values('english_title')
30
        .first()
31
    )
32
33
    assert queryset['english_title'] == 'english'
34
35
36
def test_hstore_f_ref():
37
    model = get_fake_model({
38
        'name': models.CharField(max_length=255),
39
        'name_new': HStoreField()
40
    })
41
42
    model.objects.create(
43
        name='waqas',
44
        name_new=dict(en='swen')
45
    )
46
47
    model.objects.update(
48
        name_new=dict(en=models.F('name'))
49
    )
50
51
    inst = model.objects.all().first()
52
    assert inst.name_new.get('en') == 'waqas'
53