web/test/unittest_views_xmlrss.py
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 29 Jun 2015 16:58:43 +0200
changeset 10463 9add9b7f9df7
parent 10245 7d21c6ac47a3
permissions -rw-r--r--
[server/test] fix random error in unittest_security When entering a new Connection, we cache the user and its 'login' attribute (with no permissions checking). This test makes 'CWUser.login' unreadable by guests, and then proceeds to make sure the 'anon' user can actually not read any 'login' attribute. However, due to the above cnx initialization, anon's login is actually cached, hence readable. This happens to make the test fail sometimes depending on the order in which CWUser entities are returned, because one of them has .complete() called, which as a side effect sets the attribute cache to None for unreadable attributes. Call .complete() on both entities to reset the login cache. While this is still highly debatable, at least it's consistent.

from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.web.views.xmlrss import SERIALIZERS

class EntityXMLViewTC(CubicWebTC):
    """see also cw.sobjects.test.unittest_parsers"""
    def test(self):
        rels = ['tags-object', 'in_group-subject',
                'in_state-subject', 'use_email-subject']
        with self.admin_access.web_request(relation=rels) as req:
            self.assertMultiLineEqual(
                req.user.view('xml'),
                '''\
<CWUser eid="6" cwuri="http://testing.fr/cubicweb/6" cwsource="system">
  <creation_date>%(cdate)s</creation_date>
  <firstname/>
  <last_login_time/>
  <login>admin</login>
  <modification_date>%(mdate)s</modification_date>
  <surname/>
  <upassword/>
  <tags role="object">
  </tags>
  <in_group role="subject">
    <CWGroup eid="%(group_eid)s" cwuri="http://testing.fr/cubicweb/%(group_eid)s"/>
  </in_group>
  <in_state role="subject">
    <State eid="%(state_eid)s" cwuri="http://testing.fr/cubicweb/%(state_eid)s" name="activated"/>
  </in_state>
  <use_email role="subject">
  </use_email>
</CWUser>
''' % {'cdate': SERIALIZERS['Datetime'](req.user.creation_date),
       'mdate': SERIALIZERS['Datetime'](req.user.modification_date),
       'state_eid': req.user.in_state[0].eid,
       'group_eid': req.user.in_group[0].eid})


if __name__ == '__main__':
    from logilab.common.testlib import unittest_main
    unittest_main()