add /api/version
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
j3d1 2023-10-23 13:06:22 +02:00
parent 49de2decca
commit cc0bdc0472
4 changed files with 56 additions and 14 deletions

27
backend/toolshed/admin.py Normal file
View file

@ -0,0 +1,27 @@
from django.contrib import admin
from toolshed.models import InventoryItem, Property, Tag, ItemProperty, ItemTag
class InventoryItemAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'category', 'availability_policy', 'owned_quantity', 'owner')
search_fields = ('name', 'description', 'category', 'availability_policy', 'owned_quantity', 'owner')
admin.site.register(InventoryItem, InventoryItemAdmin)
class PropertyAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)
admin.site.register(Property, PropertyAdmin)
class TagAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)
admin.site.register(Tag, TagAdmin)

View file

@ -7,6 +7,14 @@ from hostadmin.models import Domain
from authentication.signature_auth import SignatureAuthentication
from toolshed.models import Tag, Property, Category
from toolshed.serializers import CategorySerializer, PropertySerializer
from backend.settings import TOOLSHED_VERSION
@api_view(['GET'])
@permission_classes([])
@authentication_classes([])
def get_version(request, format=None): # /version/
return Response({'version': TOOLSHED_VERSION})
@api_view(['GET'])
@ -53,12 +61,13 @@ def list_availability_policies(request, format=None): # /availability_policies/
def combined_info(request, format=None): # /info/
tags = [tag.name for tag in Tag.objects.all()]
properties = [property.name for property in Property.objects.all()]
categories = [category.name for category in Category.objects.all()]
categories = [str(category) for category in Category.objects.all()]
policies = ['private', 'friends', 'internal', 'public']
return Response({'tags': tags, 'properties': properties, 'policies': policies, 'categories': categories})
urlpatterns = [
path('version/', get_version, name='version'),
path('availability_policies/', list_availability_policies, name='availability_policies'),
path('properties/', list_properties, name='propertylist'),
path('categories/', list_categories, name='categorylist'),

View file

@ -1,25 +1,30 @@
from django.test import Client
from authentication.tests import UserTestMixin, SignatureAuthClient, ToolshedTestCase
from toolshed.models import Category, Tag, Property
from backend import settings
from toolshed.tests import CategoryTestMixin, TagTestMixin, PropertyTestMixin
anonymous_client = Client()
client = SignatureAuthClient()
class CombinedApiTestCase(UserTestMixin, ToolshedTestCase):
class CombinedApiTestCase(UserTestMixin, CategoryTestMixin, TagTestMixin, PropertyTestMixin, ToolshedTestCase):
def setUp(self):
super().setUp()
self.prepare_users()
self.f['cat1'] = Category.objects.create(name='cat1')
self.f['cat2'] = Category.objects.create(name='cat2')
self.f['cat3'] = Category.objects.create(name='cat3')
self.f['tag1'] = Tag.objects.create(name='tag1')
self.f['tag2'] = Tag.objects.create(name='tag2')
self.f['tag3'] = Tag.objects.create(name='tag3')
self.f['prop1'] = Property.objects.create(name='prop1')
self.f['prop2'] = Property.objects.create(name='prop2')
self.f['prop3'] = Property.objects.create(name='prop3')
self.prepare_categories()
self.prepare_tags()
self.prepare_properties()
def test_version_anonymous(self):
response = anonymous_client.get('/api/version/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {'version': settings.TOOLSHED_VERSION})
def test_version_authenticated(self):
response = client.get('/api/version/', self.f['local_user1'])
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {'version': settings.TOOLSHED_VERSION})
def test_domains_anonymous(self):
response = anonymous_client.get('/api/domains/')
@ -39,7 +44,8 @@ class CombinedApiTestCase(UserTestMixin, ToolshedTestCase):
response = client.get('/api/info/', self.f['local_user1'])
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['policies'], ['private', 'friends', 'internal', 'public'])
self.assertEqual(response.json()['categories'], ['cat1', 'cat2', 'cat3'])
self.assertEqual(response.json()['categories'],
['cat1', 'cat2', 'cat3', 'cat1/subcat1', 'cat1/subcat2', 'cat1/subcat1/subcat3'])
self.assertEqual(response.json()['tags'], ['tag1', 'tag2', 'tag3'])
self.assertEqual(response.json()['properties'], ['prop1', 'prop2', 'prop3'])
@ -51,3 +57,4 @@ class CombinedApiTestCase(UserTestMixin, ToolshedTestCase):
response = client.get('/api/availability_policies/', self.f['local_user1'])
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), ['private', 'friends', 'internal', 'public'])

View file

@ -1,5 +1,4 @@
from authentication.tests import SignatureAuthClient, UserTestMixin, ToolshedTestCase
from toolshed.models import Category
from toolshed.tests import CategoryTestMixin
client = SignatureAuthClient()