130 peschema.subject_relation('connait').set_rproperty(peschema, peschema, 'cardinality', '11') |
130 peschema.subject_relation('connait').set_rproperty(peschema, peschema, 'cardinality', '11') |
131 peschema.subject_relation('evaluee').set_rproperty(peschema, Note.e_schema, 'cardinality', '1*') |
131 peschema.subject_relation('evaluee').set_rproperty(peschema, Note.e_schema, 'cardinality', '1*') |
132 seschema.subject_relation('evaluee').set_rproperty(seschema, Note.e_schema, 'cardinality', '1*') |
132 seschema.subject_relation('evaluee').set_rproperty(seschema, Note.e_schema, 'cardinality', '1*') |
133 # testing basic fetch_attrs attribute |
133 # testing basic fetch_attrs attribute |
134 self.assertEquals(Personne.fetch_rql(user), |
134 self.assertEquals(Personne.fetch_rql(user), |
135 'Any X,AA,AB,AC ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC') |
135 'Any X,AA,AB,AC ORDERBY AA ASC ' |
|
136 'WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC') |
136 pfetch_attrs = Personne.fetch_attrs |
137 pfetch_attrs = Personne.fetch_attrs |
137 sfetch_attrs = Societe.fetch_attrs |
138 sfetch_attrs = Societe.fetch_attrs |
138 try: |
139 try: |
139 # testing unknown attributes |
140 # testing unknown attributes |
140 Personne.fetch_attrs = ('bloug', 'beep') |
141 Personne.fetch_attrs = ('bloug', 'beep') |
141 self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
142 self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
142 # testing one non final relation |
143 # testing one non final relation |
143 Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
144 Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
144 self.assertEquals(Personne.fetch_rql(user), |
145 self.assertEquals(Personne.fetch_rql(user), |
145 'Any X,AA,AB,AC,AD ORDERBY AA ASC WHERE X is Personne, X nom AA, X prenom AB, X travaille AC, AC nom AD') |
146 'Any X,AA,AB,AC,AD ORDERBY AA ASC ' |
|
147 'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
146 # testing two non final relations |
148 # testing two non final relations |
147 Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
149 Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
148 self.assertEquals(Personne.fetch_rql(user), |
150 self.assertEquals(Personne.fetch_rql(user), |
149 'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC WHERE X is Personne, X nom AA, ' |
151 'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC ' |
150 'X prenom AB, X travaille AC, AC nom AD, X evaluee AE, AE modification_date AF') |
152 'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
|
153 'X evaluee AE?, AE modification_date AF') |
151 # testing one non final relation with recursion |
154 # testing one non final relation with recursion |
152 Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
155 Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
153 Societe.fetch_attrs = ('nom', 'evaluee') |
156 Societe.fetch_attrs = ('nom', 'evaluee') |
154 self.assertEquals(Personne.fetch_rql(user), |
157 self.assertEquals(Personne.fetch_rql(user), |
155 'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC WHERE X is Personne, X nom AA, X prenom AB, ' |
158 'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA ASC,AF DESC ' |
156 'X travaille AC, AC nom AD, AC evaluee AE, AE modification_date AF' |
159 'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
|
160 'AC evaluee AE?, AE modification_date AF' |
157 ) |
161 ) |
158 # testing symetric relation |
162 # testing symetric relation |
159 Personne.fetch_attrs = ('nom', 'connait') |
163 Personne.fetch_attrs = ('nom', 'connait') |
160 self.assertEquals(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ASC ' |
164 self.assertEquals(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ASC ' |
161 'WHERE X is Personne, X nom AA, X connait AB?') |
165 'WHERE X is Personne, X nom AA, X connait AB?') |
176 |
180 |
177 def test_related_rql(self): |
181 def test_related_rql(self): |
178 from cubicweb.entities import fetch_config |
182 from cubicweb.entities import fetch_config |
179 Personne = self.vreg['etypes'].etype_class('Personne') |
183 Personne = self.vreg['etypes'].etype_class('Personne') |
180 Note = self.vreg['etypes'].etype_class('Note') |
184 Note = self.vreg['etypes'].etype_class('Note') |
|
185 self.failUnless(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note)) |
181 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
186 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', 'type')) |
182 Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
187 Note.fetch_attrs, Note.fetch_order = fetch_config(('type',)) |
183 aff = self.add_entity('Personne', nom=u'pouet') |
188 p = self.add_entity('Personne', nom=u'pouet') |
184 self.assertEquals(aff.related_rql('evaluee'), |
189 self.assertEquals(p.related_rql('evaluee'), |
185 'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
190 'Any X,AA,AB ORDERBY AA ASC WHERE E eid %(x)s, E evaluee X, ' |
186 'X type AA, X modification_date AB') |
191 'X type AA, X modification_date AB') |
187 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
192 Personne.fetch_attrs, Personne.fetch_order = fetch_config(('nom', )) |
188 # XXX |
193 # XXX |
189 self.assertEquals(aff.related_rql('evaluee'), |
194 self.assertEquals(p.related_rql('evaluee'), |
190 'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA') |
195 'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA') |
191 |
196 |
192 def test_entity_unrelated(self): |
197 def test_entity_unrelated(self): |
193 p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
198 p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
194 e = self.add_entity('Tag', name=u'x') |
199 e = self.add_entity('Tag', name=u'x') |