envelope endpoint tests: slight cleanup

This commit is contained in:
Klaas van Schelven
2025-11-05 11:20:30 +01:00
parent d807ea2c50
commit 2e2a8cfeeb

View File

@@ -21,6 +21,7 @@ from projects.models import Project
from events.factories import create_event_data, create_event from events.factories import create_event_data, create_event
from events.retention import evict_for_max_events from events.retention import evict_for_max_events
from events.storage_registry import override_event_storages from events.storage_registry import override_event_storages
from events.models import Event
from issues.factories import get_or_create_issue from issues.factories import get_or_create_issue
from issues.models import IssueStateManager, Issue, TurningPoint, TurningPointKind from issues.models import IssueStateManager, Issue, TurningPoint, TurningPointKind
from issues.utils import get_values from issues.utils import get_values
@@ -293,21 +294,11 @@ class IngestViewTestCase(TransactionTestCase):
sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }") sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }")
# first, we ingest many issues
command = SendJsonCommand()
command.stdout = io.StringIO()
command.stderr = io.StringIO()
SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples") SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples")
event_samples = glob(SAMPLES_DIR + "/sentry/mobile1-xen.json") # pick a fixed one for reproducibility filename = glob(SAMPLES_DIR + "/sentry/mobile1-xen.json")[0] # pick a fixed one for reproducibility
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in _readlines(SAMPLES_DIR + "/KNOWN-BROKEN")]
if len(event_samples) == 0: for i, include_event_id in enumerate([True, False]):
raise Exception(f"No event samples found in {SAMPLES_DIR}; I insist on having some to test with.")
for include_event_id in [True, False]:
for filename in [sample for sample in event_samples if sample not in known_broken][:1]: # one is enough
with open(filename) as f: with open(filename) as f:
data = json.loads(f.read()) data = json.loads(f.read())
@@ -337,6 +328,8 @@ class IngestViewTestCase(TransactionTestCase):
self.assertEqual( self.assertEqual(
200, response.status_code, response.content if response.status_code != 302 else response.url) 200, response.status_code, response.content if response.status_code != 302 else response.url)
self.assertEqual(1 + i, Event.objects.count())
@tag("samples") @tag("samples")
def test_envelope_endpoint_reused_ids_different_exceptions(self): def test_envelope_endpoint_reused_ids_different_exceptions(self):
# dirty copy/paste from test_envelope_endpoint, # dirty copy/paste from test_envelope_endpoint,
@@ -344,20 +337,10 @@ class IngestViewTestCase(TransactionTestCase):
sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }") sentry_auth_header = get_header_value(f"http://{ project.sentry_key }@hostisignored/{ project.id }")
# first, we ingest many issues
command = SendJsonCommand()
command.stdout = io.StringIO()
command.stderr = io.StringIO()
SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples") SAMPLES_DIR = os.getenv("SAMPLES_DIR", "../event-samples")
event_samples = glob(SAMPLES_DIR + "/sentry/mobile1-xen.json") # this one has 'exception.values[0].type' filename = glob(SAMPLES_DIR + "/sentry/mobile1-xen.json")[0] # this one has 'exception.values[0].type'
known_broken = [SAMPLES_DIR + "/" + s.strip() for s in _readlines(SAMPLES_DIR + "/KNOWN-BROKEN")]
if len(event_samples) == 0:
raise Exception(f"No event samples found in {SAMPLES_DIR}; I insist on having some to test with.")
for filename in [sample for sample in event_samples if sample not in known_broken][:1]: # one is enough
with open(filename) as f: with open(filename) as f:
data = json.loads(f.read()) data = json.loads(f.read())
data["event_id"] = uuid.uuid4().hex # we set it once, before the loop. data["event_id"] = uuid.uuid4().hex # we set it once, before the loop.