Implement api/information

This commit is contained in:
Michael Herrmann
2021-12-09 11:14:53 +01:00
parent ef5921ffc6
commit 97aaa49cfa
9 changed files with 43 additions and 17 deletions
View File
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
View File
View File
+15
View File
@@ -0,0 +1,15 @@
from django.test import TestCase, Client
from django.urls import reverse
class APITest(TestCase):
def setUp(self):
super().setUp()
self.client = Client()
def test_information_required_parts(self):
response = self.client.get(reverse('api:information'))
data = response.json()['Data']
self.assertEqual(
'github.com/omaha-consulting/winget-private-repository',
data['SourceIdentifier']
)
self.assertEqual(data['ServerSupportedVersions'], ['1.1.0'])
+9
View File
@@ -0,0 +1,9 @@
from django.urls import path
from . import views
app_name = 'api'
urlpatterns = [
path('information', views.information, name='information')
]
+9
View File
@@ -0,0 +1,9 @@
from django.http import JsonResponse
def information(request):
return JsonResponse({
'Data': {
'SourceIdentifier': 'github.com/omaha-consulting/winget-private-repository',
'ServerSupportedVersions': ['1.1.0']
}
})
+1
View File
@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api'
]
MIDDLEWARE = [
+3 -17
View File
@@ -1,21 +1,7 @@
"""wpr URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path
urlpatterns = [
path('api/', include('api.urls')),
path('admin/', admin.site.urls),
]
]