From 97aaa49cfa87ea13904e742b340f445e308ecc64 Mon Sep 17 00:00:00 2001 From: Michael Herrmann Date: Thu, 9 Dec 2021 11:14:53 +0100 Subject: [PATCH] Implement api/information --- api/__init__.py | 0 api/apps.py | 6 ++++++ api/migrations/__init__.py | 0 api/tests/__init__.py | 0 api/tests/test_views.py | 15 +++++++++++++++ api/urls.py | 9 +++++++++ api/views.py | 9 +++++++++ wpr/settings.py | 1 + wpr/urls.py | 20 +++----------------- 9 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 api/__init__.py create mode 100644 api/apps.py create mode 100644 api/migrations/__init__.py create mode 100644 api/tests/__init__.py create mode 100644 api/tests/test_views.py create mode 100644 api/urls.py create mode 100644 api/views.py diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/tests/__init__.py b/api/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/tests/test_views.py b/api/tests/test_views.py new file mode 100644 index 0000000..b602762 --- /dev/null +++ b/api/tests/test_views.py @@ -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']) \ No newline at end of file diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..84f3886 --- /dev/null +++ b/api/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +app_name = 'api' + +urlpatterns = [ + path('information', views.information, name='information') +] \ No newline at end of file diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..ec6c074 --- /dev/null +++ b/api/views.py @@ -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'] + } + }) \ No newline at end of file diff --git a/wpr/settings.py b/wpr/settings.py index d3f944b..042b8ba 100644 --- a/wpr/settings.py +++ b/wpr/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'api' ] MIDDLEWARE = [ diff --git a/wpr/urls.py b/wpr/urls.py index 42f9ac0..c3857e4 100644 --- a/wpr/urls.py +++ b/wpr/urls.py @@ -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), -] +] \ No newline at end of file