merge
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Dec 2009 14:53:59 +0100
changeset 4038 273f9e4e6d19
parent 4035 a0b6714e84f1 (current diff)
parent 4037 42f3a80738d7 (diff)
child 4039 6e3d96ab565f
merge
--- a/devtools/testlib.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/devtools/testlib.py	Tue Dec 08 14:53:59 2009 +0100
@@ -756,7 +756,7 @@
             rset = cu.execute('%s X' % etype)
             edict[str(etype)] = set(row[0] for row in rset.rows)
         existingrels = {}
-        ignored_relations = SYSTEM_RELATIONS + self.ignored_relations
+        ignored_relations = SYSTEM_RELATIONS | self.ignored_relations
         for rschema in self.schema.relations():
             if rschema.final or rschema in ignored_relations:
                 continue
--- a/entities/test/unittest_base.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/entities/test/unittest_base.py	Tue Dec 08 14:53:59 2009 +0100
@@ -29,7 +29,7 @@
 
     def test_creator(self):
         self.login(u'member')
-        entity = self.add_entity('Bookmark', title=u"hello", path=u'project/cubicweb')
+        entity = self.request().create_entity('Bookmark', title=u"hello", path=u'project/cubicweb')
         self.commit()
         self.assertEquals(entity.creator.eid, self.member.eid)
         self.assertEquals(entity.dc_creator(), u'member')
--- a/entities/test/unittest_wfobjs.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/entities/test/unittest_wfobjs.py	Tue Dec 08 14:53:59 2009 +0100
@@ -45,7 +45,6 @@
         # gnark gnark
         bar = wf.add_state(u'bar')
         self.commit()
-        print '*'*80
         bar.set_attributes(name=u'foo')
         ex = self.assertRaises(ValidationError, self.commit)
         self.assertEquals(ex.errors, {'name': 'workflow already have a state of that name'})
@@ -76,8 +75,8 @@
 
     def setup_database(self):
         rschema = self.schema['in_state']
-        for x, y in rschema.iter_rdefs():
-            self.assertEquals(rschema.rproperty(x, y, 'cardinality'), '1*')
+        for rdef in rschema.rdefs.values():
+            self.assertEquals(rdef.cardinality, '1*')
         self.member = self.create_user('member')
 
     def test_workflow_base(self):
@@ -210,7 +209,7 @@
                                       [(swfstate2, state2), (swfstate3, state3)])
         self.assertEquals(swftr1.destination().eid, swfstate1.eid)
         # workflows built, begin test
-        self.group = self.add_entity('CWGroup', name=u'grp1')
+        self.group = self.request().create_entity('CWGroup', name=u'grp1')
         self.commit()
         self.assertEquals(self.group.current_state.eid, state1.eid)
         self.assertEquals(self.group.current_workflow.eid, mwf.eid)
@@ -234,7 +233,7 @@
         # subworkflow input transition
         ex = self.assertRaises(ValidationError,
                                self.group.change_state, swfstate1, u'gadget')
-        self.assertEquals(ex.errors, {'to_state': "state doesn't belong to entity's current workflow"})
+        self.assertEquals(ex.errors, {'to_state': "state doesn't belong to entity's workflow"})
         self.rollback()
         # force back to state1
         self.group.change_state('state1', u'gadget')
@@ -295,7 +294,7 @@
         twf.add_wftransition(_('close'), subwf, (released,),
                              [(xsigned, closed), (xaborted, released)])
         self.commit()
-        group = self.add_entity('CWGroup', name=u'grp1')
+        group = self.request().create_entity('CWGroup', name=u'grp1')
         self.commit()
         for trans in ('identify', 'release', 'close'):
             group.fire_transition(trans)
@@ -320,7 +319,7 @@
         twf.add_wftransition(_('release'), subwf, identified,
                              [(xaborted, None)])
         self.commit()
-        group = self.add_entity('CWGroup', name=u'grp1')
+        group = self.request().create_entity('CWGroup', name=u'grp1')
         self.commit()
         for trans, nextstate in (('identify', 'xsigning'),
                                  ('xabort', 'created'),
@@ -390,7 +389,7 @@
         wf = add_wf(self, 'Company')
         wf.add_state('asleep', initial=True)
         self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s',
-                     {'wf': wf.eid, 'x': self.member.eid})
+                     {'wf': wf.eid, 'x': self.member.eid}, 'x')
         ex = self.assertRaises(ValidationError, self.commit)
         self.assertEquals(ex.errors, {'custom_workflow': 'workflow isn\'t a workflow for this type'})
 
--- a/entities/wfobjs.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/entities/wfobjs.py	Tue Dec 08 14:53:59 2009 +0100
@@ -146,8 +146,8 @@
                                   requiredgroups, conditions, **kwargs)
         if hasattr(subworkflow, 'eid'):
             subworkflow = subworkflow.eid
-        assert _cw.req.execute('SET T subworkflow WF WHERE WF eid %(wf)s,T eid %(t)s',
-                               {'t': tr.eid, 'wf': subworkflow}, ('wf', 't'))
+        assert self._cw.execute('SET T subworkflow WF WHERE WF eid %(wf)s,T eid %(t)s',
+                                {'t': tr.eid, 'wf': subworkflow}, ('wf', 't'))
         for fromstate, tostate in exitpoints:
             tr.add_exit_point(fromstate, tostate)
         return tr
@@ -247,9 +247,8 @@
             kwargs['x'] = self.eid
             kwargs.setdefault('mainvars', u'X')
             self._cw.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", '
-                             'X expression %(expr)s, T condition X '
-                             'WHERE T eid %(x)s',
-                             'T condition X WHERE T eid %(x)s', kwargs, 'x')
+                             'X expression %(expr)s, X mainvars %(mainvars)s, '
+                             'T condition X WHERE T eid %(x)s',kwargs, 'x')
         # XXX clear caches?
 
 
@@ -464,9 +463,9 @@
                 kwargs['comment_format'] = commentformat
         kwargs['wf_info_for'] = self
         if treid is not None:
-            kwargs['by_transition'] = self.req.entity_from_eid(treid)
+            kwargs['by_transition'] = self._cw.entity_from_eid(treid)
         if tseid is not None:
-            kwargs['to_state'] = self.req.entity_from_eid(tseid)
+            kwargs['to_state'] = self._cw.entity_from_eid(tseid)
         return self._cw.create_entity('TrInfo', **kwargs)
 
     def fire_transition(self, tr, comment=None, commentformat=None):
--- a/hooks/integrity.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/hooks/integrity.py	Tue Dec 08 14:53:59 2009 +0100
@@ -67,7 +67,7 @@
 
 class UserIntegrityHook(IntegrityHook):
     __abstract__ = True
-    __select__ = IntegrityHook.__select__ & ~hook.regular_session()
+    __select__ = IntegrityHook.__select__ & hook.regular_session()
 
 
 class CheckCardinalityHook(UserIntegrityHook):
@@ -153,6 +153,7 @@
             _CheckConstraintsOp(self._cw, constraints=constraints,
                                rdef=(self.eidfrom, self.rtype, self.eidto))
 
+
 class CheckAttributeConstraintHook(UserIntegrityHook):
     """check the attribute relation satisfy its constraints
 
@@ -182,8 +183,7 @@
         entity = self.entity
         eschema = entity.e_schema
         for attr in entity.edited_attributes:
-            if eschema.subject_relation(attr).final and \
-                   eschema.has_unique_values(attr):
+            if eschema.subjrels[attr].final and eschema.has_unique_values(attr):
                 val = entity[attr]
                 if val is None:
                     continue
--- a/hooks/workflow.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/hooks/workflow.py	Tue Dec 08 14:53:59 2009 +0100
@@ -125,13 +125,13 @@
             msg %= session._(forentity.current_workflow.name)
             session.transaction_data[(forentity.eid, 'subwfentrytr')] = True
             # XXX iirk
-            req = forentity.req
-            forentity.req = session.super_session
+            req = forentity._cw
+            forentity._cw = session.super_session
             try:
                 trinfo = forentity.change_state(tostate, msg, u'text/plain',
                                                 tr=wftr)
             finally:
-                forentity.req = req
+                forentity._cw = req
 
 
 # hooks ########################################################################
--- a/schema.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/schema.py	Tue Dec 08 14:53:59 2009 +0100
@@ -431,7 +431,7 @@
         if 'toeid' in kwargs:
             objtype = session.describe(kwargs['toeid'])[0]
         else:
-            objtype = Nono
+            objtype = None
         if objtype and subjtype:
             return self.rdef(subjtype, objtype).has_perm(session, action, **kwargs)
         elif subjtype:
--- a/selectors.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/selectors.py	Tue Dec 08 14:53:59 2009 +0100
@@ -79,7 +79,7 @@
         ret = selector(cls, *args, **kwargs)
         if TRACED_OIDS == 'all' or oid in TRACED_OIDS:
             #SELECTOR_LOGGER.warning('selector %s returned %s for %s', selname, ret, cls)
-            print '%s -> %s for %s' % (selname, ret, vobj)
+            print '%s -> %s for %s(%s)' % (selname, ret, vobj, vobj.__regid__)
         return ret
     traced.__name__ = selector.__name__
     return traced
--- a/server/hook.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/server/hook.py	Tue Dec 08 14:53:59 2009 +0100
@@ -145,12 +145,12 @@
     """
     def __init__(self, *expected):
         self.expected = expected
-        if len(expected) == 1:
-            try:
-                iter(expected[0])
-                self.expected = expected[0]
-            except TypeError:
-                pass
+        # if len(expected) == 1:
+        #     try:
+        #         iter(expected[0])
+        #         self.expected = expected[0]
+        #     except TypeError:
+        #         pass
 
     @lltrace
     def __call__(self, cls, req, *args, **kwargs):
--- a/server/schemaserial.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/server/schemaserial.py	Tue Dec 08 14:53:59 2009 +0100
@@ -363,7 +363,7 @@
 def _rdef_values(rschema, objtype, props):
     amap = {'order': 'ordernum'}
     values = {}
-    for prop, default in rschema.rproperty_defs(objtype).iteritems():
+    for prop, default in schemamod.RelationDefinitionSchema.rproperty_defs(objtype).iteritems():
         if prop in ('eid', 'constraints', 'uid', 'infered', 'permissions'):
             continue
         value = props.get(prop, default)
@@ -395,7 +395,8 @@
     return relations, values
 
 
-def __rdef2rql(genmap, rschema, subjtype=None, objtype=None, props=None, groupmap=None):
+def __rdef2rql(genmap, rschema, subjtype=None, objtype=None, props=None,
+               groupmap=None):
     if subjtype is None:
         assert objtype is None
         assert props is None
@@ -445,8 +446,8 @@
 
 def erschema2rql(erschema, groupmap):
     if isinstance(erschema, schemamod.EntitySchema):
-        return eschema2rql(erschema, groupmap)
-    return rschema2rql(erschema)
+        return eschema2rql(erschema, groupmap=groupmap)
+    return rschema2rql(erschema, groupmap=groupmap)
 
 def eschema2rql(eschema, groupmap):
     """return a list of rql insert statements to enter an entity schema
--- a/test/unittest_entity.py	Tue Dec 08 12:46:45 2009 +0100
+++ b/test/unittest_entity.py	Tue Dec 08 14:53:59 2009 +0100
@@ -39,13 +39,14 @@
         self.assertEquals(e.has_eid(), True)
 
     def test_copy(self):
-        self.add_entity('Tag', name=u'x')
-        p = self.add_entity('Personne', nom=u'toto')
-        oe = self.add_entity('Note', type=u'x')
+        req = self.request()
+        req.create_entity('Tag', name=u'x')
+        p = req.create_entity('Personne', nom=u'toto')
+        oe = req.create_entity('Note', type=u'x')
         self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s',
                      {'t': oe.eid, 'u': p.eid}, ('t','u'))
         self.execute('SET TAG tags X WHERE X eid %(x)s', {'x': oe.eid}, 'x')
-        e = self.add_entity('Note', type=u'z')
+        e = req.create_entity('Note', type=u'z')
         e.copy_relations(oe.eid)
         self.assertEquals(len(e.ecrit_par), 1)
         self.assertEquals(e.ecrit_par[0].eid, p.eid)
@@ -54,12 +55,13 @@
         self.assertEquals(len(e.created_by), 0)
 
     def test_copy_with_nonmeta_composite_inlined(self):
-        p = self.add_entity('Personne', nom=u'toto')
-        oe = self.add_entity('Note', type=u'x')
+        req = self.request()
+        p = req.create_entity('Personne', nom=u'toto')
+        oe = req.create_entity('Note', type=u'x')
         self.schema['ecrit_par'].rdef('Note', 'Personne').composite = 'subject'
         self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s',
                      {'t': oe.eid, 'u': p.eid}, ('t','u'))
-        e = self.add_entity('Note', type=u'z')
+        e = req.create_entity('Note', type=u'z')
         e.copy_relations(oe.eid)
         self.failIf(e.ecrit_par)
         self.failUnless(oe.ecrit_par)
@@ -105,9 +107,10 @@
             self.failIf('in_group_subject' in group._related_cache, group._related_cache.keys())
 
     def test_related_limit(self):
-        p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
+        req = self.request()
+        p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
         for tag in u'abcd':
-            self.add_entity('Tag', name=tag)
+            req.create_entity('Tag', name=tag)
         self.execute('SET X tags Y WHERE X is Tag, Y is Personne')
         self.assertEquals(len(p.related('tags', 'object', limit=2)), 2)
         self.assertEquals(len(p.related('tags', 'object')), 4)
@@ -178,7 +181,7 @@
         self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note))
         Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type'))
         Note.fetch_attrs, Note.fetch_order = fetch_config(('type',))
-        p = self.add_entity('Personne', nom=u'pouet')
+        p = self.request().create_entity('Personne', nom=u'pouet')
         self.assertEquals(p.related_rql('evaluee'),
                           'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, '
                           'X type AA, X modification_date AB')
@@ -241,8 +244,9 @@
                           'A eid %(B)s, EXISTS(S identity A, NOT A in_group C, C name "guests", C is CWGroup)')
 
     def test_unrelated_base(self):
-        p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
-        e = self.add_entity('Tag', name=u'x')
+        req = self.request()
+        p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
+        e = req.create_entity('Tag', name=u'x')
         related = [r.eid for r in e.tags]
         self.failUnlessEqual(related, [])
         unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')]
@@ -253,9 +257,10 @@
         self.failIf(p.eid in unrelated)
 
     def test_unrelated_limit(self):
-        e = self.add_entity('Tag', name=u'x')
-        self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
-        self.add_entity('Personne', nom=u'thenault', prenom=u'sylvain')
+        req = self.request()
+        e = req.create_entity('Tag', name=u'x')
+        req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
+        req.create_entity('Personne', nom=u'thenault', prenom=u'sylvain')
         self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)),
                           1)
 
@@ -292,7 +297,7 @@
         self.assertEquals(len(unrelated), 3)
 
     def test_printable_value_string(self):
-        e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`',
+        e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`',
                             content_format=u'text/rest')
         self.assertEquals(e.printable_value('content'),
                           '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/guests">*ReST*</a></p>\n')
@@ -325,7 +330,8 @@
 
 
     def test_printable_value_bytes(self):
-        e = self.add_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python',
+        req = self.request()
+        e = req.create_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python',
                             data_encoding=u'ascii', data_name=u'toto.py')
         from cubicweb import mttransforms
         if mttransforms.HAS_PYGMENTS_TRANSFORMS:
@@ -340,14 +346,15 @@
 </pre>
 ''')
 
-        e = self.add_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest',
+        e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest',
                             data_encoding=u'utf-8', data_name=u'toto.txt')
         self.assertEquals(e.printable_value('data'),
                           u'<p><em>héhéhé</em></p>\n')
 
     def test_printable_value_bad_html(self):
         """make sure we don't crash if we try to render invalid XHTML strings"""
-        e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>',
+        req = self.request()
+        e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>',
                             content_format=u'text/html')
         tidy = lambda x: x.replace('\n', '')
         self.assertEquals(tidy(e.printable_value('content')),
@@ -380,7 +387,8 @@
 
     def test_printable_value_bad_html_ms(self):
         self.skip('fix soup2xhtml to handle this test')
-        e = self.add_entity('Card', title=u'bad html', content=u'<div>R&D<br>',
+        req = self.request()
+        e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>',
                             content_format=u'text/html')
         tidy = lambda x: x.replace('\n', '')
         e['content'] = u'<div x:foo="bar">ms orifice produces weird html</div>'
@@ -411,8 +419,9 @@
 
 
     def test_nonregr_relation_cache(self):
-        p1 = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
-        p2 = self.add_entity('Personne', nom=u'toto')
+        req = self.request()
+        p1 = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
+        p2 = req.create_entity('Personne', nom=u'toto')
         self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"')
         self.assertEquals(p1.evaluee[0].nom, "toto")
         self.failUnless(not p1.reverse_evaluee)
@@ -438,26 +447,28 @@
         self.failUnless(state is samestate)
 
     def test_rest_path(self):
-        note = self.add_entity('Note', type=u'z')
+        req = self.request()
+        note = req.create_entity('Note', type=u'z')
         self.assertEquals(note.rest_path(), 'note/%s' % note.eid)
         # unique attr
-        tag = self.add_entity('Tag', name=u'x')
+        tag = req.create_entity('Tag', name=u'x')
         self.assertEquals(tag.rest_path(), 'tag/x')
         # test explicit rest_attr
-        person = self.add_entity('Personne', prenom=u'john', nom=u'doe')
+        person = req.create_entity('Personne', prenom=u'john', nom=u'doe')
         self.assertEquals(person.rest_path(), 'personne/doe')
         # ambiguity test
-        person2 = self.add_entity('Personne', prenom=u'remi', nom=u'doe')
+        person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe')
         self.assertEquals(person.rest_path(), 'personne/eid/%s' % person.eid)
         self.assertEquals(person2.rest_path(), 'personne/eid/%s' % person2.eid)
         # unique attr with None value (wikiid in this case)
-        card1 = self.add_entity('Card', title=u'hop')
+        card1 = req.create_entity('Card', title=u'hop')
         self.assertEquals(card1.rest_path(), 'card/eid/%s' % card1.eid)
-        card2 = self.add_entity('Card', title=u'pod', wikiid=u'zob/i')
+        card2 = req.create_entity('Card', title=u'pod', wikiid=u'zob/i')
         self.assertEquals(card2.rest_path(), 'card/zob%2Fi')
 
     def test_set_attributes(self):
-        person = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
+        req = self.request()
+        person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien')
         self.assertEquals(person.prenom, u'adrien')
         self.assertEquals(person.nom, u'di mascio')
         person.set_attributes(prenom=u'sylvain', nom=u'thénault')
@@ -466,7 +477,8 @@
         self.assertEquals(person.nom, u'thénault')
 
     def test_metainformation_and_external_absolute_url(self):
-        note = self.add_entity('Note', type=u'z')
+        req = self.request()
+        note = req.create_entity('Note', type=u'z')
         metainf = note.metainformation()
         self.assertEquals(metainf, {'source': {'adapter': 'native', 'uri': 'system'}, 'type': u'Note', 'extid': None})
         self.assertEquals(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid)
@@ -476,14 +488,16 @@
         self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/1234')
 
     def test_absolute_url_empty_field(self):
-        card = self.add_entity('Card', wikiid=u'', title=u'test')
+        req = self.request()
+        card = req.create_entity('Card', wikiid=u'', title=u'test')
         self.assertEquals(card.absolute_url(),
                           'http://testing.fr/cubicweb/card/eid/%s' % card.eid)
 
     def test_create_entity(self):
-        p1 = self.add_entity('Personne', nom=u'fayolle', prenom=u'alexandre')
-        p2 = self.add_entity('Personne', nom=u'campeas', prenom=u'aurelien')
-        note = self.add_entity('Note', type=u'z')
+        req = self.request()
+        p1 = req.create_entity('Personne', nom=u'fayolle', prenom=u'alexandre')
+        p2 = req.create_entity('Personne', nom=u'campeas', prenom=u'aurelien')
+        note = req.create_entity('Note', type=u'z')
         req = self.request()
         p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien',
                               connait=p1, evaluee=[p1, p2],