| |
@@ -0,0 +1,59 @@
|
| |
+ From 6c127384b76f7534592dcb0d791f9580981f1afd Mon Sep 17 00:00:00 2001
|
| |
+ From: Lukas Holecek <hluk@email.cz>
|
| |
+ Date: Wed, 31 Jul 2019 10:25:43 +0200
|
| |
+ Subject: [PATCH] Fix start with delta parameter
|
| |
+
|
| |
+ Fixes #218
|
| |
+
|
| |
+ Signed-off-by: Lukas Holecek <hluk@email.cz>
|
| |
+ ---
|
| |
+ datagrepper/util.py | 3 ++-
|
| |
+ tests/test_api.py | 14 ++++++++++++++
|
| |
+ 2 files changed, 16 insertions(+), 1 deletion(-)
|
| |
+
|
| |
+ diff --git a/datagrepper/util.py b/datagrepper/util.py
|
| |
+ index 9696fef..330b12a 100644
|
| |
+ --- a/datagrepper/util.py
|
| |
+ +++ b/datagrepper/util.py
|
| |
+ @@ -54,7 +54,8 @@ def assemble_timerange(start, end, delta):
|
| |
+ if start is None:
|
| |
+ end = float(now)
|
| |
+ else:
|
| |
+ - end = float(start) + float(delta)
|
| |
+ + start = float(start)
|
| |
+ + end = start + float(delta)
|
| |
+
|
| |
+ end = datetime.fromtimestamp(float(end))
|
| |
+
|
| |
+ diff --git a/tests/test_api.py b/tests/test_api.py
|
| |
+ index fa731ea..5f49f44 100644
|
| |
+ --- a/tests/test_api.py
|
| |
+ +++ b/tests/test_api.py
|
| |
+ @@ -1,6 +1,7 @@
|
| |
+ # SPDX-License-Identifier: GPL-2.0+
|
| |
+ # Copyright 2018 Mike Bonnet <mikeb@redhat.com>
|
| |
+
|
| |
+ +from datetime import datetime, timedelta
|
| |
+ import json
|
| |
+ import os
|
| |
+ import unittest
|
| |
+ @@ -47,6 +48,19 @@ def test_raw_contains_delta(self, grep):
|
| |
+ resp = self.client.get('/raw?delta=14400&category=wat&contains=foo')
|
| |
+ self.assertEqual(resp.status_code, 200)
|
| |
+
|
| |
+ + @patch('datagrepper.app.dm.Message.grep', return_value=(0, 0, []))
|
| |
+ + def test_raw_contains_delta_and_start(self, grep):
|
| |
+ + resp = self.client.get('/raw?start=1564503781&delta=600')
|
| |
+ + self.assertEqual(resp.status_code, 200)
|
| |
+ + self.assertEqual(grep.call_args[0], ())
|
| |
+ + kws = grep.call_args[1]
|
| |
+ +
|
| |
+ + expected_start = datetime.fromtimestamp(1564503781)
|
| |
+ + self.assertEqual(kws['start'], expected_start)
|
| |
+ +
|
| |
+ + expected_end = expected_start + timedelta(seconds=600)
|
| |
+ + self.assertEqual(kws['end'], expected_end)
|
| |
+ +
|
| |
+ @patch('datagrepper.app.dm.Message.grep', return_value=(0, 0, []))
|
| |
+ def test_raw_contains_without_delta(self, grep):
|
| |
+ """ https://github.com/fedora-infra/datagrepper/issues/206 """
|
| |
Backport of upstream fix https://github.com/fedora-infra/datagrepper/issues/218