tests: add testing of WcsFormsOfCategoryCell

This commit is contained in:
Frédéric Péters 2015-04-03 17:27:45 +02:00
parent de5a91eef9
commit 098b2bd197
1 changed files with 51 additions and 2 deletions

View File

@ -10,7 +10,8 @@ from django.conf import settings
from django.template import Context
from combo.data.models import Page
from combo.apps.wcs.models import WcsFormCell, WcsCurrentFormsCell
from combo.apps.wcs.models import (WcsFormCell, WcsCurrentFormsCell,
WcsFormsOfCategoryCell)
pytestmark = pytest.mark.django_db
@ -41,11 +42,13 @@ from wcs.categories import Category
from wcs.formdef import FormDef
from wcs import fields
cats = []
for i in range(1, 10):
cat = Category()
cat.name = 'Test %d' % i
cat.description = 'Hello world'
cat.store()
cats.append(cat)
formdef = FormDef()
formdef.name = 'form title'
@ -81,6 +84,19 @@ for i in range(50):
formdata.user_id = user.id
formdata.store()
# another formdef in same category
formdef = FormDef()
formdef.name = 'a second form title'
formdef.category_id = cat.id
formdef.fields = []
formdef.store()
# a formdef in another category
formdef = FormDef()
formdef.name = 'third form title'
formdef.category_id = cats[2].id
formdef.fields = []
formdef.store()
""",
}
@ -134,8 +150,12 @@ def test_form_cell_setup():
form_class = cell.get_default_form_class()
form = form_class()
assert form.fields['formdef_reference'].widget.choices == [
(u'default:a-second-form-title', u'test : a second form title'),
(u'default:form-title', u'test : form title'),
(u'other:form-title', u'test2 : form title')]
(u'default:third-form-title', u'test : third form title'),
(u'other:a-second-form-title', u'test2 : a second form title'),
(u'other:form-title', u'test2 : form title'),
(u'other:third-form-title', u'test2 : third form title')]
@wcsctl_present
def test_form_cell_save_cache():
@ -206,3 +226,32 @@ def test_current_forms_cell_render():
assert 'http://127.0.0.1:8999/form-title/22/' in result
assert 'http://127.0.0.2:8999/form-title/1/' not in result
assert 'http://127.0.0.2:8999/form-title/22/' not in result
@wcsctl_present
def test_forms_of_category_cell_setup():
cell = WcsFormsOfCategoryCell()
form_class = cell.get_default_form_class()
form = form_class()
assert form.fields['category_reference'].widget.choices == [
(u'default:test-3', u'test : Test 3'),
(u'default:test-9', u'test : Test 9'),
(u'other:test-3', u'test2 : Test 3'),
(u'other:test-9', u'test2 : Test 9')]
@wcsctl_present
def test_forms_of_category_cell_render():
page = Page(title='xxx', slug='test_forms_of_category_cell_render', template_name='standard')
page.save()
cell = WcsFormsOfCategoryCell(page=page, placeholder='content', order=0)
cell.category_reference = 'default:test-9'
cell.ordering = 'alpha'
cell.save()
result = cell.render(Context())
assert 'form title' in result and 'a second form title' in result
assert result.index('form title') > result.index('a second form title')
cell.ordering = 'popularity'
cell.save()
result = cell.render(Context())
assert 'form title' in result and 'a second form title' in result
assert result.index('form title') < result.index('a second form title')