Projet

Général

Profil

0001-jsondatastore-return-entries-alphabetically-sorted-3.patch

Frédéric Péters, 25 mars 2019 19:12

Télécharger (2,73 ko)

Voir les différences:

Subject: [PATCH] jsondatastore: return entries alphabetically sorted (#31711)

 .../migrations/0006_auto_20190325_1311.py     | 19 +++++++++++++++++++
 passerelle/apps/jsondatastore/models.py       |  3 +++
 tests/test_jsondatastore.py                   |  8 ++++++++
 3 files changed, 30 insertions(+)
 create mode 100644 passerelle/apps/jsondatastore/migrations/0006_auto_20190325_1311.py
passerelle/apps/jsondatastore/migrations/0006_auto_20190325_1311.py
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.12 on 2019-03-25 18:11
3
from __future__ import unicode_literals
4

  
5
from django.db import migrations
6

  
7

  
8
class Migration(migrations.Migration):
9

  
10
    dependencies = [
11
        ('jsondatastore', '0005_remove_jsondatastore_log_level'),
12
    ]
13

  
14
    operations = [
15
        migrations.AlterModelOptions(
16
            name='jsondata',
17
            options={'ordering': ['text']},
18
        ),
19
    ]
passerelle/apps/jsondatastore/models.py
43 43
    creation_datetime = models.DateTimeField(auto_now_add=True)
44 44
    last_update_datetime = models.DateTimeField(auto_now=True)
45 45

  
46
    class Meta:
47
        ordering = ['text']
48

  
46 49
    def save(self, *args, **kwargs):
47 50
        text_value_template = self.datastore.text_value_template
48 51
        if text_value_template:
tests/test_jsondatastore.py
112 112
    assert len(resp.json['data']) == 1
113 113
    assert resp.json['data'][0]['text'] == 'bar'
114 114

  
115
    # check entries are alphabetically sorted
116
    resp = app.post_json('/jsondatastore/foobar/data/create', params={'foo': 'aaa'})
117
    uuid = resp.json['id']
118
    resp = app.get('/jsondatastore/foobar/data/')
119
    assert len(resp.json['data']) == 2
120
    assert resp.json['data'][0]['text'] == 'aaa'
121
    assert resp.json['data'][1]['text'] == 'bar'
122

  
115 123
def test_jsondatastore_get_by_attribute(app, jsondatastore):
116 124
    resp = app.post_json('/jsondatastore/foobar/data/create', params={'foo': 'bar'})
117 125
    uuid = resp.json['id']
118
-