1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import datetime
- from django.shortcuts import reverse
- from django.utils import timezone
- from model_bakery import baker
- from freezegun import freeze_time
- from glitchtip.test_utils.test_case import GlitchTipTestCase
- class TransactionAPITestCase(GlitchTipTestCase):
- def setUp(self):
- self.create_user_and_project()
- self.list_url = reverse(
- "organization-transactions-list",
- kwargs={"organization_slug": self.organization.slug},
- )
- def test_list(self):
- transaction = baker.make(
- "performance.TransactionEvent", group__project=self.project
- )
- res = self.client.get(self.list_url)
- self.assertContains(res, transaction.event_id)
- class TransactionGroupAPITestCase(GlitchTipTestCase):
- def setUp(self):
- self.create_user_and_project()
- self.list_url = reverse(
- "organization-transaction-groups-list",
- kwargs={"organization_slug": self.organization.slug},
- )
- def test_list(self):
- group = baker.make("performance.TransactionGroup", project=self.project)
- res = self.client.get(self.list_url)
- self.assertContains(res, group.transaction)
- def test_filter_then_average(self):
- group = baker.make("performance.TransactionGroup", project=self.project)
- now = timezone.now()
- last_minute = now - datetime.timedelta(minutes=1)
- with freeze_time(last_minute):
- transaction1 = baker.make(
- "performance.TransactionEvent",
- group=group,
- start_timestamp=last_minute,
- timestamp=last_minute + datetime.timedelta(seconds=5),
- )
- transaction2 = baker.make(
- "performance.TransactionEvent",
- group=group,
- start_timestamp=now,
- timestamp=now + datetime.timedelta(seconds=1),
- )
- res = self.client.get(self.list_url)
- self.assertEqual(res.data[0]["avgDuration"], "00:00:03")
- res = self.client.get(
- self.list_url
- + "?start="
- + transaction2.created.replace(microsecond=0)
- .replace(tzinfo=None)
- .isoformat()
- + "Z"
- )
- self.assertEqual(res.data[0]["avgDuration"], "00:00:01")
- class SpanAPITestCase(GlitchTipTestCase):
- def setUp(self):
- self.create_user_and_project()
- self.list_url = reverse(
- "organization-spans-list",
- kwargs={"organization_slug": self.organization.slug},
- )
- def test_list(self):
- span = baker.make("performance.Span", transaction__group__project=self.project)
- res = self.client.get(self.list_url)
- self.assertContains(res, span.op)
|