1
|
import pytest
|
2
|
import json
|
3
|
|
4
|
|
5
|
from django.core.urlresolvers import reverse
|
6
|
|
7
|
from corbo.models import Category, Announce, Broadcast
|
8
|
|
9
|
pytestmark = pytest.mark.django_db
|
10
|
|
11
|
CATEGORIES = ('Alerts', 'News')
|
12
|
|
13
|
|
14
|
@pytest.fixture
|
15
|
def categories():
|
16
|
categories = []
|
17
|
for category in CATEGORIES:
|
18
|
c, created = Category.objects.get_or_create(name=category)
|
19
|
categories.append(c)
|
20
|
return categories
|
21
|
|
22
|
@pytest.fixture
|
23
|
def announces():
|
24
|
announces = []
|
25
|
for category in Category.objects.all():
|
26
|
a = Announce.objects.create(category=category, title='By email')
|
27
|
Broadcast.objects.create(announce=a, channel='mailto')
|
28
|
announces.append(a)
|
29
|
a = Announce.objects.create(category=category, title='On homepage')
|
30
|
Broadcast.objects.create(announce=a, channel='homepage')
|
31
|
announces.append(a)
|
32
|
return announces
|
33
|
|
34
|
|
35
|
def test_get_newsletters(app, categories, announces):
|
36
|
resp = app.get(reverse('newsletters'), status=200)
|
37
|
data = resp.json
|
38
|
assert data['data']
|
39
|
for category in data['data']:
|
40
|
assert 'id' in category
|
41
|
assert 'text' in category
|
42
|
assert category['text'] in CATEGORIES
|
43
|
assert 'transports' in category
|
44
|
assert category['transports'] == [{'id': 'mailto', 'text': 'Email'},
|
45
|
{'id': 'homepage', 'text': 'Homepage'}
|
46
|
]
|