Projet

Général

Profil

0002-export-workflow-in-formdef-json-exports-fixes-9849.patch

Benjamin Dauvergne, 29 avril 2016 15:51

Télécharger (4,65 ko)

Voir les différences:

Subject: [PATCH 2/2] export workflow in formdef json exports (fixes #9849)

 help/fr/api-schema.page | 21 ++++++++++++++++++++-
 tests/test_api.py       | 23 +++++++++++++++++++++++
 wcs/formdef.py          | 13 ++++++++++---
 3 files changed, 53 insertions(+), 4 deletions(-)
help/fr/api-schema.page
181 181
            "type": "email",
182 182
            "varname": "email"
183 183
        }
184
    ]
184
    ],
185
    "workflow": {
186
        "name": "Workflow Newsletter",
187
        "id": "1",
188
        "last_modification_time": "2015-12-12T10:20:45",
189
        "statuses": {
190
            "1": {
191
                "name": "Nouveau",
192
                "forced_endpoint": false
193
            },
194
            "2": {
195
                "name": "En cours",
196
                "forced_endpoint": false
197
            },
198
            "3": {
199
                "name": "Terminé",
200
                "forced_endpoint": false
201
            }
202
        }
203
    }
185 204
}
186 205
</code>
187 206

  
tests/test_api.py
8 8
import urlparse
9 9
import datetime
10 10
import time
11
import json
11 12

  
12 13
from quixote import cleanup, get_publisher
13 14
from wcs.qommon.http_request import HTTPRequest
......
333 334
    assert resp1.json[0]['count'] == 0
334 335
    assert resp1.json[0]['redirection'] == True
335 336

  
337

  
336 338
def test_formdef_schema(pub):
339
    Workflow.wipe()
340
    workflow = Workflow(name='test')
341
    workflow.add_status('Status1', 'st1')
342
    workflow.add_status('Status2', 'st2')
343
    workflow.store()
337 344
    FormDef.wipe()
338 345
    formdef = FormDef()
339 346
    formdef.name = 'test'
340 347
    formdef.fields = [fields.StringField(id='0', label='foobar')]
348
    formdef.workflow_id = workflow.id
341 349
    formdef.store()
342 350

  
343 351
    resp = get_app(pub).get('/api/formdefs/test/schema')
344 352
    resp2 = get_app(pub).get('/test/schema')
353

  
354
    # check schema
345 355
    assert resp.json == resp2.json
356
    assert set(resp.json.keys()) >= set(['enable_tracking_codes', 'url_name', 'description',
357
                                         'workflow', 'expiration_date', 'discussion',
358
                                         'last_modification_time', 'has_captcha',
359
                                         'always_advertise', 'name', 'disabled', 'only_allow_one',
360
                                         'private_status_and_history', 'fields', 'keywords',
361
                                         'publication_date', 'detailed_emails',
362
                                         'disabled_redirection'])
346 363
    assert resp.json['name'] == 'test'
364

  
365
    # fields checks
347 366
    assert resp.json['fields'][0]['label'] == 'foobar'
348 367
    assert resp.json['fields'][0]['type'] == 'string'
349 368

  
369
    # workflow checks
370
    assert len(resp.json['workflow']['statuses']) == 2
371

  
372

  
350 373
def test_formdef_submit(pub, local_user):
351 374
    Role.wipe()
352 375
    role = Role(name='test')
wcs/formdef.py
523 523
            root['category'] = unicode(self.category.name, charset)
524 524
            root['category_id'] = str(self.category.id)
525 525
        if self.workflow:
526
            root['workflow'] = unicode(self.workflow.name, charset)
527
            root['workflow_id'] = str(self.workflow.id)
526
            root['workflow'] = self.workflow.get_json_export_dict(include_id=include_id)
528 527

  
529 528
        if self.max_field_id is None and self.fields:
530 529
            self.max_field_id = max([lax_int(x.id) for x in self.fields])
......
588 587

  
589 588
        if include_id and 'workflow_id' in value:
590 589
            formdef.workflow_id = value.get('workflow_id')
590
        elif (include_id
591
              and 'workflow' in value
592
              and isinstance(value['workflow'], dict)
593
              and 'id' in value['workflow']):
594
            formdef.workflow_id = value['workflow'].get('id')
591 595
        elif 'workflow' in value:
592
            workflow = value.get('workflow')
596
            if isinstance(value['workflow'], basestring):
597
                workflow = value.get('workflow')
598
            else:
599
                workflow = value['workflow'].get('name')
593 600
            from wcs.workflows import Workflow
594 601
            for w in Workflow.select():
595 602
                if w.name == workflow:
596
-