test_nested_views.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. from django.test import TestCase
  2. from django.urls import reverse
  3. from model_bakery import baker
  4. from glitchtip.test_utils.test_case import GlitchTipTestCaseMixin
  5. class OrganizationProjectsViewTestCase(GlitchTipTestCaseMixin, TestCase):
  6. def setUp(self):
  7. self.create_logged_in_user()
  8. self.url = reverse(
  9. "api:list_organization_projects", args=[self.organization.slug]
  10. )
  11. def test_organization_projects_list(self):
  12. with self.assertNumQueries(2):
  13. res = self.client.get(self.url)
  14. self.assertNotContains(res, self.organization.slug)
  15. self.assertContains(res, self.team.slug)
  16. def test_organization_projects_list_query(self):
  17. other_team = baker.make("teams.Team", organization=self.organization)
  18. other_team.members.add(self.org_user)
  19. other_project = baker.make("projects.Project", organization=self.organization)
  20. other_project.teams.add(other_team)
  21. res = self.client.get(self.url + "?query=team:" + self.team.slug)
  22. self.assertContains(res, self.team.slug)
  23. self.assertNotContains(res, other_team.slug)
  24. res = self.client.get(self.url + "?query=!team:" + self.team.slug)
  25. self.assertNotContains(res, self.team.slug)
  26. self.assertContains(res, other_team.slug)