web/test/unittest_views_xmlrss.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Jun 2011 18:53:38 +0200
changeset 7553 935423529f45
child 7554 fdace9d67d96
permissions -rw-r--r--
[datafeed cw parser] refactor: split logic that was in the parser into: * an "item builder" component, turning an etree xml node into a specific python dictionnary representing an entity * "action" components, selected given an entity, a relation and its role in the relation, and responsible to link the entity to given related items (eg dictionnary) This changes make it easy to add new action or to override existing one's behaviour according to the entity, the relation, etc... Also refactor the xml view so one can also override what's included in the tag used to mark the entity as used by a relation, hopefully allowing to reduce the number of http requests needed for a full datafeed import.

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):
        req = self.request(relation=['tags-object', 'in_group-subject',
                                     'in_state-subject', 'use_email-subject'])
        self.assertMultiLineEqual(
            req.user.view('xml'),
            '''\
<CWUser eid="6" cwuri="None6" cwsource="system">
  <login>admin</login>
  <upassword/>
  <firstname/>
  <surname/>
  <last_login_time/>
  <creation_date>%(date)s</creation_date>
  <modification_date>%(date)s</modification_date>
  <tags role="object">
  </tags>
  <in_group role="subject">
    <CWGroup eid="%(group_eid)s" cwuri="None%(group_eid)s"/>
  </in_group>
  <in_state role="subject">
    <State eid="%(state_eid)s" cwuri="None%(state_eid)s" name="activated"/>
  </in_state>
  <use_email role="subject">
  </use_email>
</CWUser>
''' % {'date': SERIALIZERS['Datetime'](req.user.creation_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()