Skip to content

Commit 36a73d0

Browse files
committed
Add namespace filter in packages api
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent d72c3b9 commit 36a73d0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

vulnerabilities/api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,15 @@ class PackageFilterSet(filters.FilterSet):
190190

191191
class Meta:
192192
model = Package
193-
fields = ["name", "type", "version", "subpath", "purl", "packagerelatedvulnerability__fix"]
193+
fields = [
194+
"name",
195+
"type",
196+
"version",
197+
"subpath",
198+
"purl",
199+
"namespace",
200+
"packagerelatedvulnerability__fix",
201+
]
194202

195203
def filter_purl(self, queryset, name, value):
196204
purl = unquote(value)

vulnerabilities/tests/test_fix_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ def test_api_response(self):
160160
response = self.csrf_client.get("/api/packages/", format="json").data
161161
self.assertEqual(response["count"], 11)
162162

163+
def test_api_with_namespace_filter(self):
164+
response = self.csrf_client.get("/api/packages/?namespace=nginx", format="json").data
165+
self.assertEqual(response["count"], 11)
166+
167+
def test_api_with_wrong_namespace_filter(self):
168+
response = self.csrf_client.get("/api/packages/?namespace=foo-bar", format="json").data
169+
self.assertEqual(response["count"], 0)
170+
163171
def test_api_with_single_vulnerability_and_fixed_package(self):
164172
response = self.csrf_client.get(f"/api/packages/{self.package.id}", format="json").data
165173
assert response == {

0 commit comments

Comments
 (0)