From 11b1cfa9afa2e66096c2361781e6fe37f196d0f0 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Tue, 4 Jun 2019 09:40:25 -0700 Subject: [PATCH] feat(api): Add searching for org projects by slug(s) (#13513) This allows the organization projects API to search for projects by slug(s). --- .../api/endpoints/organization_projects.py | 2 ++ .../api/endpoints/test_organization_projects.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/sentry/api/endpoints/organization_projects.py b/src/sentry/api/endpoints/organization_projects.py index e4a38393d361e7..a6037b1a2d200d 100644 --- a/src/sentry/api/endpoints/organization_projects.py +++ b/src/sentry/api/endpoints/organization_projects.py @@ -106,6 +106,8 @@ def get(self, request, organization): queryset = queryset.filter(Q(name__icontains=value) | Q(slug__icontains=value)) elif key == 'id': queryset = queryset.filter(id__in=value) + elif key == 'slug': + queryset = queryset.filter(slug__in=value) elif key == "team": team_list = list(Team.objects.filter(slug__in=value)) queryset = queryset.filter(teams__in=team_list) diff --git a/tests/sentry/api/endpoints/test_organization_projects.py b/tests/sentry/api/endpoints/test_organization_projects.py index b61ffa9a51f7b3..0b80017b07540d 100644 --- a/tests/sentry/api/endpoints/test_organization_projects.py +++ b/tests/sentry/api/endpoints/test_organization_projects.py @@ -81,6 +81,22 @@ def test_search_by_ids(self): self.check_valid_response(response, [project_bar, project_foo]) + def test_search_by_slugs(self): + self.login_as(user=self.user) + + project_bar = self.create_project(teams=[self.team], name='bar', slug='bar') + project_foo = self.create_project(teams=[self.team], name='foo', slug='foo') + self.create_project(teams=[self.team], name='baz', slug='baz') + + path = u'{}?query=slug:{}'.format(self.path, project_foo.slug) + response = self.client.get(path) + self.check_valid_response(response, [project_foo]) + + path = u'{}?query=slug:{} slug:{}'.format(self.path, project_bar.slug, project_foo.slug) + response = self.client.get(path) + + self.check_valid_response(response, [project_bar, project_foo]) + def test_bookmarks_appear_first_across_pages(self): self.login_as(user=self.user)