Révision 40b65753
Ajouté par Serghei Mihai (congés, retour 15/05) il y a plus de 7 ans
tests/test_api.py | ||
---|---|---|
5 | 5 |
from django.core.urlresolvers import reverse |
6 | 6 |
from django.utils.http import urlencode |
7 | 7 |
from django.contrib.auth import get_user_model |
8 |
from django.utils.text import slugify |
|
8 | 9 |
|
9 | 10 |
from corbo.models import Category, Announce, Broadcast, Subscription |
10 | 11 |
from corbo.models import channel_choices |
11 | 12 |
|
12 | 13 |
pytestmark = pytest.mark.django_db |
13 | 14 |
|
14 |
CATEGORIES = ('Alerts', 'News')
|
|
15 |
CATEGORIES = (u'Alerts', u'News')
|
|
15 | 16 |
|
16 | 17 |
|
17 | 18 |
@pytest.fixture |
18 | 19 |
def categories(): |
19 | 20 |
categories = [] |
20 | 21 |
for category in CATEGORIES: |
21 |
c, created = Category.objects.get_or_create(name=category) |
|
22 |
c, created = Category.objects.get_or_create(name=category, slug=slugify(category))
|
|
22 | 23 |
categories.append(c) |
23 | 24 |
return categories |
24 | 25 |
|
... | ... | |
55 | 56 |
for category in data['data']: |
56 | 57 |
assert 'id' in category |
57 | 58 |
assert 'text' in category |
59 |
assert category['id'] in [slugify(c) for c in CATEGORIES] |
|
58 | 60 |
assert category['text'] in CATEGORIES |
59 | 61 |
assert 'transports' in category |
60 | 62 |
assert category['transports'] == [{'id': 'mailto', 'text': 'Email'}] |
... | ... | |
73 | 75 |
assert 'data' in resp.json |
74 | 76 |
data = resp.json['data'] |
75 | 77 |
for d in data: |
76 |
assert d['id'] in [str(category.id) for category in categories]
|
|
78 |
assert d['id'] in [category.slug for category in categories]
|
|
77 | 79 |
assert d['text'] in [category.name for category in categories] |
78 | 80 |
for t in d['transports']: |
79 | 81 |
assert t['id'] == identifier |
... | ... | |
114 | 116 |
|
115 | 117 |
|
116 | 118 |
def test_simple_subscription(app, categories, user): |
117 |
payload = {'category_id': 1}
|
|
119 |
payload = {'category_id': 'alerts'}
|
|
118 | 120 |
url = '/api/subscribe/?email=john@example.net' |
119 | 121 |
|
120 | 122 |
# anonymous |
... | ... | |
135 | 137 |
|
136 | 138 |
data = resp.json['data'] |
137 | 139 |
assert len(data) == 1 |
138 |
assert data[0]['id'] == '1'
|
|
140 |
assert data[0]['id'] == 'alerts'
|
|
139 | 141 |
assert data[0]['text'] == 'Alerts' |
140 | 142 |
assert len(data[0]['transports']) == 1 |
141 | 143 |
transport = data[0]['transports'][0] |
Formats disponibles : Unified diff
api: use categories slugs instead of ids (#13791)