test_deletes.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import time
  2. from datetime import datetime, timedelta
  3. from uuid import uuid4
  4. import pytest
  5. from snuba_sdk import DeleteQuery, Request
  6. from sentry.snuba.dataset import Dataset, StorageKey
  7. from sentry.testutils.cases import SnubaTestCase, TestCase
  8. from sentry.utils import snuba
  9. class SnubaTest(TestCase, SnubaTestCase):
  10. @pytest.mark.xfail
  11. def test_basic(self) -> None:
  12. # insert a new issue
  13. now = datetime.now()
  14. id = uuid4()
  15. issue = (
  16. 2,
  17. "insert",
  18. {
  19. "group_id": 1,
  20. "message": "message",
  21. "platform": "python",
  22. "primary_hash": "1" * 32,
  23. "event_id": "a" * 32,
  24. "project_id": self.project.id,
  25. "datetime": now.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
  26. "data": {"received": time.mktime(now.timetuple())},
  27. "occurrence_data": {
  28. "detection_time": time.mktime(now.timetuple()),
  29. "fingerprint": ["hi"],
  30. "issue_title": "myissue",
  31. "id": id,
  32. "type": 1,
  33. },
  34. "organization_id": 6,
  35. },
  36. )
  37. self.store_issues([issue])
  38. # make sure its there
  39. assert snuba.query(
  40. dataset=Dataset.IssuePlatform,
  41. start=now - timedelta(days=1),
  42. end=now + timedelta(days=1),
  43. groupby=["project_id"],
  44. filter_keys={"project_id": [self.project.id]},
  45. referrer="testing.test",
  46. tenant_ids={"referrer": "testing.test", "organization_id": 1},
  47. ) == {self.project.id: 1}
  48. # delete it
  49. req = Request(
  50. dataset=Dataset.IssuePlatform.value,
  51. app_id="my_app",
  52. query=DeleteQuery(
  53. StorageKey.SearchIssues.value,
  54. {"project_id": [self.project.id], "occurrence_id": [str(id)]},
  55. ),
  56. tenant_ids={"referrer": "testing.test", "organization_id": 1},
  57. )
  58. snuba.raw_snql_query(req)
  59. # make sure its gone
  60. time.sleep(5) # test will currently fail without the sleep (maybe it take time to delete?)
  61. assert (
  62. snuba.query(
  63. dataset=Dataset.IssuePlatform,
  64. start=now - timedelta(days=1),
  65. end=now + timedelta(days=1),
  66. groupby=["project_id"],
  67. filter_keys={"project_id": [self.project.id]},
  68. referrer="testing.test",
  69. tenant_ids={"referrer": "testing.test", "organization_id": 1},
  70. )
  71. == {}
  72. )