def _get_payload(query, query_id, dates, opts): """ Create the Payload :param query: Query string :param dates: from -> Date from :param dates: to -> Date to :param opts: response -> response of the output :param opts: limit -> limit of rows for response :param opts: offset -> number, set the start of response :param opts: destination -> Destination for the results :return: Return the formed payload """ date_from = default_from(dates['from']) date_to = default_to(dates['to']) if dates['to'] is not None else None payload = { "from": int(date_from / 1000) if isinstance(date_from, (int, float)) else date_from, "to": int(date_to / 1000) if isinstance(date_to, (int, float)) else date_to, "mode": { "type": opts['response'] } } if dates.get("timeZone"): payload['timeZone'] = dates.get("timeZone") if query: payload['query'] = query if query_id: payload['queryId'] = query_id if opts['limit']: payload['limit'] = opts['limit'] if opts['offset']: payload['offset'] = opts['offset'] if opts["destination"]: payload['destination'] = opts['destination'] return json.dumps(payload)
def test_yesterday(self): ts1 = default_from('yesterday()') tmp = dt.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) ts2 = int((tmp - self.epoch).total_seconds() * 1000) - 86400000 self.assertTrue(ts1 == ts2)
def test_now(self): ts1 = default_from('now()') ts2 = int((dt.utcnow() - self.epoch).total_seconds() * 1000) self.assertTrue(ts1 == ts2)
def test_month(self): ts1 = default_from('month()') ts2 = 30 * 24 * 60 * 60 * 1000 self.assertTrue(ts1 == ts2)
def test_week(self): ts1 = default_from('week()') ts2 = 7 * 24 * 60 * 60 * 1000 self.assertTrue(ts1 == ts2)
def test_day(self): ts1 = default_from('day()') ts2 = 24 * 60 * 60 * 1000 self.assertTrue(ts1 == ts2)
def test_hour(self): ts1 = default_from('hour()') ts2 = 60 * 60 * 1000 self.assertTrue(ts1 == ts2)
def test_minute(self): ts1 = default_from('minute()') ts2 = 60 * 1000 self.assertTrue(ts1 == ts2)
def test_second(self): ts1 = default_from('second()') ts2 = 1000 self.assertTrue(ts1 == ts2)
def test_default_from(self): ts1 = str(default_from())[:11] ts2 = str( int((dt.utcnow() - self.epoch).total_seconds() * 1000) - 86400000)[:11] self.assertTrue(ts1 == ts2)
def test_default_from(self): ts1 = default_from() ts2 = int((dt.utcnow() - self.epoch).total_seconds() * 1000) - 86400000 self.assertTrue(ts1 == ts2)