author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 15 Apr 2010 19:39:55 +0200 | |
changeset 5302 | dfd147de06b2 |
parent 4491 | a0f48c31b58a |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2657
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1739
diff
changeset
|
7 |
""" |
1284 | 8 |
from logilab.common.testlib import TestCase, unittest_main |
2369
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
9 |
from cubicweb.rtags import RelationTags, RelationTagsSet, RelationTagsDict |
1284 | 10 |
|
11 |
class RelationTagsTC(TestCase): |
|
1533 | 12 |
|
1284 | 13 |
def test_rtags_expansion(self): |
14 |
rtags = RelationTags() |
|
1739 | 15 |
rtags.tag_subject_of(('Societe', 'travaille', '*'), 'primary') |
16 |
rtags.tag_subject_of(('*', 'evaluee', '*'), 'secondary') |
|
17 |
rtags.tag_object_of(('*', 'tags', '*'), 'generated') |
|
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
18 |
self.assertEquals(rtags.get('Note', 'evaluee', '*', 'subject'), |
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
19 |
'secondary') |
1739 | 20 |
self.assertEquals(rtags.get('Societe', 'travaille', '*', 'subject'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
21 |
'primary') |
1739 | 22 |
self.assertEquals(rtags.get('Note', 'travaille', '*', 'subject'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
23 |
None) |
1739 | 24 |
self.assertEquals(rtags.get('Note', 'tags', '*', 'subject'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
25 |
None) |
1739 | 26 |
self.assertEquals(rtags.get('*', 'tags', 'Note', 'object'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
27 |
'generated') |
1739 | 28 |
self.assertEquals(rtags.get('Tag', 'tags', '*', 'object'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
29 |
'generated') |
1533 | 30 |
|
1284 | 31 |
# self.assertEquals(rtags.rtag('evaluee', 'Note', 'subject'), set(('secondary', 'link'))) |
32 |
# self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), False) |
|
33 |
# self.assertEquals(rtags.rtag('evaluee', 'Personne', 'subject'), set(('secondary', 'link'))) |
|
34 |
# self.assertEquals(rtags.is_inlined('evaluee', 'Personne', 'subject'), False) |
|
35 |
# self.assertEquals(rtags.rtag('ecrit_par', 'Note', 'object'), set(('inlineview', 'link'))) |
|
36 |
# self.assertEquals(rtags.is_inlined('ecrit_par', 'Note', 'object'), True) |
|
37 |
# class Personne2(Personne): |
|
38 |
# id = 'Personne' |
|
39 |
# __rtags__ = { |
|
40 |
# ('evaluee', 'Note', 'subject') : set(('inlineview',)), |
|
41 |
# } |
|
4491
a0f48c31b58a
kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
42 |
# self.vreg.register(Personne2) |
1284 | 43 |
# rtags = Personne2.rtags |
44 |
# self.assertEquals(rtags.rtag('evaluee', 'Note', 'subject'), set(('inlineview', 'link'))) |
|
45 |
# self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), True) |
|
46 |
# self.assertEquals(rtags.rtag('evaluee', 'Personne', 'subject'), set(('secondary', 'link'))) |
|
1533 | 47 |
# self.assertEquals(rtags.is_inlined('evaluee', 'Personne', 'subject'), False) |
48 |
||
49 |
||
50 |
def test_rtagset_expansion(self): |
|
51 |
rtags = RelationTagsSet() |
|
1739 | 52 |
rtags.tag_subject_of(('Societe', 'travaille', '*'), 'primary') |
53 |
rtags.tag_subject_of(('*', 'travaille', '*'), 'secondary') |
|
54 |
self.assertEquals(rtags.get('Societe', 'travaille', '*', 'subject'), |
|
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
55 |
set(('primary', 'secondary'))) |
1739 | 56 |
self.assertEquals(rtags.get('Note', 'travaille', '*', 'subject'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
57 |
set(('secondary',))) |
1739 | 58 |
self.assertEquals(rtags.get('Note', 'tags', "*", 'subject'), |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1533
diff
changeset
|
59 |
set()) |
1284 | 60 |
|
2369
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
61 |
def test_rtagdict_expansion(self): |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
62 |
rtags = RelationTagsDict() |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
63 |
rtags.tag_subject_of(('Societe', 'travaille', '*'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
64 |
{'key1': 'val1', 'key2': 'val1'}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
65 |
rtags.tag_subject_of(('*', 'travaille', '*'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
66 |
{'key1': 'val0', 'key3': 'val0'}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
67 |
rtags.tag_subject_of(('Societe', 'travaille', '*'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
68 |
{'key2': 'val2'}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
69 |
self.assertEquals(rtags.get('Societe', 'travaille', '*', 'subject'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
70 |
{'key1': 'val1', 'key2': 'val2', 'key3': 'val0'}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
71 |
self.assertEquals(rtags.get('Note', 'travaille', '*', 'subject'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
72 |
{'key1': 'val0', 'key3': 'val0'}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
73 |
self.assertEquals(rtags.get('Note', 'tags', "*", 'subject'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
74 |
{}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
75 |
|
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
76 |
rtags.setdefault(('Societe', 'travaille', '*', 'subject'), 'key1', 'val4') |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
77 |
rtags.setdefault(('Societe', 'travaille', '*', 'subject'), 'key4', 'val4') |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
78 |
self.assertEquals(rtags.get('Societe', 'travaille', '*', 'subject'), |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
79 |
{'key1': 'val1', 'key2': 'val2', 'key3': 'val0', 'key4': 'val4'}) |
5a2b8ed266ca
new RelationTagsDict class, use it in uicfg where necessary
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
80 |
|
1284 | 81 |
if __name__ == '__main__': |
82 |
unittest_main() |