Skip to content

Commit

Permalink
Refine the generated schema for PurlValidateViewSet
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
  • Loading branch information
keshav-space committed Dec 19, 2023
1 parent fa2ecc5 commit 79d7aec
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
9 changes: 8 additions & 1 deletion packagedb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ class PurlValidateViewSet(viewsets.ViewSet):
`gem`, `golang`, `hex`, `maven`, `npm`, `nuget` and `pypi` ecosystems.
**Example request:**
```doc
```
GET /api/validate/?purl=pkg:npm/foobar@12.3.1&check_existence=false
```
Expand All @@ -735,6 +735,13 @@ class PurlValidateViewSet(viewsets.ViewSet):
def get_view_name(self):
return 'Validate PURL'

@extend_schema(
parameters=[
OpenApiParameter('purl', str, 'query', description='PackageURL'),
OpenApiParameter('check_existence', bool, 'query', description='Check existence', default=False),
],
responses={200: PurlValidateResponseSerializer()},
)
def list(self, request):
serializer = self.serializer_class(data=request.query_params)

Expand Down
20 changes: 10 additions & 10 deletions packagedb/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ def test_api_resource_checksum_filter(self):
self.resource1.name,
self.resource2.name,
])
self.assertEquals(expected_names, names)
self.assertEqual(expected_names, names)

filters = f'?sha1={self.resource1.sha1}&sha1={self.resource2.sha1}'
response = self.client.get(f'/api/resources/{filters}')
Expand All @@ -1106,7 +1106,7 @@ def test_api_resource_checksum_filter(self):
self.resource1.name,
self.resource2.name,
])
self.assertEquals(expected_names, names)
self.assertEqual(expected_names, names)

class PurlValidateApiTestCase(TestCase):

Expand Down Expand Up @@ -1140,15 +1140,15 @@ def test_api_purl_validation(self):
}
response2 = self.client.get(f"/api/validate/", data=data2)

self.assertEquals(True, response1.data["valid"])
self.assertEquals(True, response1.data["exists"])
self.assertEquals(
self.assertEqual(True, response1.data["valid"])
self.assertEqual(True, response1.data["exists"])
self.assertEqual(
"The provided Package URL is valid, and the package exists in the upstream repo.",
response1.data["message"],
)

self.assertEquals(False, response2.data["valid"])
self.assertEquals(
self.assertEqual(False, response2.data["valid"])
self.assertEqual(
"The provided PackageURL is not valid.", response2.data["message"]
)

Expand All @@ -1160,11 +1160,11 @@ def test_api_purl_validation_unsupported_package_type(self):
response1 = self.client.get(f"/api/validate/", data=data1)


self.assertEquals(True, response1.data["valid"])
self.assertEquals(
self.assertEqual(True, response1.data["valid"])
self.assertEqual(
"The provided PackageURL is valid, but `check_existence` is not supported for this package type.", response1.data["message"]
)
self.assertEquals(None, response1.data["exists"])
self.assertEqual(None, response1.data["exists"])

def test_api_purl_validation_empty_request(self):
data1 = {}
Expand Down
2 changes: 2 additions & 0 deletions purldb_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from minecode.api import PriorityResourceURIViewSet
from packagedb.api import PurlValidateViewSet
from packagedb.api import CollectViewSet
from drf_spectacular.views import SpectacularAPIView
from drf_spectacular.views import SpectacularSwaggerView


Expand All @@ -49,5 +50,6 @@
),
path('api/', include((api_router.urls, 'api'))),
path("", RedirectView.as_view(url="api/")),
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
]

0 comments on commit 79d7aec

Please sign in to comment.