50 self.assertEqual(range1, sorted(range1)) |
50 self.assertEqual(range1, sorted(range1)) |
51 self.assertEqual(range2, sorted(range2)) |
51 self.assertEqual(range2, sorted(range2)) |
52 self.assertEqual(set(), set(range1) & set(range2)) |
52 self.assertEqual(set(), set(range1) & set(range2)) |
53 |
53 |
54 def test_occurence_count(self): |
54 def test_occurence_count(self): |
55 req = self.request() |
55 with self.admin_access.repo_cnx() as cnx: |
56 c1 = req.create_entity('Card', title=u'c1', |
56 c1 = cnx.create_entity('Card', title=u'c1', |
57 content=u'cubicweb cubicweb cubicweb') |
57 content=u'cubicweb cubicweb cubicweb') |
58 c2 = req.create_entity('Card', title=u'c3', |
58 c2 = cnx.create_entity('Card', title=u'c3', |
59 content=u'cubicweb') |
59 content=u'cubicweb') |
60 c3 = req.create_entity('Card', title=u'c2', |
60 c3 = cnx.create_entity('Card', title=u'c2', |
61 content=u'cubicweb cubicweb') |
61 content=u'cubicweb cubicweb') |
62 self.commit() |
62 cnx.commit() |
63 self.assertEqual(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
63 self.assertEqual(cnx.execute('Card X ORDERBY FTIRANK(X) DESC ' |
64 [[c1.eid,], [c3.eid,], [c2.eid,]]) |
64 'WHERE X has_text "cubicweb"').rows, |
|
65 [[c1.eid,], [c3.eid,], [c2.eid,]]) |
65 |
66 |
66 |
67 |
67 def test_attr_weight(self): |
68 def test_attr_weight(self): |
68 class CardIFTIndexableAdapter(IFTIndexableAdapter): |
69 class CardIFTIndexableAdapter(IFTIndexableAdapter): |
69 __select__ = is_instance('Card') |
70 __select__ = is_instance('Card') |
70 attr_weight = {'title': 'A'} |
71 attr_weight = {'title': 'A'} |
71 with self.temporary_appobjects(CardIFTIndexableAdapter): |
72 with self.temporary_appobjects(CardIFTIndexableAdapter): |
72 req = self.request() |
73 with self.admin_access.repo_cnx() as cnx: |
73 c1 = req.create_entity('Card', title=u'c1', |
74 c1 = cnx.create_entity('Card', title=u'c1', |
74 content=u'cubicweb cubicweb cubicweb') |
75 content=u'cubicweb cubicweb cubicweb') |
75 c2 = req.create_entity('Card', title=u'c2', |
76 c2 = cnx.create_entity('Card', title=u'c2', |
76 content=u'cubicweb cubicweb') |
77 content=u'cubicweb cubicweb') |
77 c3 = req.create_entity('Card', title=u'cubicweb', |
78 c3 = cnx.create_entity('Card', title=u'cubicweb', |
78 content=u'autre chose') |
79 content=u'autre chose') |
79 self.commit() |
80 cnx.commit() |
80 self.assertEqual(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
81 self.assertEqual(cnx.execute('Card X ORDERBY FTIRANK(X) DESC ' |
81 [[c3.eid,], [c1.eid,], [c2.eid,]]) |
82 'WHERE X has_text "cubicweb"').rows, |
|
83 [[c3.eid,], [c1.eid,], [c2.eid,]]) |
82 |
84 |
83 def test_entity_weight(self): |
85 def test_entity_weight(self): |
84 class PersonneIFTIndexableAdapter(IFTIndexableAdapter): |
86 class PersonneIFTIndexableAdapter(IFTIndexableAdapter): |
85 __select__ = is_instance('Personne') |
87 __select__ = is_instance('Personne') |
86 entity_weight = 2.0 |
88 entity_weight = 2.0 |
87 with self.temporary_appobjects(PersonneIFTIndexableAdapter): |
89 with self.temporary_appobjects(PersonneIFTIndexableAdapter): |
88 req = self.request() |
90 with self.admin_access.repo_cnx() as cnx: |
89 c1 = req.create_entity('Personne', nom=u'c1', prenom=u'cubicweb') |
91 c1 = cnx.create_entity('Personne', nom=u'c1', prenom=u'cubicweb') |
90 c2 = req.create_entity('Comment', content=u'cubicweb cubicweb', comments=c1) |
92 c2 = cnx.create_entity('Comment', content=u'cubicweb cubicweb', |
91 c3 = req.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', comments=c1) |
93 comments=c1) |
92 self.commit() |
94 c3 = cnx.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', |
93 self.assertEqual(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
95 comments=c1) |
94 [[c1.eid,], [c3.eid,], [c2.eid,]]) |
96 cnx.commit() |
|
97 self.assertEqual(cnx.execute('Any X ORDERBY FTIRANK(X) DESC ' |
|
98 'WHERE X has_text "cubicweb"').rows, |
|
99 [[c1.eid,], [c3.eid,], [c2.eid,]]) |
95 |
100 |
96 |
101 |
97 def test_tz_datetime(self): |
102 def test_tz_datetime(self): |
98 self.execute("INSERT Personne X: X nom 'bob', X tzdatenaiss %(date)s", |
103 with self.admin_access.repo_cnx() as cnx: |
99 {'date': datetime(1977, 6, 7, 2, 0, tzinfo=FixedOffset(1))}) |
104 cnx.execute("INSERT Personne X: X nom 'bob', X tzdatenaiss %(date)s", |
100 datenaiss = self.execute("Any XD WHERE X nom 'bob', X tzdatenaiss XD")[0][0] |
105 {'date': datetime(1977, 6, 7, 2, 0, tzinfo=FixedOffset(1))}) |
101 self.assertEqual(datenaiss.tzinfo, None) |
106 datenaiss = cnx.execute("Any XD WHERE X nom 'bob', X tzdatenaiss XD")[0][0] |
102 self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 1, 0)) |
107 self.assertEqual(datenaiss.tzinfo, None) |
103 self.commit() |
108 self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 1, 0)) |
104 self.execute("INSERT Personne X: X nom 'boby', X tzdatenaiss %(date)s", |
109 cnx.commit() |
105 {'date': datetime(1977, 6, 7, 2, 0)}) |
110 cnx.execute("INSERT Personne X: X nom 'boby', X tzdatenaiss %(date)s", |
106 datenaiss = self.execute("Any XD WHERE X nom 'boby', X tzdatenaiss XD")[0][0] |
111 {'date': datetime(1977, 6, 7, 2, 0)}) |
107 self.assertEqual(datenaiss.tzinfo, None) |
112 datenaiss = cnx.execute("Any XD WHERE X nom 'boby', X tzdatenaiss XD")[0][0] |
108 self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0)) |
113 self.assertEqual(datenaiss.tzinfo, None) |
|
114 self.assertEqual(datenaiss.utctimetuple()[:5], (1977, 6, 7, 2, 0)) |
109 |
115 |
110 if __name__ == '__main__': |
116 if __name__ == '__main__': |
111 from logilab.common.testlib import unittest_main |
117 from logilab.common.testlib import unittest_main |
112 unittest_main() |
118 unittest_main() |