mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
Fix tests (were rightfully failing on system with clock set to utc)
This commit is contained in:
parent
9379f76562
commit
d9964d84b3
@ -125,7 +125,7 @@ class QueryResult(BaseModel):
|
||||
query_hash = utils.gen_query_hash(query)
|
||||
|
||||
query = cls.select().where(cls.query_hash == query_hash, cls.data_source == data_source,
|
||||
peewee.SQL("retrieved_at + interval '%s second' > now() at time zone 'utc'", ttl)).order_by(cls.retrieved_at.desc())
|
||||
peewee.SQL("retrieved_at + interval '%s second' >= now() at time zone 'utc'", ttl)).order_by(cls.retrieved_at.desc())
|
||||
|
||||
return query.first()
|
||||
|
||||
|
@ -65,7 +65,7 @@ query_factory = ModelFactory(redash.models.Query,
|
||||
query_result_factory = ModelFactory(redash.models.QueryResult,
|
||||
data='{"columns":{}, "rows":[]}',
|
||||
runtime=1,
|
||||
retrieved_at=datetime.datetime.now(),
|
||||
retrieved_at=datetime.datetime.utcnow,
|
||||
query="SELECT 1",
|
||||
query_hash=gen_query_hash('SELECT 1'),
|
||||
data_source=data_source_factory.create)
|
||||
|
@ -35,24 +35,25 @@ class QueryResultTest(BaseTestCase):
|
||||
|
||||
def test_get_latest_returns_none_if_not_found(self):
|
||||
ds = data_source_factory.create()
|
||||
models.QueryResult.get_latest(ds, "SELECT 1")
|
||||
found_query_result = models.QueryResult.get_latest(ds, "SELECT 1", 60)
|
||||
self.assertIsNone(found_query_result)
|
||||
|
||||
def test_get_latest_returns_when_found(self):
|
||||
qr = query_result_factory.create()
|
||||
found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query)
|
||||
found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query, 60)
|
||||
|
||||
self.assertEqual(qr, found_query_result)
|
||||
|
||||
def test_get_latest_works_with_data_source_id(self):
|
||||
qr = query_result_factory.create()
|
||||
found_query_result = models.QueryResult.get_latest(qr.data_source.id, qr.query)
|
||||
found_query_result = models.QueryResult.get_latest(qr.data_source.id, qr.query, 60)
|
||||
|
||||
self.assertEqual(qr, found_query_result)
|
||||
|
||||
def test_get_latest_doesnt_return_query_from_different_data_source(self):
|
||||
qr = query_result_factory.create()
|
||||
data_source = data_source_factory.create()
|
||||
found_query_result = models.QueryResult.get_latest(data_source, qr.query)
|
||||
found_query_result = models.QueryResult.get_latest(data_source, qr.query, 60)
|
||||
|
||||
self.assertIsNone(found_query_result)
|
||||
|
||||
@ -77,6 +78,6 @@ class QueryResultTest(BaseTestCase):
|
||||
old_qr = query_result_factory.create(retrieved_at=yesterday)
|
||||
qr = query_result_factory.create()
|
||||
|
||||
found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query)
|
||||
found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query, 60)
|
||||
|
||||
self.assertEqual(found_query_result.id, qr.id)
|
Loading…
Reference in New Issue
Block a user