R [test] update and fix deprecation warnings
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Sat, 01 Aug 2009 17:21:19 +0200
changeset 2637 07103211e511
parent 2636 104291d9bd00
child 2638 cda0be2e2c3f
R [test] update and fix deprecation warnings
entities/test/data/schema.py
server/test/data/migratedapp/schema.py
server/test/unittest_extlite.py
server/test/unittest_hookhelper.py
server/test/unittest_migractions.py
sobjects/test/unittest_notification.py
web/test/unittest_form.py
web/test/unittest_magicsearch.py
web/test/unittest_views_baseviews.py
web/test/unittest_views_editforms.py
--- a/entities/test/data/schema.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/entities/test/data/schema.py	Sat Aug 01 17:21:19 2009 +0200
@@ -5,6 +5,8 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+from yams.buildobjs import EntityType, String
+
 class Company(EntityType):
     name = String()
 
--- a/server/test/data/migratedapp/schema.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/server/test/data/migratedapp/schema.py	Sat Aug 01 17:21:19 2009 +0200
@@ -77,7 +77,7 @@
 class Personne(EntityType):
     nom    = String(fulltextindexed=True, required=True, maxsize=64)
     prenom = String(fulltextindexed=True, maxsize=64)
-    sexe   = String(maxsize=1, default='M')
+    civility   = String(maxsize=1, default='M')
     promo  = String(vocabulary=('bon','pasbon'))
     titre  = String(fulltextindexed=True, maxsize=128)
     adel   = String(maxsize=128)
--- a/server/test/unittest_extlite.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/server/test/unittest_extlite.py	Sat Aug 01 17:21:19 2009 +0200
@@ -17,7 +17,7 @@
             os.remove(self.sqlite_file)
         except:
             pass
-        
+
     def test(self):
         lock = threading.Lock()
 
--- a/server/test/unittest_hookhelper.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/server/test/unittest_hookhelper.py	Sat Aug 01 17:21:19 2009 +0200
@@ -41,10 +41,10 @@
         from cubicweb.server import hooks, schemahooks
         session = self.session
         op1 = hooks.DelayedDeleteOp(session)
-        op2 = schemahooks.DeleteRelationDefOp(session)
+        op2 = schemahooks.MemSchemaRDefDel(session)
         # equivalent operation generated by op2 but replace it here by op3 so we
         # can check the result...
-        op3 = schemahooks.UpdateSchemaOp(session)
+        op3 = schemahooks.MemSchemaNotifyChanges(session)
         op4 = hooks.DelayedDeleteOp(session)
         op5 = hooks.CheckORelationOp(session)
         self.assertEquals(session.pending_operations, [op1, op2, op4, op5, op3])
--- a/server/test/unittest_migractions.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/server/test/unittest_migractions.py	Sat Aug 01 17:21:19 2009 +0200
@@ -133,14 +133,16 @@
         self.failUnless('filed_under2' in self.schema)
         self.failUnless(self.execute('CWRType X WHERE X name "filed_under2"'))
         self.assertEquals(sorted(str(rs) for rs in self.schema['Folder2'].subject_relations()),
-                          ['created_by', 'creation_date', 'description', 'description_format', 'eid',
-                           'filed_under2', 'has_text', 'identity', 'is', 'is_instance_of',
+                          ['created_by', 'creation_date', 'cwuri',
+                           'description', 'description_format',
+                           'eid',
+                           'filed_under2', 'has_text',
+                           'identity', 'in_basket', 'is', 'is_instance_of',
                            'modification_date', 'name', 'owned_by'])
         self.assertEquals([str(rs) for rs in self.schema['Folder2'].object_relations()],
                           ['filed_under2', 'identity'])
         self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
-                          ['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File',
-                           'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision'])
+                          sorted(str(e) for e in self.schema.entities() if not e.is_final()))
         self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',))
         eschema = self.schema.eschema('Folder2')
         for cstr in eschema.constraints('name'):
@@ -166,8 +168,7 @@
         self.mh.cmd_add_relation_type('filed_under2')
         self.failUnless('filed_under2' in self.schema)
         self.assertEquals(sorted(str(e) for e in self.schema['filed_under2'].subjects()),
-                          ['Affaire', 'Card', 'Division', 'Email', 'EmailThread', 'File',
-                           'Folder2', 'Image', 'Note', 'Personne', 'Societe', 'SubDivision'])
+                          sorted(str(e) for e in self.schema.entities() if not e.is_final()))
         self.assertEquals(self.schema['filed_under2'].objects(), ('Folder2',))
         self.mh.cmd_drop_relation_type('filed_under2')
         self.failIf('filed_under2' in self.schema)
@@ -181,26 +182,38 @@
         self.failIf('concerne2' in self.schema)
 
     def test_drop_relation_definition_existant_rtype(self):
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         self.mh.cmd_drop_relation_definition('Personne', 'concerne', 'Affaire')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Division', 'Note', 'Societe', 'SubDivision'])
         self.mh.cmd_add_relation_definition('Personne', 'concerne', 'Affaire')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         # trick: overwrite self.maxeid to avoid deletion of just reintroduced types
         self.maxeid = self.execute('Any MAX(X)')[0][0]
 
     def test_drop_relation_definition_with_specialization(self):
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         self.mh.cmd_drop_relation_definition('Affaire', 'concerne', 'Societe')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Note'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Note'])
         self.mh.cmd_add_relation_definition('Affaire', 'concerne', 'Societe')
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()), ['Affaire', 'Personne'])
-        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()), ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].subjects()),
+                          ['Affaire', 'Personne'])
+        self.assertEquals(sorted(str(e) for e in self.schema['concerne'].objects()),
+                          ['Affaire', 'Division', 'Note', 'Societe', 'SubDivision'])
         # trick: overwrite self.maxeid to avoid deletion of just reintroduced types
         self.maxeid = self.execute('Any MAX(X)')[0][0]
 
@@ -233,28 +246,15 @@
             self.mh.cmd_change_relation_props('Personne', 'adel', 'String',
                                               fulltextindexed=False)
 
-    def test_synchronize_schema(self):
+    def test_sync_schema_props_perms(self):
         cursor = self.mh.rqlcursor
         nbrqlexpr_start = len(cursor.execute('RQLExpression X'))
         migrschema['titre']._rproperties[('Personne', 'String')]['order'] = 7
         migrschema['adel']._rproperties[('Personne', 'String')]['order'] = 6
         migrschema['ass']._rproperties[('Personne', 'String')]['order'] = 5
-#         expected = ['eid', 'has_text', 'creation_date', 'modification_date',
-#                     'nom', 'prenom', 'civility', 'promo', 'ass', 'adel', 'titre',
-#                     'web', 'tel', 'fax', 'datenaiss', 'test']
-#         self.assertEquals([rs.type for rs in migrschema['Personne'].ordered_relations() if rs.is_final()],
-#                           expected)
         migrschema['Personne'].description = 'blabla bla'
         migrschema['titre'].description = 'usually a title'
         migrschema['titre']._rproperties[('Personne', 'String')]['description'] = 'title for this person'
-#         rinorderbefore = cursor.execute('Any O,N WHERE X is CWAttribute, X relation_type RT, RT name N,'
-#                                         'X from_entity FE, FE name "Personne",'
-#                                         'X ordernum O ORDERBY O')
-#         expected = [u'creation_date', u'modification_date', u'nom', u'prenom',
-#                     u'sexe', u'promo', u'titre', u'adel', u'ass', u'web', u'tel',
-#                     u'fax', u'datenaiss', u'test', u'description']
-#        self.assertListEquals(rinorderbefore, map(list, zip([0, 0]+range(1, len(expected)), expected)))
-
         self.mh.cmd_sync_schema_props_perms(commit=False)
 
         self.assertEquals(cursor.execute('Any D WHERE X name "Personne", X description D')[0][0],
@@ -265,16 +265,13 @@
                                          'X from_entity FE, FE name "Personne",'
                                          'X description D')[0][0],
                           'title for this person')
-        # skip "sexe" and "description" since they aren't in the migration
-        # schema and so behaviour is undefined
-        # "civility" is also skipped since it may have been added by
-        # test_rename_attribut :o/
-        rinorder = [n for n, in cursor.execute('Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,'
-                                               'X from_entity FE, FE name "Personne",'
-                                               'X ordernum O') if n not in ('sexe', 'description', 'civility')]
+        rinorder = [n for n, in cursor.execute(
+            'Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,'
+            'X from_entity FE, FE name "Personne",'
+            'X ordernum O')]
         expected = [u'nom', u'prenom', u'promo', u'ass', u'adel', u'titre',
-                    u'web', u'tel', u'fax', u'datenaiss', u'test', u'firstname',
-                    u'creation_date', u'modification_date']
+                    u'web', u'tel', u'fax', u'datenaiss', u'test', 'description', u'firstname',
+                    u'creation_date', 'cwuri', u'modification_date']
         self.assertEquals(rinorder, expected)
 
         # test permissions synchronization ####################################
--- a/sobjects/test/unittest_notification.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/sobjects/test/unittest_notification.py	Sat Aug 01 17:21:19 2009 +0200
@@ -74,7 +74,7 @@
         u = self.create_user('toto', req=req)
         assert u.req
         self.execute('SET X in_state S WHERE X eid %s, S name "deactivated"' % u.eid)
-        v = self.vreg.select('views', 'notif_status_change', req, u.rset, row=0)
+        v = self.vreg.select('views', 'notif_status_change', req, rset=u.rset, row=0)
         content = v.render(row=0, comment='yeah',
                            previous_state='activated',
                            current_state='deactivated')
--- a/web/test/unittest_form.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/web/test/unittest_form.py	Sat Aug 01 17:21:19 2009 +0200
@@ -151,17 +151,17 @@
 
     def test_richtextfield_1(self):
         self.req.use_fckeditor = lambda: False
-        self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="0">
+        self._test_richtextfield('''<select id="description_format:%(eid)s" name="description_format:%(eid)s" size="1" style="display: block" tabindex="1">
 <option value="text/cubicweb-page-template">text/cubicweb-page-template</option>
 <option value="text/html">text/html</option>
 <option value="text/plain">text/plain</option>
 <option selected="selected" value="text/rest">text/rest</option>
-</select><textarea cols="80" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="1"></textarea>''')
+</select><textarea cols="80" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="2"></textarea>''')
 
 
     def test_richtextfield_2(self):
         self.req.use_fckeditor = lambda: True
-        self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest" /><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="0"></textarea>')
+        self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest" /><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="1"></textarea>')
 
 
     def test_filefield(self):
@@ -172,11 +172,11 @@
                                data=Binary('new widgets system'))
         form = FFForm(self.req, redirect_path='perdu.com', entity=file)
         self.assertTextEquals(self._render_entity_field('data', form),
-                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value="" />
+                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" />
 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
 <div id="data:%(eid)s-advanced" class="hidden">
-<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain" /><br/>
-<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8" /><br/>
+<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
+<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
 </div>
 <br/>
 <input name="data:%(eid)s__detach" type="checkbox" />
@@ -196,17 +196,17 @@
                                data=Binary('new widgets system'))
         form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
         self.assertTextEquals(self._render_entity_field('data', form),
-                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value="" />
+                              '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="1" type="file" value="" />
 <a href="javascript: toggleVisibility(&#39;data:%(eid)s-advanced&#39;)" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
 <div id="data:%(eid)s-advanced" class="hidden">
-<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain" /><br/>
-<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8" /><br/>
+<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="2" type="text" value="text/plain" /><br/>
+<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="3" type="text" value="UTF-8" /><br/>
 </div>
 <br/>
 <input name="data:%(eid)s__detach" type="checkbox" />
 detach attached file
 <p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
-<textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
+<textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="4">new widgets system</textarea>''' % {'eid': file.eid})
 
 
     def test_passwordfield(self):
@@ -214,9 +214,9 @@
             upassword = StringField(widget=PasswordInput)
         form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
         self.assertTextEquals(self._render_entity_field('upassword', form),
-                              '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__" />
+                              '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
 <br/>
-<input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__" />
+<input name="upassword-confirm:%(eid)s" tabindex="1" type="password" value="__cubicweb_internal_field__" />
 &nbsp;
 <span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
 
--- a/web/test/unittest_magicsearch.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/web/test/unittest_magicsearch.py	Sat Aug 01 17:21:19 2009 +0200
@@ -147,11 +147,6 @@
                           ('CWUser C WHERE C use_email C1, C1 alias LIKE %(text)s', {'text': '%Logilab'}))
         self.assertRaises(BadRQLQuery, transform, 'word1', 'word2', 'word3')
 
-    def test_multiple_words_query(self):
-        """tests multiple_words_query()"""
-        self.assertEquals(self.proc._multiple_words_query(['a', 'b', 'c', 'd', 'e']),
-                          ('a b c d e',))
-
     def test_quoted_queries(self):
         """tests how quoted queries are handled"""
         queries = [
--- a/web/test/unittest_views_baseviews.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/web/test/unittest_views_baseviews.py	Sat Aug 01 17:21:19 2009 +0200
@@ -44,11 +44,16 @@
         rset = self.execute('Any X WHERE X eid 1')
         self.assertEquals(vid_from_rset(req, rset, self.schema), 'primary')
 
-    def test_more_than_one_entity(self):
+    def test_more_than_one_entity_same_type(self):
         req = self.request()
         rset = self.execute('Any X WHERE X is CWUser')
-        self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
+        self.assertEquals(vid_from_rset(req, rset, self.schema), 'adaptedlist')
         rset = self.execute('Any X, L WHERE X login L')
+        self.assertEquals(vid_from_rset(req, rset, self.schema), 'adaptedlist')
+
+    def test_more_than_one_entity_diff_type(self):
+        req = self.request()
+        rset = self.execute('Any X WHERE X is IN (CWUser, CWGroup)')
         self.assertEquals(vid_from_rset(req, rset, self.schema), 'list')
 
     def test_more_than_one_entity_by_row(self):
@@ -86,7 +91,7 @@
         rset = self.execute('Any X, D, CD, NOW - CD WHERE X is State, X description D, X creation_date CD, X eid %(x)s',
                             {'x': e.eid}, 'x')
         req = self.request()
-        view = self.vreg.select('views', 'table', req, rset)
+        view = self.vreg.select('views', 'table', req, rset=rset)
         return e, rset, view
 
     def test_headers(self):
@@ -102,9 +107,8 @@
         # self.assertAlmostEquals(value, rset.rows[0][3].seconds)
 
     def test_sortvalue_with_display_col(self):
-        self.skip('XXX there is no column_labels on rset')
         e, rset, view = self._prepare_entity()
-        labels = rset.column_labels()
+        labels = view.columns_labels()
         table = TableWidget(view)
         table.columns = view.get_columns(labels, [1, 2], None, None, None, None, 0)
         expected = ['loo"ong blabla'[:10], e.creation_date.strftime('%Y-%m-%d %H:%M')]
--- a/web/test/unittest_views_editforms.py	Sat Aug 01 17:20:26 2009 +0200
+++ b/web/test/unittest_views_editforms.py	Sat Aug 01 17:21:19 2009 +0200
@@ -25,12 +25,12 @@
         AEF.rfields_kwargs.del_rtag('CWUser', 'login', '*', 'subject')
 
 
-    def test_euser_relations_by_category(self):
+    def test_cwuser_relations_by_category(self):
         #for (rtype, role, stype, otype), tag in AEF.rcategories._tagdefs.items():
         #    if rtype == 'tags':
         #        print rtype, role, stype, otype, ':', tag
         e = self.etype_instance('CWUser')
-        # see custom configuration in views.euser
+        # see custom configuration in views.cwuser
         self.assertEquals(rbc(e, 'primary'),
                           [('login', 'subject'),
                            ('upassword', 'subject'),
@@ -46,6 +46,7 @@
                               [('last_login_time', 'subject'),
                                ('created_by', 'subject'),
                                ('creation_date', 'subject'),
+                               ('cwuri', 'subject'),
                                ('modification_date', 'subject'),
                                ('owned_by', 'subject'),
                                ('bookmarked_by', 'object'),
@@ -97,6 +98,7 @@
         self.assertListEquals(rbc(e, 'metadata'),
                               [('created_by', 'subject'),
                                ('creation_date', 'subject'),
+                               ('cwuri', 'subject'),
                                ('modification_date', 'subject'),
                                ('owned_by', 'subject'),
                                ])
@@ -158,3 +160,4 @@
 
 if __name__ == '__main__':
     unittest_main()
+