This commit is contained in:
parent
49de2decca
commit
cc0bdc0472
4 changed files with 56 additions and 14 deletions
27
backend/toolshed/admin.py
Normal file
27
backend/toolshed/admin.py
Normal 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)
|
|
@ -7,6 +7,14 @@ from hostadmin.models import Domain
|
||||||
from authentication.signature_auth import SignatureAuthentication
|
from authentication.signature_auth import SignatureAuthentication
|
||||||
from toolshed.models import Tag, Property, Category
|
from toolshed.models import Tag, Property, Category
|
||||||
from toolshed.serializers import CategorySerializer, PropertySerializer
|
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'])
|
@api_view(['GET'])
|
||||||
|
@ -53,12 +61,13 @@ def list_availability_policies(request, format=None): # /availability_policies/
|
||||||
def combined_info(request, format=None): # /info/
|
def combined_info(request, format=None): # /info/
|
||||||
tags = [tag.name for tag in Tag.objects.all()]
|
tags = [tag.name for tag in Tag.objects.all()]
|
||||||
properties = [property.name for property in Property.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']
|
policies = ['private', 'friends', 'internal', 'public']
|
||||||
return Response({'tags': tags, 'properties': properties, 'policies': policies, 'categories': categories})
|
return Response({'tags': tags, 'properties': properties, 'policies': policies, 'categories': categories})
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
path('version/', get_version, name='version'),
|
||||||
path('availability_policies/', list_availability_policies, name='availability_policies'),
|
path('availability_policies/', list_availability_policies, name='availability_policies'),
|
||||||
path('properties/', list_properties, name='propertylist'),
|
path('properties/', list_properties, name='propertylist'),
|
||||||
path('categories/', list_categories, name='categorylist'),
|
path('categories/', list_categories, name='categorylist'),
|
||||||
|
|
|
@ -1,25 +1,30 @@
|
||||||
from django.test import Client
|
from django.test import Client
|
||||||
from authentication.tests import UserTestMixin, SignatureAuthClient, ToolshedTestCase
|
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()
|
anonymous_client = Client()
|
||||||
client = SignatureAuthClient()
|
client = SignatureAuthClient()
|
||||||
|
|
||||||
|
|
||||||
class CombinedApiTestCase(UserTestMixin, ToolshedTestCase):
|
class CombinedApiTestCase(UserTestMixin, CategoryTestMixin, TagTestMixin, PropertyTestMixin, ToolshedTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.prepare_users()
|
self.prepare_users()
|
||||||
self.f['cat1'] = Category.objects.create(name='cat1')
|
self.prepare_categories()
|
||||||
self.f['cat2'] = Category.objects.create(name='cat2')
|
self.prepare_tags()
|
||||||
self.f['cat3'] = Category.objects.create(name='cat3')
|
self.prepare_properties()
|
||||||
self.f['tag1'] = Tag.objects.create(name='tag1')
|
|
||||||
self.f['tag2'] = Tag.objects.create(name='tag2')
|
def test_version_anonymous(self):
|
||||||
self.f['tag3'] = Tag.objects.create(name='tag3')
|
response = anonymous_client.get('/api/version/')
|
||||||
self.f['prop1'] = Property.objects.create(name='prop1')
|
self.assertEqual(response.status_code, 200)
|
||||||
self.f['prop2'] = Property.objects.create(name='prop2')
|
self.assertEqual(response.json(), {'version': settings.TOOLSHED_VERSION})
|
||||||
self.f['prop3'] = Property.objects.create(name='prop3')
|
|
||||||
|
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):
|
def test_domains_anonymous(self):
|
||||||
response = anonymous_client.get('/api/domains/')
|
response = anonymous_client.get('/api/domains/')
|
||||||
|
@ -39,7 +44,8 @@ class CombinedApiTestCase(UserTestMixin, ToolshedTestCase):
|
||||||
response = client.get('/api/info/', self.f['local_user1'])
|
response = client.get('/api/info/', self.f['local_user1'])
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json()['policies'], ['private', 'friends', 'internal', 'public'])
|
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()['tags'], ['tag1', 'tag2', 'tag3'])
|
||||||
self.assertEqual(response.json()['properties'], ['prop1', 'prop2', 'prop3'])
|
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'])
|
response = client.get('/api/availability_policies/', self.f['local_user1'])
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json(), ['private', 'friends', 'internal', 'public'])
|
self.assertEqual(response.json(), ['private', 'friends', 'internal', 'public'])
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from authentication.tests import SignatureAuthClient, UserTestMixin, ToolshedTestCase
|
from authentication.tests import SignatureAuthClient, UserTestMixin, ToolshedTestCase
|
||||||
from toolshed.models import Category
|
|
||||||
from toolshed.tests import CategoryTestMixin
|
from toolshed.tests import CategoryTestMixin
|
||||||
|
|
||||||
client = SignatureAuthClient()
|
client = SignatureAuthClient()
|
||||||
|
|
Loading…
Reference in a new issue