Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
CMFTopic.tests.test_DateC.FriendlyDateCriterionFunctionalTests Class Reference
Collaboration diagram for CMFTopic.tests.test_DateC.FriendlyDateCriterionFunctionalTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def beforeTearDown
def test_Harness
def test_WithinDayAgo
def test_WithinDayAhead
def test_MoreThanDaysAgo
def test_MoreThanZeroDaysAgo
def test_MoreThanDaysAhead
def test_MoreThanZeroDaysAhead
def test_LessThanDaysAgo
def test_LessThanZeroDaysAgo
def test_LessThanDaysAhead
def test_LessThanZeroDaysAhead

Public Attributes

 site
 topic
 criterion
 now

Static Public Attributes

 layer = FunctionalLayer
list selectable_diffs = [0, 1, 2, 5, 7, 14, 31, 93, 186, 365, 730]
list nonzero_diffs = [1, 2, 5, 7, 14, 31, 93, 186, 365, 730]
list day_diffs = [-730, -365, -186, -93, -31, -14, -7, -5, -2, -1]

Private Attributes

 _old_as_of

Detailed Description

Definition at line 166 of file test_DateC.py.


Member Function Documentation

Definition at line 176 of file test_DateC.py.

00176 
00177     def afterSetUp(self):
00178         setSite(self.app.site)
00179         self.site = self.app.site
00180         self.site._setObject( 'topic', Topic('topic') )
00181         self.topic = self.site.topic
00182         self.topic.addCriterion('modified', 'Friendly Date Criterion')
00183         self.topic.addCriterion('portal_type', 'String Criterion')
00184         type_crit = self.topic.getCriterion('portal_type')
00185         type_crit.edit(value='Dummy Content')
00186         self.criterion = self.topic.getCriterion('modified')
00187         self.now = DateTime()
00188         self._old_as_of = _replace_DC__as_of(lambda: self.now)
00189 
00190         for i in self.day_diffs:
00191             dummy_id = 'dummy%i' % i
00192             self.site._setObject( dummy_id, DummyContent( id=dummy_id
00193                                                         , catalog=1
00194                                                         ) )
00195             dummy_ob = getattr(self.site, dummy_id)
00196             dummy_ob.modified_date = self.now + i
00197             dummy_ob.reindexObject()

Definition at line 198 of file test_DateC.py.

00198 
00199     def beforeTearDown(self):
00200         _replace_DC__as_of(self._old_as_of)

Here is the call graph for this function:

Definition at line 201 of file test_DateC.py.

00201 
00202     def test_Harness(self):
00203         # Make sure the test harness is set up OK
00204         ob_values = self.site.objectValues(['Dummy'])
00205         self.assertEqual(len(ob_values), len(self.day_diffs))
00206 
00207         catalog_results = self.site.portal_catalog(portal_type='Dummy Content')
00208         self.assertEqual(len(catalog_results), len(self.day_diffs))

Definition at line 315 of file test_DateC.py.

00315 
00316     def test_LessThanDaysAgo(self):
00317         # What items are modified "Less than X days ago"
00318         resultset_size = 2
00319 
00320         for diff in self.nonzero_diffs:
00321             self.criterion.edit( value=diff
00322                                , operation='max'
00323                                , daterange='old'
00324                                )
00325             results = self.topic.queryCatalog()
00326 
00327             # With this query we are looking for items modified "less than
00328             # X days ago", meaning between the given time and now. As we move
00329             # through the selectable day values we increase the range to
00330             # search through and thus increase the resultset size.
00331             self.assertEquals(len(results), resultset_size)
00332             for brain in results:
00333                 self.failUnless(self.now-diff <= brain.modified <= self.now)
00334 
00335             resultset_size += 1

Definition at line 352 of file test_DateC.py.

00352 
00353     def test_LessThanDaysAhead(self):
00354         # What items are modified "Less than X days ahead"
00355         resultset_size = 2
00356 
00357         for diff in self.nonzero_diffs:
00358             self.criterion.edit( value=diff
00359                                , operation='max'
00360                                , daterange='ahead'
00361                                )
00362             results = self.topic.queryCatalog()
00363 
00364             # With this query we are looking for items modified "less than
00365             # X days ahead", meaning between now and the given time. As we move
00366             # through the selectable day values we increase the range to
00367             # search through and thus increase the resultset size.
00368             self.assertEquals(len(results), resultset_size)
00369             for brain in results:
00370                 self.failUnless(self.now+diff >= brain.modified >= self.now)
00371 
00372             resultset_size += 1

Definition at line 336 of file test_DateC.py.

00336 
00337     def test_LessThanZeroDaysAgo(self):
00338         # What items are modified "Less than 0 days ago"?
00339         # This represents a special case. The "special munging"
00340         # that corrects the query terms to what a human would expect
00341         # are not applied and the search is a simple
00342         # "everything in the past" search.
00343         resultset_size = len(self.selectable_diffs)
00344         self.criterion.edit( value=0
00345                            , operation='max'
00346                            , daterange='old'
00347                            )
00348         results = self.topic.queryCatalog()
00349         self.assertEquals(len(results), resultset_size)
00350         for brain in results:
00351             self.failUnless(brain.modified <= self.now)

Definition at line 373 of file test_DateC.py.

00373 
00374     def test_LessThanZeroDaysAhead(self):
00375         # What items are modified "Less than 0 days ahead"?
00376         # This represents a special case. The "special munging"
00377         # that corrects the query terms to what a human would expect
00378         # are not applied and the search is a simple
00379         # "everything in the past" search.
00380         resultset_size = len(self.selectable_diffs)
00381         self.criterion.edit( value=0
00382                            , operation='max'
00383                            , daterange='ahead'
00384                            )
00385         results = self.topic.queryCatalog()
00386         self.assertEquals(len(results), resultset_size)
00387         for brain in results:
00388             self.failUnless(brain.modified <= self.now)
00389 

Definition at line 239 of file test_DateC.py.

00239 
00240     def test_MoreThanDaysAgo(self):
00241         # What items are modified "More than X days ago"
00242         resultset_size = len(self.nonzero_diffs)
00243 
00244         for diff in self.nonzero_diffs:
00245             self.criterion.edit( value=diff
00246                                , operation='min'
00247                                , daterange='old'
00248                                )
00249             results = self.topic.queryCatalog()
00250 
00251             # As we move up in our date difference range, we must find as
00252             # many items as we have "modified" values <= the current value
00253             # in our sequence of user-selectable time differences. As we
00254             # increase the "value", we actually move backwards in time, so
00255             # the expected count of results *decreases*
00256             self.assertEquals(len(results), resultset_size)
00257             for brain in results:
00258                 self.failUnless(brain.modified <= self.now-diff)
00259 
00260             resultset_size -= 1

Definition at line 277 of file test_DateC.py.

00277 
00278     def test_MoreThanDaysAhead(self):
00279         # What items are modified "More than X days ahead"
00280         resultset_size = len(self.nonzero_diffs)
00281 
00282         for diff in self.nonzero_diffs:
00283             self.criterion.edit( value=diff
00284                                , operation='min'
00285                                , daterange='ahead'
00286                                )
00287             results = self.topic.queryCatalog()
00288 
00289             # As we move up in our date difference range, we must find as
00290             # many items as we have "modified" values >= the current value
00291             # in our sequence of user-selectable time differences. As we
00292             # increase the "value", we actually move formward in time, so
00293             # the expected count of results *decreases*
00294             self.assertEquals(len(results), resultset_size)
00295             for brain in results:
00296                 self.failUnless(brain.modified >= self.now+diff)
00297 
00298             resultset_size -= 1

Definition at line 261 of file test_DateC.py.

00261 
00262     def test_MoreThanZeroDaysAgo(self):
00263         # What items are modified "More than 0 days ago"?
00264         # This represents a special case. The "special munging"
00265         # that corrects the query terms to what a human would expect
00266         # are not applied and the search is a simple
00267         # "everything in the future" search.
00268         resultset_size = len(self.selectable_diffs)
00269         self.criterion.edit( value=0
00270                            , operation='min'
00271                            , daterange='old'
00272                            )
00273         results = self.topic.queryCatalog()
00274         self.assertEquals(len(results), resultset_size)
00275         for brain in results:
00276             self.failUnless(brain.modified >= self.now)

Definition at line 299 of file test_DateC.py.

00299 
00300     def test_MoreThanZeroDaysAhead(self):
00301         # What items are modified "More than 0 days ahead"?
00302         # This represents a special case. The "special munging"
00303         # that corrects the query terms to what a human would expect
00304         # are not applied and the search is a simple
00305         # "everything in the future" search.
00306         resultset_size = len(self.selectable_diffs)
00307         self.criterion.edit( value=0
00308                            , operation='min'
00309                            , daterange='ahead'
00310                            )
00311         results = self.topic.queryCatalog()
00312         self.assertEquals(len(results), resultset_size)
00313         for brain in results:
00314             self.failUnless(brain.modified >= self.now)

Definition at line 209 of file test_DateC.py.

00209 
00210     def test_WithinDayAgo(self):
00211         # What items were modified "On the day X days ago"
00212         for diff in self.selectable_diffs:
00213             self.criterion.edit( value=abs(diff)
00214                                , operation='within_day'
00215                                , daterange='old'
00216                                )
00217             results = self.topic.queryCatalog()
00218 
00219             # There is only one item with an modified date for this day
00220             self.assertEquals(len(results), 1)
00221             self.assertEquals( results[0].modified.Date()
00222                              , (self.now-diff).Date()
00223                              )

Definition at line 224 of file test_DateC.py.

00224 
00225     def test_WithinDayAhead(self):
00226         # What items were modified "On the day X days ahead"
00227         for diff in self.selectable_diffs:
00228             self.criterion.edit( value=abs(diff)
00229                                , operation='within_day'
00230                                , daterange='ahead'
00231                                )
00232             results = self.topic.queryCatalog()
00233 
00234             # There is only one item with an modified date for this day
00235             self.assertEquals(len(results), 1)
00236             self.assertEquals( results[0].modified.Date()
00237                              , (self.now+diff).Date()
00238                              )


Member Data Documentation

Definition at line 187 of file test_DateC.py.

Definition at line 185 of file test_DateC.py.

list CMFTopic.tests.test_DateC.FriendlyDateCriterionFunctionalTests.day_diffs = [-730, -365, -186, -93, -31, -14, -7, -5, -2, -1] [static]

Definition at line 173 of file test_DateC.py.

Definition at line 168 of file test_DateC.py.

list CMFTopic.tests.test_DateC.FriendlyDateCriterionFunctionalTests.nonzero_diffs = [1, 2, 5, 7, 14, 31, 93, 186, 365, 730] [static]

Definition at line 172 of file test_DateC.py.

Definition at line 186 of file test_DateC.py.

list CMFTopic.tests.test_DateC.FriendlyDateCriterionFunctionalTests.selectable_diffs = [0, 1, 2, 5, 7, 14, 31, 93, 186, 365, 730] [static]

Definition at line 171 of file test_DateC.py.

Definition at line 178 of file test_DateC.py.

Definition at line 180 of file test_DateC.py.


The documentation for this class was generated from the following file: