test_nested_views.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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. # Find project with teams
  17. teams = res.json()[0]["teams"] or res.json()[1]["teams"]
  18. self.assertIsInstance(teams[0]["id"], str)
  19. def test_organization_projects_list_query(self):
  20. other_team = baker.make("teams.Team", organization=self.organization)
  21. other_team.members.add(self.org_user)
  22. other_project = baker.make("projects.Project", organization=self.organization)
  23. other_project.teams.add(other_team)
  24. res = self.client.get(self.url + "?query=team:" + self.team.slug)
  25. self.assertContains(res, self.team.slug)
  26. self.assertNotContains(res, other_team.slug)
  27. res = self.client.get(self.url + "?query=!team:" + self.team.slug)
  28. self.assertNotContains(res, self.team.slug)
  29. self.assertContains(res, other_team.slug)