web/test/unittest_views_baseforms.py
branchtls-sprint
changeset 1398 5fe84a5f7035
parent 1016 26387b836099
child 1802 d628defebc17
equal deleted inserted replaced
1397:6cbc7bc8ea6d 1398:5fe84a5f7035
    47     
    47     
    48     def _test_view_for(self, etype, expected):
    48     def _test_view_for(self, etype, expected):
    49         self.assertTextEquals(expected, cleanup_text(self._build_creation_form(etype)))
    49         self.assertTextEquals(expected, cleanup_text(self._build_creation_form(etype)))
    50         
    50         
    51     def test_base(self):
    51     def test_base(self):
    52         self._test_view_for('EGroup', '''\
    52         self._test_view_for('CWGroup', '''\
    53 <form id="entityForm" class="entityForm" cubicweb:target="eformframe"
    53 <form id="entityForm" class="entityForm" cubicweb:target="eformframe"
    54 method="post" onsubmit="return freezeFormButtons('entityForm')" enctype="application/x-www-form-urlencoded" action="http://testing.fr/cubicweb/validateform">
    54 method="post" onsubmit="return freezeFormButtons('entityForm')" enctype="application/x-www-form-urlencoded" action="http://testing.fr/cubicweb/validateform">
    55 <div class="formTitle"><span>egroup (creation)</span></div>
    55 <div class="formTitle"><span>egroup (creation)</span></div>
    56 <div id="progress">validating...</div>
    56 <div id="progress">validating...</div>
    57 <div class="iformTitle"><span>main informations</span></div>
    57 <div class="iformTitle"><span>main informations</span></div>
    58 <div class="formBody"><fieldset>
    58 <div class="formBody"><fieldset>
    59 <input type="hidden" name="eid" value="A" />
    59 <input type="hidden" name="eid" value="A" />
    60 <input type="hidden" name="__type:A" value="EGroup" />
    60 <input type="hidden" name="__type:A" value="CWGroup" />
    61 <input type="hidden" name="__maineid" value="A" />
    61 <input type="hidden" name="__maineid" value="A" />
    62 <input id="errorurl" type="hidden" name="__errorurl" value="http://testing.fr/cubicweb/view?rql=Blop&amp;vid=blop" />
    62 <input id="errorurl" type="hidden" name="__errorurl" value="http://testing.fr/cubicweb/view?rql=Blop&amp;vid=blop" />
    63 <input type="hidden" name="__form_id" value="edition" />
    63 <input type="hidden" name="__form_id" value="edition" />
    64 <input type="hidden" name="__message" value="element created" />
    64 <input type="hidden" name="__message" value="element created" />
    65 <table id="entityFormA" class="attributeForm" style="width:100%;">
    65 <table id="entityFormA" class="attributeForm" style="width:100%;">
    86 </table>
    86 </table>
    87 </form>''')
    87 </form>''')
    88 
    88 
    89     def test_with_inline_view(self):
    89     def test_with_inline_view(self):
    90         activated = self.execute('Any X WHERE X is State, X name "activated"')[0][0]
    90         activated = self.execute('Any X WHERE X is State, X name "activated"')[0][0]
    91         self._test_view_for('EUser', '''<form id="entityForm" class="entityForm" cubicweb:target="eformframe"
    91         self._test_view_for('CWUser', '''<form id="entityForm" class="entityForm" cubicweb:target="eformframe"
    92 method="post" onsubmit="return freezeFormButtons('entityForm')" enctype="application/x-www-form-urlencoded" action="http://testing.fr/cubicweb/validateform">
    92 method="post" onsubmit="return freezeFormButtons('entityForm')" enctype="application/x-www-form-urlencoded" action="http://testing.fr/cubicweb/validateform">
    93 <div class="formTitle"><span>euser (creation)</span></div>
    93 <div class="formTitle"><span>euser (creation)</span></div>
    94 <div id="progress">validating...</div>
    94 <div id="progress">validating...</div>
    95 <div class="iformTitle"><span>main informations</span></div>
    95 <div class="iformTitle"><span>main informations</span></div>
    96 <div class="formBody"><fieldset>
    96 <div class="formBody"><fieldset>
    97 <input type="hidden" name="eid" value="A" />
    97 <input type="hidden" name="eid" value="A" />
    98 <input type="hidden" name="__type:A" value="EUser" />
    98 <input type="hidden" name="__type:A" value="CWUser" />
    99 <input type="hidden" name="__maineid" value="A" />
    99 <input type="hidden" name="__maineid" value="A" />
   100 <input id="errorurl" type="hidden" name="__errorurl" value="http://testing.fr/cubicweb/view?rql=Blop&amp;vid=blop" />
   100 <input id="errorurl" type="hidden" name="__errorurl" value="http://testing.fr/cubicweb/view?rql=Blop&amp;vid=blop" />
   101 <input type="hidden" name="__form_id" value="edition" />
   101 <input type="hidden" name="__form_id" value="edition" />
   102 <input type="hidden" name="__message" value="element created" />
   102 <input type="hidden" name="__message" value="element created" />
   103 <table id="entityFormA" class="attributeForm" style="width:100%%;">
   103 <table id="entityFormA" class="attributeForm" style="width:100%%;">
   157 </td>
   157 </td>
   158 </tr>
   158 </tr>
   159 </table>
   159 </table>
   160 <div id="inlineuse_emailslot">
   160 <div id="inlineuse_emailslot">
   161 <div class="inlinedform" id="addNewEmailAddressuse_emailsubject:A" cubicweb:limit="true">
   161 <div class="inlinedform" id="addNewEmailAddressuse_emailsubject:A" cubicweb:limit="true">
   162 <a class="addEntity" id="adduse_email:Alink" href="javascript: addInlineCreationForm('A', 'EUser', 'EmailAddress', 'use_email', 'subject')" >+ add a EmailAddress.</a>
   162 <a class="addEntity" id="adduse_email:Alink" href="javascript: addInlineCreationForm('A', 'CWUser', 'EmailAddress', 'use_email', 'subject')" >+ add a EmailAddress.</a>
   163 </div>
   163 </div>
   164 <div class="trame_grise">&nbsp;</div>
   164 <div class="trame_grise">&nbsp;</div>
   165 </div>
   165 </div>
   166 </fieldset>
   166 </fieldset>
   167 </div>
   167 </div>
   177 </table>
   177 </table>
   178 </form>''' % {'activated' : activated})
   178 </form>''' % {'activated' : activated})
   179 
   179 
   180     def test_redirection_after_creation(self):
   180     def test_redirection_after_creation(self):
   181         req = self.request()
   181         req = self.request()
   182         req.form['etype'] = 'EUser'
   182         req.form['etype'] = 'CWUser'
   183         view = self.vreg.select_view('creation', req, None)
   183         view = self.vreg.select_view('creation', req, None)
   184         self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/euser')
   184         self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/euser')
   185         req.form['__redirectrql'] = 'Any X WHERE X eid 3012'
   185         req.form['__redirectrql'] = 'Any X WHERE X eid 3012'
   186         req.form['__redirectvid'] = 'avid'
   186         req.form['__redirectvid'] = 'avid'
   187         self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/view?rql=Any%20X%20WHERE%20X%20eid%203012&vid=avid')
   187         self.assertEquals(view.redirect_url(), 'http://testing.fr/cubicweb/view?rql=Any%20X%20WHERE%20X%20eid%203012&vid=avid')
   227         self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s',
   227         self.execute('SET P use_email E, P primary_email E WHERE P eid %(p)s, E eid %(e)s',
   228                      {'p' : p.eid, 'e' : e.eid})
   228                      {'p' : p.eid, 'e' : e.eid})
   229 
   229 
   230 
   230 
   231     def test_cloned_elements_in_copy_form(self):
   231     def test_cloned_elements_in_copy_form(self):
   232         rset = self.execute('EUser P WHERE P login "Doe"')
   232         rset = self.execute('CWUser P WHERE P login "Doe"')
   233         output = self.view('copy', rset)
   233         output = self.view('copy', rset)
   234         clones = [attrs for _, attrs in output.input_tags
   234         clones = [attrs for _, attrs in output.input_tags
   235                   if attrs.get('name', '').startswith('__cloned_eid')]
   235                   if attrs.get('name', '').startswith('__cloned_eid')]
   236         # the only cloned entity should be the original person
   236         # the only cloned entity should be the original person
   237         self.assertEquals(len(clones), 1)
   237         self.assertEquals(len(clones), 1)