Coverage for django_napse/api/custom_viewset.py: 41%
17 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from rest_framework.viewsets import GenericViewSet
3from django_napse.auth.models import NapseAPIKey
4from django_napse.core.models import NapseSpace
5from django_napse.utils.errors import APIError
8class CustomViewSet(GenericViewSet):
9 def get_api_key(self, request):
10 try:
11 return NapseAPIKey.objects.get_from_key(request.META["HTTP_AUTHORIZATION"].split()[1])
12 except NapseAPIKey.DoesNotExist as e:
13 raise APIError.InvalidAPIKey() from e
14 except KeyError as e:
15 raise APIError.NoAPIKey() from e
17 def get_space(self, request) -> NapseSpace | None:
18 try:
19 return NapseSpace.objects.get(uuid=request.query_params["space"])
20 except NapseSpace.DoesNotExist:
21 return None