test_nested_views.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django.urls import reverse
  2. from model_bakery import baker
  3. from glitchtip.test_utils.test_case import GlitchTipTestCase
  4. from ..models import OrganizationUserRole
  5. class OrganizationProjectsViewTestCase(GlitchTipTestCase):
  6. def setUp(self):
  7. self.create_user_and_project()
  8. organization = baker.make("organizations_ext.Organization")
  9. organization.add_user(self.user, OrganizationUserRole.ADMIN)
  10. team = baker.make("teams.Team", organization=self.organization)
  11. team.members.add(self.org_user)
  12. self.project.team_set.add(team)
  13. self.url = reverse(
  14. "organization-projects-list",
  15. kwargs={"organization_slug": self.organization.slug},
  16. )
  17. def test_organization_projects_list(self):
  18. with self.assertNumQueries(8):
  19. res = self.client.get(self.url)
  20. self.assertContains(res, self.organization.slug)
  21. self.assertContains(res, self.team.slug)
  22. def test_organization_projects_list_query(self):
  23. other_team = baker.make("teams.Team", organization=self.organization)
  24. other_team.members.add(self.org_user)
  25. other_project = baker.make("projects.Project", organization=self.organization)
  26. other_project.team_set.add(other_team)
  27. res = self.client.get(self.url + "?query=team:" + self.team.slug)
  28. self.assertContains(res, self.team.slug)
  29. self.assertNotContains(res, other_team.slug)
  30. res = self.client.get(self.url + "?query=!team:" + self.team.slug)
  31. self.assertNotContains(res, self.team.slug)
  32. self.assertContains(res, other_team.slug)