Project

General

Profile

0001-api-include-category_slug-in-formdefs-API-10366.patch

Frédéric Péters, 22 March 2016 11:04 AM

Download (2.95 KB)

View differences:

Subject: [PATCH] api: include category_slug in formdefs API (#10366)

 help/fr/api-schema.page | 6 ++++--
 tests/test_api.py       | 6 ++++--
 wcs/api.py              | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)
help/fr/api-schema.page
45 45
  "redirection": false,
46 46
  "description": "",
47 47
  "keywords": [],
48
  "category": "Inscriptions"},
48
  "category": "Inscriptions",
49
  "category_slug": "inscriptions"},
49 50
 {"url": "https://www.example.net/inscriptions/piscine",
50 51
  "title": "Piscine",
51 52
  "slug": "piscine",
......
54 55
  "redirection": false,
55 56
  "description": "La piscine est ouverte du lundi au samedi.",
56 57
  "keywords": ["sport"],
57
  "category": "Inscriptions"}
58
  "category": "Inscriptions",
59
  "category_slug": "inscriptions"}
58 60
]
59 61
</output>
60 62
</screen>
tests/test_api.py
506 506
    FormDef.wipe()
507 507
    Category.wipe()
508 508
    category = Category()
509
    category.name = 'category'
509
    category.name = 'Category'
510 510
    category.description = 'hello world'
511 511
    category.store()
512 512

  
......
532 532
    resp = get_app(pub).get('/api/categories/')
533 533
    resp2 = get_app(pub).get('/categories', headers={'Accept': 'application/json'})
534 534
    assert resp.json == resp2.json
535
    assert resp.json['data'][0]['title'] == 'category'
535
    assert resp.json['data'][0]['title'] == 'Category'
536 536
    assert resp.json['data'][0]['url'] == 'http://example.net/category/'
537 537
    assert resp.json['data'][0]['description'] == 'hello world'
538 538
    assert set(resp.json['data'][0]['keywords']) == set(['foobar', 'mobile', 'test'])
......
556 556
    assert resp.json[0]['url'] == 'http://example.net/test/'
557 557
    assert resp.json[0]['count'] == 0
558 558
    assert resp.json[0]['redirection'] == False
559
    assert resp.json[0]['category'] == 'Category'
560
    assert resp.json[0]['category_slug'] == 'category'
559 561

  
560 562
def test_categories_full(pub):
561 563
    test_categories(pub)
wcs/api.py
342 342

  
343 343
            if formdef.category:
344 344
                formdict['category'] = unicode(formdef.category.name, charset)
345
                formdict['category_slug'] = unicode(formdef.category.url_name, charset)
345 346
                formdict['category_position'] = (formdef.category.position or 0)
346 347
            else:
347 348
                formdict['category_position'] = sys.maxint
348
-