|
| 1 | +import json |
| 2 | + |
| 3 | +from django.test import Client, TestCase |
| 4 | + |
| 5 | +from app.models.app import App |
| 6 | +from app.models.conference import Conference |
| 7 | +from app.models.issue import Issue |
| 8 | +from app.models.organization import Organization |
| 9 | +from app.models.participant import Participant |
| 10 | +from app.models.session import Session |
| 11 | + |
| 12 | + |
| 13 | +class PR26RegressionTests(TestCase): |
| 14 | + def setUp(self): |
| 15 | + self.client = Client() |
| 16 | + self.organization = Organization.objects.create(name="Test Org") |
| 17 | + self.app = App.objects.create( |
| 18 | + name="Test App", |
| 19 | + api_key="a" * 32, |
| 20 | + organization=self.organization, |
| 21 | + ) |
| 22 | + |
| 23 | + def _make_conference_graph(self, conference_id): |
| 24 | + conference = Conference.objects.create( |
| 25 | + conference_id=conference_id, |
| 26 | + app=self.app, |
| 27 | + ) |
| 28 | + participant = Participant.objects.create( |
| 29 | + participant_id=f"{conference_id}-participant", |
| 30 | + app=self.app, |
| 31 | + ) |
| 32 | + participant.conferences.add(conference) |
| 33 | + session = Session.objects.create( |
| 34 | + conference=conference, |
| 35 | + participant=participant, |
| 36 | + ) |
| 37 | + return conference, participant, session |
| 38 | + |
| 39 | + def test_conferences_issue_code_filter_returns_distinct_conferences(self): |
| 40 | + conference, participant, session = self._make_conference_graph("conf-1") |
| 41 | + |
| 42 | + Issue.objects.create( |
| 43 | + session=session, |
| 44 | + conference=conference, |
| 45 | + participant=participant, |
| 46 | + type=Issue.TYPES_OF_ISSUES["warning"], |
| 47 | + code="getusermedia_error", |
| 48 | + data={"name": "NotFoundError"}, |
| 49 | + ) |
| 50 | + Issue.objects.create( |
| 51 | + session=session, |
| 52 | + conference=conference, |
| 53 | + participant=participant, |
| 54 | + type=Issue.TYPES_OF_ISSUES["warning"], |
| 55 | + code="getusermedia_error", |
| 56 | + data={"name": "NotFoundError"}, |
| 57 | + ) |
| 58 | + |
| 59 | + response = self.client.get( |
| 60 | + "/v1/conferences", |
| 61 | + { |
| 62 | + "appId": str(self.app.id), |
| 63 | + "issue_code": "getusermedia_error", |
| 64 | + "limit": "50", |
| 65 | + }, |
| 66 | + ) |
| 67 | + |
| 68 | + self.assertEqual(response.status_code, 200) |
| 69 | + payload = json.loads(response.content) |
| 70 | + self.assertEqual(payload["count"], 1) |
| 71 | + self.assertEqual(len(payload["results"]), 1) |
| 72 | + self.assertEqual(payload["results"][0]["id"], str(conference.id)) |
| 73 | + |
| 74 | + def test_conferences_issue_code_filter_ignores_inactive_issues(self): |
| 75 | + conference_active, participant_active, session_active = self._make_conference_graph("conf-active") |
| 76 | + conference_inactive, participant_inactive, session_inactive = self._make_conference_graph("conf-inactive") |
| 77 | + |
| 78 | + Issue.objects.create( |
| 79 | + session=session_active, |
| 80 | + conference=conference_active, |
| 81 | + participant=participant_active, |
| 82 | + type=Issue.TYPES_OF_ISSUES["warning"], |
| 83 | + code="getusermedia_error", |
| 84 | + data={"name": "NotFoundError"}, |
| 85 | + is_active=True, |
| 86 | + ) |
| 87 | + Issue.objects.create( |
| 88 | + session=session_inactive, |
| 89 | + conference=conference_inactive, |
| 90 | + participant=participant_inactive, |
| 91 | + type=Issue.TYPES_OF_ISSUES["warning"], |
| 92 | + code="getusermedia_error", |
| 93 | + data={"name": "NotReadableError"}, |
| 94 | + is_active=False, |
| 95 | + ) |
| 96 | + |
| 97 | + response = self.client.get( |
| 98 | + "/v1/conferences", |
| 99 | + { |
| 100 | + "appId": str(self.app.id), |
| 101 | + "issue_code": "getusermedia_error", |
| 102 | + "limit": "50", |
| 103 | + }, |
| 104 | + ) |
| 105 | + |
| 106 | + self.assertEqual(response.status_code, 200) |
| 107 | + payload = json.loads(response.content) |
| 108 | + returned_ids = {row["id"] for row in payload["results"]} |
| 109 | + self.assertEqual(returned_ids, {str(conference_active.id)}) |
| 110 | + self.assertEqual(payload["count"], 1) |
| 111 | + |
| 112 | + def test_gum_summary_skips_non_dict_issue_data(self): |
| 113 | + conference, participant, session = self._make_conference_graph("conf-gum") |
| 114 | + |
| 115 | + Issue.objects.create( |
| 116 | + session=session, |
| 117 | + conference=conference, |
| 118 | + participant=participant, |
| 119 | + type=Issue.TYPES_OF_ISSUES["warning"], |
| 120 | + code="getusermedia_error", |
| 121 | + data={"name": "NotAllowedError", "message": "Permission denied"}, |
| 122 | + ) |
| 123 | + Issue.objects.create( |
| 124 | + session=session, |
| 125 | + conference=conference, |
| 126 | + participant=participant, |
| 127 | + type=Issue.TYPES_OF_ISSUES["warning"], |
| 128 | + code="getusermedia_error", |
| 129 | + data="malformed", |
| 130 | + ) |
| 131 | + |
| 132 | + response = self.client.get( |
| 133 | + "/v1/issues/gum-summary", |
| 134 | + { |
| 135 | + "appId": str(self.app.id), |
| 136 | + }, |
| 137 | + ) |
| 138 | + |
| 139 | + self.assertEqual(response.status_code, 200) |
| 140 | + payload = json.loads(response.content) |
| 141 | + self.assertEqual(payload["total"], 1) |
| 142 | + self.assertEqual(payload["data"][0]["name"], "NotAllowedError") |
| 143 | + self.assertEqual(payload["data"][0]["count"], 1) |
0 commit comments