mirror of
https://github.com/omaha-consulting/winget.pro.git
synced 2026-10-24 12:52:26 +00:00
Fix errors when winget searches our source
This commit is contained in:
@@ -191,6 +191,18 @@ class APITest(TestCase):
|
||||
installer_json, = version_json['Installers']
|
||||
self._check_vscode_installer_json(installer, installer_json)
|
||||
|
||||
|
||||
def test_nonexistent_manifest_returns_204_not_404(self):
|
||||
# This is a peculiarity / inconsistency of the winget client. The API
|
||||
# design docs say that packageManifests should return 404 when a package
|
||||
# does not exist. But winget doesn't gracefully handle this case.
|
||||
# Instead, it expects HTTP 204.
|
||||
# See: https://github.com/microsoft/winget-cli-restsource/issues/170
|
||||
url = self._reverse('packageManifests', {'identifier': 'nonexistent'})
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(204, response.status_code)
|
||||
|
||||
|
||||
def _check_vscode_installer_json(
|
||||
self, installer, installer_json, scope=None
|
||||
):
|
||||
|
||||
+15
-3
@@ -1,6 +1,6 @@
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_GET, require_POST
|
||||
|
||||
@@ -69,9 +69,21 @@ def manifestSearch(_, data, tenant):
|
||||
|
||||
@require_GET
|
||||
@load_tenant
|
||||
@return_jsonresponse
|
||||
def packageManifests(request, tenant, identifier):
|
||||
package = get_object_or_404(Package, tenant=tenant, identifier=identifier)
|
||||
try:
|
||||
package = Package.objects.get(tenant=tenant, identifier=identifier)
|
||||
except ObjectDoesNotExist:
|
||||
# This is a peculiarity / inconsistency of the winget client. The API
|
||||
# design docs say that packageManifests should return 404 when a package
|
||||
# does not exist. But winget doesn't gracefully handle this case.
|
||||
# Instead, it expects HTTP 204.
|
||||
# See: https://github.com/microsoft/winget-cli-restsource/issues/170
|
||||
return HttpResponse(status=204)
|
||||
return _packageManifests(request, package)
|
||||
|
||||
|
||||
@return_jsonresponse
|
||||
def _packageManifests(request, package):
|
||||
return {
|
||||
'PackageIdentifier': package.identifier,
|
||||
'Versions': [
|
||||
|
||||
Reference in New Issue
Block a user