Commit 1f994d8a authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

all web tests OK

parent f1b9f0ed1253
......@@ -169,11 +169,11 @@ class ApplicationTC(CubicWebTC):
def test_publish_validation_error(self):
req = self.request()
user = self.user()
eid = unicode(user.eid)
req.form = {
'eid': `user.eid`,
'__type:'+`user.eid`: 'CWUser',
'login:'+`user.eid`: '', # ERROR: no login specified
'edits-login:'+`user.eid`: unicode(user.login),
'eid': eid,
'__type:'+eid: 'CWUser', '_cw_edited_fields:'+eid: 'login-subject',
'login-subject:'+eid: '', # ERROR: no login specified
# just a sample, missing some necessary information for real life
'__errorurl': 'view?vid=edition...'
}
......@@ -182,9 +182,8 @@ class ApplicationTC(CubicWebTC):
eidmap = forminfo['eidmap']
self.assertEquals(eidmap, {})
values = forminfo['values']
self.assertEquals(values['login:'+`user.eid`], '')
self.assertEquals(values['edits-login:'+`user.eid`], user.login)
self.assertEquals(values['eid'], `user.eid`)
self.assertEquals(values['login-subject:'+eid], '')
self.assertEquals(values['eid'], eid)
errors = forminfo['errors']
self.assertEquals(errors.entity, user.eid)
self.assertEquals(errors.errors['login'], 'required attribute')
......@@ -194,16 +193,16 @@ class ApplicationTC(CubicWebTC):
"""test creation of two linked entities
"""
req = self.request()
form = {'eid': ['X', 'Y'],
'__type:X': 'CWUser',
form = {'eid': ['X', 'Y'], '__maineid': 'X',
'__type:X': 'CWUser', '_cw_edited_fields:X': 'login-subject,surname-subject',
# missing required field
'login:X': u'', 'edits-login:X': '',
'surname:X': u'Mr Ouaoua', 'edits-surname:X': '',
'__type:Y': 'EmailAddress',
'login-subject:X': u'',
'surname-subject:X': u'Mr Ouaoua',
# but email address is set
'address:Y': u'bougloup@logilab.fr', 'edits-address:Y': '',
'alias:Y': u'', 'edits-alias:Y': '',
'use_email:X': 'Y', 'edits-use_email:X': INTERNAL_FIELD_VALUE,
'__type:Y': 'EmailAddress', '_cw_edited_fields:Y': 'address-subject,alias-subject,use_email-object',
'address-subject:Y': u'bougloup@logilab.fr',
'alias-subject:Y': u'',
'use_email-object:Y': 'X',
# necessary to get validation error handling
'__errorurl': 'view?vid=edition...',
}
......@@ -212,7 +211,7 @@ class ApplicationTC(CubicWebTC):
req.edited_eids = lambda : ('Y', 'X')
path, params = self.expect_redirect(lambda x: self.app_publish(x, 'edit'), req)
forminfo = req.get_session_data('view?vid=edition...')
self.assertUnorderedIterableEquals(forminfo['eidmap'].keys(), ['X', 'Y'])
self.assertEquals(set(forminfo['eidmap']), set('XY'))
self.assertEquals(forminfo['errors'].entity, forminfo['eidmap']['X'])
self.assertEquals(forminfo['errors'].errors, {'login': 'required attribute',
'upassword': 'required attribute'})
......
......@@ -3,8 +3,9 @@ from cubicweb.devtools.testlib import CubicWebTC
class BreadCrumbsTC(CubicWebTC):
def test_base(self):
f1 = self.add_entity('Folder', name=u'par&ent')
f2 = self.add_entity('Folder', name=u'chi&ld')
req = self.request()
f1 = req.create_entity('Folder', name=u'par&ent')
f2 = req.create_entity('Folder', name=u'chi&ld')
self.execute('SET F2 filed_under F1 WHERE F1 eid %(f1)s, F2 eid %(f2)s',
{'f1' : f1.eid, 'f2' : f2.eid})
self.commit()
......@@ -15,3 +16,7 @@ class BreadCrumbsTC(CubicWebTC):
self.assertEquals(ibc.render(),
"""<span id="breadcrumbs" class="pathbar">&#160;&gt;&#160;<a href="http://testing.fr/cubicweb/Folder">folder_plural</a>&#160;&gt;&#160;<a href="http://testing.fr/cubicweb/folder/%s" title="">par&amp;ent</a>&#160;&gt;&#160;
chi&amp;ld</span>""" % f1.eid)
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()
......@@ -15,7 +15,7 @@ from logilab.common.compat import any
from cubicweb import Binary
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.web.formfields import (IntField, StringField, RichTextField,
DateTimeField, DateTimePicker,
PasswordField, DateTimeField, DateTimePicker,
FileField, EditableFileField)
from cubicweb.web.formwidgets import PasswordInput, Input
from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm
......@@ -27,10 +27,10 @@ class FieldsFormTC(CubicWebTC):
def test_form_field_format(self):
form = FieldsForm(self.request(), None)
self.assertEquals(form.form_field_format(None), 'text/html')
self.assertEquals(StringField().format(form), 'text/html')
self.execute('INSERT CWProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"')
self.commit()
self.assertEquals(form.form_field_format(None), 'text/rest')
self.assertEquals(StringField().format(form), 'text/rest')
class EntityFieldsFormTC(CubicWebTC):
......@@ -41,42 +41,28 @@ class EntityFieldsFormTC(CubicWebTC):
self.entity = self.user(self.req)
def test_form_field_vocabulary_unrelated(self):
b = self.add_entity('BlogEntry', title=u'di mascii code', content=u'a best-seller')
t = self.add_entity('Tag', name=u'x')
form1 = EntityFieldsForm(self.request(), None, entity=t)
unrelated = [reid for rview, reid in form1.subject_relation_vocabulary('tags')]
b = self.req.create_entity('BlogEntry', title=u'di mascii code', content=u'a best-seller')
t = self.req.create_entity('Tag', name=u'x')
form1 = self.vreg['forms'].select('edition', self.req, entity=t)
unrelated = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
self.failUnless(b.eid in unrelated, unrelated)
form2 = EntityFieldsForm(self.request(), None, entity=b)
unrelated = [reid for rview, reid in form2.object_relation_vocabulary('tags')]
form2 = self.vreg['forms'].select('edition', self.req, entity=b)
unrelated = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
self.failUnless(t.eid in unrelated, unrelated)
self.execute('SET X tags Y WHERE X is Tag, Y is BlogEntry')
unrelated = [reid for rview, reid in form1.subject_relation_vocabulary('tags')]
unrelated = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
self.failIf(b.eid in unrelated, unrelated)
unrelated = [reid for rview, reid in form2.object_relation_vocabulary('tags')]
unrelated = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
self.failIf(t.eid in unrelated, unrelated)
def test_form_field_vocabulary_new_entity(self):
e = self.vreg['etypes'].etype_class('CWUser')(self.request())
form = EntityFieldsForm(e.req, None, entity=e)
unrelated = [rview for rview, reid in form.subject_relation_vocabulary('in_group')]
form = self.vreg['forms'].select('edition', self.req, entity=e)
unrelated = [rview for rview, reid in form.field_by_name('in_group', 'subject').choices(form)]
# should be default groups but owners, i.e. managers, users, guests
self.assertEquals(unrelated, [u'guests', u'managers', u'users'])
# def test_subject_in_state_vocabulary(self):
# # on a new entity
# e = self.etype_instance('CWUser')
# form = EntityFieldsForm(self.request(), None, entity=e)
# states = list(form.subject_in_state_vocabulary('in_state'))
# self.assertEquals(len(states), 1)
# self.assertEquals(states[0][0], u'activated') # list of (combobox view, state eid)
# # on an existant entity
# e = self.user()
# form = EntityFieldsForm(self.request(), None, entity=e)
# states = list(form.subject_in_state_vocabulary('in_state'))
# self.assertEquals(len(states), 1)
# self.assertEquals(states[0][0], u'deactivated') # list of (combobox view, state eid)
def test_consider_req_form_params(self):
e = self.vreg['etypes'].etype_class('CWUser')(self.request())
e.eid = 'A'
......@@ -84,20 +70,20 @@ class EntityFieldsFormTC(CubicWebTC):
field = StringField(name='login', eidparam=True)
form.append_field(field)
form.build_context({})
self.assertEquals(form.form_field_display_value(field, {}), 'toto')
self.assertEquals(field.display_value(form), 'toto')
def test_linkto_field_duplication(self):
e = self.vreg['etypes'].etype_class('CWUser')(self.request())
e.eid = 'A'
e.req = self.req
e._cw = self.req
geid = self.execute('CWGroup X WHERE X name "users"')[0][0]
self.req.form['__linkto'] = 'in_group:%s:subject' % geid
form = self.vreg['forms'].select('edition', self.req, entity=e)
form.content_type = 'text/html'
pageinfo = self._check_html(form.render(), form, template=None)
inputs = pageinfo.find_tag('select', False)
self.failUnless(any(attrs for t, attrs in inputs if attrs.get('name') == 'in_group:A'))
self.failUnless(any(attrs for t, attrs in inputs if attrs.get('name') == 'in_group-subject:A'))
inputs = pageinfo.find_tag('input', False)
self.failIf(any(attrs for t, attrs in inputs if attrs.get('name') == '__linkto'))
......@@ -106,8 +92,7 @@ class EntityFieldsFormTC(CubicWebTC):
form = self.vreg['views'].select('doreledit', self.request(),
rset=rset, row=0, rtype='content')
data = form.render(row=0, rtype='content')
self.failUnless('edits-content' in data)
self.failUnless('edits-content_format' in data)
self.failUnless('content_format' in data)
# form view tests #########################################################
......@@ -140,98 +125,102 @@ class EntityFieldsFormTC(CubicWebTC):
def _render_entity_field(self, name, form):
form.build_context({})
renderer = FormRenderer(self.req)
return form.field_by_name(name).render(form, renderer)
return form.field_by_name(name, 'subject').render(form, renderer)
def _test_richtextfield(self, expected):
class RTFForm(EntityFieldsForm):
description = RichTextField()
description = RichTextField(eidparam=True, role='subject')
state = self.execute('State X WHERE X name "activated", X state_of WF, WF workflow_of ET, ET name "CWUser"').get_entity(0, 0)
form = RTFForm(self.req, redirect_path='perdu.com', entity=state)
# make it think it can use fck editor anyway
form.form_field_format = lambda x: 'text/html'
form.field_by_name('description', 'subject').format = lambda x: 'text/html'
self.assertTextEquals(self._render_entity_field('description', form),
expected % {'eid': state.eid})
def test_richtextfield_1(self):
self.req.use_fckeditor = lambda: False
self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="1">
self._test_richtextfield('''<select id="description_format-subject:%(eid)s" name="description_format-subject:%(eid)s" size="1" style="display: block" tabindex="1">
<option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
<option value="text/html">text/html</option>
<option selected="selected" value="text/html">text/html</option>
<option value="text/plain">text/plain</option>
<option selected="selected" value="text/rest">text/rest</option>
</select><textarea cols="80" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="2"></textarea>''')
<option value="text/rest">text/rest</option>
</select><textarea cols="80" id="description-subject:%(eid)s" name="description-subject:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="2"></textarea>''')
def test_richtextfield_2(self):
self.req.use_fckeditor = lambda: True
self._test_richtextfield('<input name="description_format:%(eid)s" type="hidden" value="text/rest" /><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="1"></textarea>')
self._test_richtextfield('<input name="description_format-subject:%(eid)s" type="hidden" value="text/html" /><textarea cols="80" cubicweb:type="wysiwyg" id="description-subject:%(eid)s" name="description-subject:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="1"></textarea>')
def test_filefield(self):
class FFForm(EntityFieldsForm):
data = FileField(format_field=StringField(name='data_format', max_length=50),
encoding_field=StringField(name='data_encoding', max_length=20))
file = self.add_entity('File', data_name=u"pouet.txt", data_encoding=u'UTF-8',
data = FileField(
format_field=StringField(name='data_format', max_length=50,
eidparam=True, role='subject'),
encoding_field=StringField(name='data_encoding', max_length=20,
eidparam=True, role='subject'),
eidparam=True, role='subject')
file = self.req.create_entity('File', data_name=u"pouet.txt", data_encoding=u'UTF-8',
data=Binary('new widgets system'))
form = FFForm(self.req, redirect_path='perdu.com', entity=file)
self.assertTextEquals(self._render_entity_field('data', form),
'''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" />
<a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
<div id="data:%(eid)s-advanced" class="hidden">
<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
'''<input id="data-subject:%(eid)s" name="data-subject:%(eid)s" tabindex="1" type="file" value="" />
<a href="javascript: toggleVisibility(&#39;data-subject:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
<div id="data-subject:%(eid)s-advanced" class="hidden">
<label for="data_format-subject:%(eid)s">data_format</label><input id="data_format-subject:%(eid)s" maxlength="50" name="data_format-subject:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
<label for="data_encoding-subject:%(eid)s">data_encoding</label><input id="data_encoding-subject:%(eid)s" maxlength="20" name="data_encoding-subject:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
</div>
<br/>
<input name="data:%(eid)s__detach" type="checkbox" />
<input name="data-subject__detach:%(eid)s" type="checkbox" />
detach attached file
''' % {'eid': file.eid})
def test_editablefilefield(self):
class EFFForm(EntityFieldsForm):
data = EditableFileField(format_field=StringField(name='data_format', max_length=50),
encoding_field=StringField(name='data_encoding', max_length=20))
def form_field_encoding(self, field):
return 'ascii'
def form_field_format(self, field):
return 'text/plain'
file = self.add_entity('File', data_name=u"pouet.txt", data_encoding=u'UTF-8',
data = EditableFileField(
format_field=StringField('data_format', max_length=50,
eidparam=True, role='subject'),
encoding_field=StringField('data_encoding', max_length=20,
eidparam=True, role='subject'),
eidparam=True, role='subject')
file = self.req.create_entity('File', data_name=u"pouet.txt", data_encoding=u'UTF-8',
data=Binary('new widgets system'))
form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
self.assertTextEquals(self._render_entity_field('data', form),
'''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" />
<a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
<div id="data:%(eid)s-advanced" class="hidden">
<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
'''<input id="data-subject:%(eid)s" name="data-subject:%(eid)s" tabindex="1" type="file" value="" />
<a href="javascript: toggleVisibility(&#39;data-subject:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
<div id="data-subject:%(eid)s-advanced" class="hidden">
<label for="data_format-subject:%(eid)s">data_format</label><input id="data_format-subject:%(eid)s" maxlength="50" name="data_format-subject:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
<label for="data_encoding-subject:%(eid)s">data_encoding</label><input id="data_encoding-subject:%(eid)s" maxlength="20" name="data_encoding-subject:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
</div>
<br/>
<input name="data:%(eid)s__detach" type="checkbox" />
<input name="data-subject__detach:%(eid)s" type="checkbox" />
detach attached file
<p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
<textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="4">new widgets system</textarea>''' % {'eid': file.eid})
<textarea cols="80" name="data-subject:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="4">new widgets system</textarea>''' % {'eid': file.eid})
def test_passwordfield(self):
class PFForm(EntityFieldsForm):
upassword = StringField(widget=PasswordInput)
upassword = PasswordField(eidparam=True, role='subject')
form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
self.assertTextEquals(self._render_entity_field('upassword', form),
'''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
'''<input id="upassword-subject:%(eid)s" name="upassword-subject:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
<br/>
<input name="upassword-confirm:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
<input name="upassword-subject-confirm:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
&#160;
<span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
def test_datefield(self):
class DFForm(EntityFieldsForm):
creation_date = DateTimeField(widget=Input)
form = DFForm(self.req, entity=self.entity)
init, cur = (fromstring(self._render_entity_field(attr, form)).get('value')
for attr in ('edits-creation_date', 'creation_date'))
self.assertEquals(init, cur)
# def test_datefield(self):
# class DFForm(EntityFieldsForm):
# creation_date = DateTimeField(widget=Input)
# form = DFForm(self.req, entity=self.entity)
# init, cur = (fromstring(self._render_entity_field(attr, form)).get('value')
# for attr in ('edits-creation_date', 'creation_date'))
# self.assertEquals(init, cur)
if __name__ == '__main__':
unittest_main()
......@@ -46,7 +46,6 @@ class GuessFieldTC(TestCase):
description_format_field = guess_field(schema['State'], schema['description_format'], skip_meta_attr=False)
self.assertEquals(description_format_field.internationalizable, True)
self.assertEquals(description_format_field.sort, True)
self.assertEquals(description_format_field.initial(None), 'text/rest')
# wikiid_field = guess_field(schema['State'], schema['wikiid'])
# self.assertIsInstance(wikiid_field, StringField)
......@@ -92,9 +91,10 @@ class GuessFieldTC(TestCase):
def test_constraints_priority(self):
salesterm_field = guess_field(schema['Salesterm'], schema['reason'])
constraints = schema['reason'].rproperty('Salesterm', 'String', 'constraints')
constraints = schema['reason'].rdef('Salesterm', 'String').constraints
self.assertEquals([c.__class__ for c in constraints],
[SizeConstraint, StaticVocabularyConstraint])
self.assertIsInstance(salesterm_field, StringField)
self.assertIsInstance(salesterm_field.widget, Select)
......@@ -102,7 +102,6 @@ class GuessFieldTC(TestCase):
field = guess_field(schema['CWAttribute'], schema['indexed'])
self.assertIsInstance(field, BooleanField)
self.assertEquals(field.required, False)
self.assertEquals(field.initial(None), None)
self.assertIsInstance(field.widget, Radio)
self.assertEquals(field.vocabulary(mock(_cw=mock(_=unicode))),
[(u'yes', '1'), (u'no', '')])
......@@ -126,10 +125,10 @@ class MoreFieldsTC(CubicWebTC):
self.assertEquals(description_format_field.internationalizable, True)
self.assertEquals(description_format_field.sort, True)
# unlike below, initial is bound to form.form_field_format
self.assertEquals(description_format_field.initial(form), 'text/html')
self.assertEquals(description_format_field.value(form), 'text/html')
self.execute('INSERT CWProperty X: X pkey "ui.default-text-format", X value "text/rest", X for_user U WHERE U login "admin"')
self.commit()
self.assertEquals(description_format_field.initial(form), 'text/rest')
self.assertEquals(description_format_field.value(form), 'text/rest')
class UtilsTC(TestCase):
......
......@@ -23,8 +23,9 @@ class URLPublisherTC(CubicWebTC):
def setup_database(self):
self.create_user(u'ÿsaÿe')
b = self.add_entity('BlogEntry', title=u'hell\'o', content=u'blabla')
c = self.add_entity('Tag', name=u'yo') # take care: Tag's name normalized to lower case
req = self.request()
b = req.create_entity('BlogEntry', title=u'hell\'o', content=u'blabla')
c = req.create_entity('Tag', name=u'yo') # take care: Tag's name normalized to lower case
self.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s', {'c':c.eid, 'b':b.eid}, 'b')
def process(self, url):
......
This diff is collapsed.
......@@ -25,7 +25,7 @@ class AutomaticEntityFormTC(CubicWebTC):
{'widget': AutoCompletionWidget(autocomplete_initfunc='get_logins')})
form = self.vreg['forms'].select('edition', self.request(),
entity=self.user())
field = form.field_by_name('login')
field = form.field_by_name('login', 'subject')
self.assertIsInstance(field.widget, AutoCompletionWidget)
AFFK.del_rtag('CWUser', 'login', '*', 'subject')
......
......@@ -422,7 +422,8 @@ class VRegistryTC(ViewSelectorTC):
req = self.request()
rset = req.execute(rql)
try:
self.vreg['views'].render(vid, req, rset=rset, **args)
obj = self['views'].select(vid, req, rset=rset, **args)
return obj.render(**args)
except:
print vid, rset, args
raise
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment