test_api_permissions.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. from django.urls import reverse
  2. from model_bakery import baker
  3. from glitchtip.test_utils.test_case import APIPermissionTestCase
  4. class UserReportAPIPermissionTests(APIPermissionTestCase):
  5. def setUp(self):
  6. self.create_user_org()
  7. self.set_client_credentials(self.auth_token.token)
  8. self.team = baker.make("teams.Team", organization=self.organization)
  9. self.team.members.add(self.org_user)
  10. self.project = baker.make("projects.Project", organization=self.organization)
  11. self.project.team_set.add(self.team)
  12. self.issue = baker.make("issues.Issue", project=self.project)
  13. self.user_report = baker.make(
  14. "user_reports.UserReport", project=self.project, issue=self.issue
  15. )
  16. self.list_url = reverse(
  17. "issue-user-reports-list", kwargs={"issue_pk": self.issue.pk}
  18. )
  19. self.detail_url = reverse(
  20. "issue-user-reports-detail",
  21. kwargs={"issue_pk": self.issue.pk, "pk": self.user_report.pk},
  22. )
  23. def test_list(self):
  24. self.assertGetReqStatusCode(self.list_url, 403)
  25. self.auth_token.add_permission("event:read")
  26. self.assertGetReqStatusCode(self.list_url, 200)
  27. def test_retrieve(self):
  28. self.assertGetReqStatusCode(self.detail_url, 403)
  29. self.auth_token.add_permission("event:read")
  30. self.assertGetReqStatusCode(self.detail_url, 200)