add rest api for backups
This commit is contained in:
parent
1ffa5cb110
commit
e81400ec5a
|
@ -0,0 +1,44 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from .models import BackupMethod
|
||||
from .models import Backup
|
||||
from .models import TargetDevice
|
||||
from .models import NotificationFromBackup
|
||||
from .models import Notification
|
||||
from .models import NotificationType
|
||||
|
||||
|
||||
class BackupMethodSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = BackupMethod
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class BackupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Backup
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class TargetDeviceSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = TargetDevice
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class NotificationFromBackupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = NotificationFromBackup
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class NotificationSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Notification
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class NotificationTypeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = NotificationType
|
||||
fields = '__all__'
|
|
@ -29,3 +29,17 @@ def test_unauthorized_request_notificaton_from_backup(api_client):
|
|||
url = reverse('notification-from-backup-list')
|
||||
response = api_client.get(url)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unauthorized_request_notificaton(api_client):
|
||||
url = reverse('notification-list')
|
||||
response = api_client.get(url)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unauthorized_request_notificaton_type(api_client):
|
||||
url = reverse('notification-types-list')
|
||||
response = api_client.get(url)
|
||||
assert response.status_code == 403
|
||||
|
|
|
@ -2,8 +2,24 @@ from django.urls import path, include
|
|||
|
||||
from rest_framework import routers
|
||||
|
||||
from . import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'backup-method',
|
||||
views.BackupMethodViewSet,
|
||||
'backup-method')
|
||||
router.register(r'backups', views.BackupViewSet)
|
||||
router.register(r'target-devices',
|
||||
views.TargetDeviceViewSet,
|
||||
'target-device')
|
||||
router.register(r'notification-from-backup',
|
||||
views.NotificationFromBackupViewSet,
|
||||
'notification-from-backup')
|
||||
router.register(r'notification',
|
||||
views.NotificationViewSet)
|
||||
router.register(r'notification-type',
|
||||
views.NotificationTypeViewSet,
|
||||
'notification-types')
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
from rest_framework import viewsets
|
||||
from rest_framework import permissions
|
||||
|
||||
from .models import BackupMethod
|
||||
from .models import Backup
|
||||
from .models import TargetDevice
|
||||
from .models import NotificationFromBackup
|
||||
from .models import Notification
|
||||
from .models import NotificationType
|
||||
|
||||
from .serializers import BackupMethodSerializer
|
||||
from .serializers import BackupSerializer
|
||||
from .serializers import TargetDeviceSerializer
|
||||
from .serializers import NotificationFromBackupSerializer
|
||||
from .serializers import NotificationSerializer
|
||||
from .serializers import NotificationTypeSerializer
|
||||
|
||||
|
||||
class BackupMethodViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows BackupMethods to be viewed or edited.
|
||||
"""
|
||||
queryset = BackupMethod.objects.all()
|
||||
serializer_class = BackupMethodSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class BackupViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows BackupMethods to be viewed or edited.
|
||||
"""
|
||||
queryset = Backup.objects.all()
|
||||
serializer_class = BackupSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class TargetDeviceViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows BackupMethods to be viewed or edited.
|
||||
"""
|
||||
queryset = TargetDevice.objects.all()
|
||||
serializer_class = TargetDeviceSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class NotificationFromBackupViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows BackupMethods to be viewed or edited.
|
||||
"""
|
||||
queryset = NotificationFromBackup.objects.all()
|
||||
serializer_class = NotificationFromBackupSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class NotificationViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows BackupMethods to be viewed or edited.
|
||||
"""
|
||||
queryset = Notification.objects.all()
|
||||
serializer_class = NotificationSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class NotificationTypeViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows BackupMethods to be viewed or edited.
|
||||
"""
|
||||
queryset = NotificationType.objects.all()
|
||||
serializer_class = NotificationTypeSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
Loading…
Reference in New Issue