|
@@ -3,9 +3,11 @@ import uuid
|
|
|
from datetime import datetime, timedelta
|
|
|
from typing import Optional
|
|
|
|
|
|
+from django.utils import timezone
|
|
|
from snuba_sdk.column import Column
|
|
|
from snuba_sdk.conditions import Condition, Op
|
|
|
from snuba_sdk.entity import Entity
|
|
|
+from snuba_sdk.expressions import Limit
|
|
|
from snuba_sdk.function import Function
|
|
|
from snuba_sdk.query import Query
|
|
|
|
|
@@ -56,3 +58,22 @@ class SnQLTest(TestCase, SnubaTestCase):
|
|
|
result = snuba.raw_snql_query(query)
|
|
|
assert len(result["data"]) == 1
|
|
|
assert result["data"][0] == {"count": 1, "project_id": self.project.id}
|
|
|
+
|
|
|
+ def test_cache(self):
|
|
|
+ """Minimal test to verify if use_cache works"""
|
|
|
+ results = snuba.raw_snql_query(
|
|
|
+ Query(
|
|
|
+ "events",
|
|
|
+ Entity("events"),
|
|
|
+ select=[Column("event_id")],
|
|
|
+ where=[
|
|
|
+ Condition(Column("project_id"), Op.EQ, self.project.id),
|
|
|
+ Condition(Column("timestamp"), Op.GTE, timezone.now() - timedelta(days=1)),
|
|
|
+ Condition(Column("timestamp"), Op.LT, timezone.now()),
|
|
|
+ ],
|
|
|
+ limit=Limit(1),
|
|
|
+ ),
|
|
|
+ use_cache=True,
|
|
|
+ )
|
|
|
+
|
|
|
+ assert results["data"] == []
|