# -*- coding: utf-8 -*- from cubicweb.devtools.apptest import EnvBasedTC from cubicweb.web.views.autoform import AutomaticEntityForm as aef from cubicweb.web.views import actions, embedding from cubes.link import views class LinkTC(EnvBasedTC): def setup_database(self): self.add_entity('Link', title=u"vous ĂȘtes perdu ?", url=u"http://www.perdu.com") def test_possible_actions(self): rset, req = self.env.get_rset_and_req('Link X') self.assertEquals(self.pactionsdict(req, rset), {'mainactions': [actions.ModifyAction, views.LinkFollowAction], 'moreactions': [actions.ManagePermissionsAction,actions.DeleteAction, actions.CopyAction, embedding.EmbedAction], }) def test_relations_by_category(self): def rbc(iterable): return [(rschema.type, x) for rschema, tschemas, x in iterable] e = self.etype_instance('Link') # we should only see embed when we are in the managers group self.assertEquals(rbc(aef.erelations_by_category(e, 'secondary', 'add')), [('embed', 'subject'), ('description', 'subject')]) self.assertEquals(rbc(aef.erelations_by_category(e,'secondary', 'delete')), [('embed', 'subject'), ('description', 'subject')]) self.create_user('toto') self.login('toto') e = self.etype_instance('Link') # create a new instance with the new connection self.assertEquals(rbc(aef.erelations_by_category(e, 'secondary', 'add')), [('description', 'subject')]) self.assertEquals(rbc(aef.erelations_by_category(e, 'secondary', 'delete')), [('description', 'subject')]) if __name__ == '__main__': from logilab.common.testlib import unittest_main unittest_main()