Commit 963f37de authored by Aurelien Campeas's avatar Aurelien Campeas
Browse files

[test/web] fix invisibly bogus test (prepares #2755994)

The test was wrong but that was cancelled out by a cache effect and
fuzzy naming.

Wiping the entity caches restores sanity: the choices list are the
same before and after the SET.

Also field.choices uses entity.unrelated but always returns related +
unrelated elements.

Hence `choice` replaces `unrelated` where it makes sense.

AssertIn is used in place of AssertTrue.
parent bdc50659f648
......@@ -59,23 +59,26 @@ class EntityFieldsFormTC(CubicWebTC):
self.req = self.request()
self.entity = self.user(self.req)
def test_form_field_vocabulary_unrelated(self):
def test_form_field_choices(self):
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.assertTrue(unicode(b.eid) in unrelated, unrelated)
choices = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
self.assertIn(unicode(b.eid), choices)
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.assertTrue(unicode(t.eid) in unrelated, unrelated)
choices = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
self.assertIn(unicode(t.eid), choices)
b.cw_clear_all_caches()
t.cw_clear_all_caches()
self.execute('SET X tags Y WHERE X is Tag, Y is BlogEntry')
unrelated = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
self.assertFalse(unicode(b.eid) in unrelated, unrelated)
unrelated = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
self.assertFalse(unicode(t.eid) in unrelated, unrelated)
choices = [reid for rview, reid in form1.field_by_name('tags', 'subject', t.e_schema).choices(form1)]
self.assertIn(unicode(b.eid), choices)
choices = [reid for rview, reid in form2.field_by_name('tags', 'object', t.e_schema).choices(form2)]
self.assertIn(unicode(t.eid), choices)
def test_form_field_vocabulary_new_entity(self):
def test_form_field_choices_new_entity(self):
e = self.vreg['etypes'].etype_class('CWUser')(self.request())
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)]
......
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