Example #1
0
    def test_rqlpath_range(self):
        with self.admin_access.web_request() as req:
            rset, rqlst, filtered_variable = self.prepare_rqlst(req)

            class RRF(facet.DateRangeRQLPathFacet):
                path = [('X created_by U'), ('U owned_by O'),
                        ('O creation_date OL')]
                filter_variable = 'OL'

            f = RRF(req,
                    rset=rset,
                    select=rqlst.children[0],
                    filtered_variable=filtered_variable)
            mind, maxd = req.cnx.execute(
                'Any MIN(CD), MAX(CD) WHERE X is CWUser, X created_by U, U owned_by O, O creation_date CD'
            )[0]
            self.assertEqual(f.vocabulary(), [(str(mind), mind),
                                              (str(maxd), maxd)])
            # ensure rqlst is left unmodified
            self.assertEqual(rqlst.as_string(),
                             'DISTINCT Any  WHERE X is CWUser')
            self.assertEqual(f.possible_values(), [str(mind), str(maxd)])
            # ensure rqlst is left unmodified
            self.assertEqual(rqlst.as_string(),
                             'DISTINCT Any  WHERE X is CWUser')
            req.form['%s_inf' % f.__regid__] = str(datetime2ticks(mind))
            req.form['%s_sup' % f.__regid__] = str(datetime2ticks(mind))
            f.add_rql_restrictions()
            # selection is cluttered because rqlst has been prepared for facet (it
            # is not in real life)
            self.assertEqual(
                f.select.as_string(),
                'DISTINCT Any  WHERE X is CWUser, X created_by G, G owned_by H, H creation_date >= "%s", '
                'H creation_date <= "%s"' %
                (mind.strftime('%Y/%m/%d'), mind.strftime('%Y/%m/%d')))
Example #2
0
 def test_daterange(self):
     with self.admin_access.web_request() as req:
         rset, rqlst, filtered_variable = self.prepare_rqlst(req)
         f = facet.DateRangeFacet(req,
                                  rset=rset,
                                  select=rqlst.children[0],
                                  filtered_variable=filtered_variable)
         f.rtype = 'creation_date'
         mind, maxd = req.cnx.execute(
             'Any MIN(CD), MAX(CD) WHERE X is CWUser, X creation_date CD'
         )[0]
         self.assertEqual(f.vocabulary(), [(str(mind), mind),
                                           (str(maxd), maxd)])
         # ensure rqlst is left unmodified
         self.assertEqual(rqlst.as_string(),
                          'DISTINCT Any  WHERE X is CWUser')
         #rqlst = rset.syntax_tree()
         self.assertEqual(f.possible_values(), [str(mind), str(maxd)])
         # ensure rqlst is left unmodified
         self.assertEqual(rqlst.as_string(),
                          'DISTINCT Any  WHERE X is CWUser')
         req.form['%s_inf' % f.__regid__] = str(datetime2ticks(mind))
         req.form['%s_sup' % f.__regid__] = str(datetime2ticks(mind))
         f.add_rql_restrictions()
         # selection is cluttered because rqlst has been prepared for facet (it
         # is not in real life)
         self.assertEqual(
             f.select.as_string(),
             'DISTINCT Any  WHERE X is CWUser, X creation_date >= "%s", '
             'X creation_date <= "%s"' %
             (mind.strftime('%Y/%m/%d'), mind.strftime('%Y/%m/%d')))
Example #3
0
 def dump_plot(self, ts):
     plot = [(datetime2ticks(x), y)
             for x, y in ts.compressed_timestamped_array()]
     return dumps(plot)
Example #4
0
 def test_datetime2ticks_date_argument(self):
     d = date(2014, 11, 26)
     timestamp = timegm(d.timetuple())
     self.assertEqual(datetime2ticks(d), timestamp * 1000)
Example #5
0
 def test_datetime2ticks(self):
     d = datetime(2014, 11, 26, 12, 0, 0, 57, tzinfo=pytz.utc)
     timestamp = timegm(d.timetuple())
     self.assertEqual(datetime2ticks(d), timestamp * 1000)
     d = d.replace(microsecond=123456)
     self.assertEqual(datetime2ticks(d), timestamp * 1000 + 123)