Skip to content

Commit

Permalink
update irodsinfo api versioning (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 10, 2024
1 parent 3b3d511 commit 875e102
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
24 changes: 13 additions & 11 deletions docs_manual/source/api_irodsinfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ Irods Info API
The REST API for the iRODS Info app is described in this document.


Versioning
==========

Media Type
``application/vnd.bihealth.sodar.irodsinfo+json``
Current Version
``1.0``
Accepted Versions
``1.0``
Header Example
``Accept: application/vnd.bihealth.sodar.irodsinfo+json; version=x.y``


API Views
=========

.. currentmodule:: irodsinfo.views_api

.. autoclass:: IrodsEnvRetrieveAPIView


Versioning
==========

For accept header versioning, the following header is expected in the current
SODAR version:

.. code-block:: console
Accept: application/vnd.bihealth.sodar+json; version=0.15.0
17 changes: 14 additions & 3 deletions irodsinfo/tests/test_permissions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

# Projectroles dependency
from projectroles.tests.test_permissions import SiteAppPermissionTestBase
from projectroles.tests.test_permissions_api import SODARAPIPermissionTestMixin

from irodsinfo.views_api import (
IRODSINFO_API_MEDIA_TYPE,
IRODSINFO_API_DEFAULT_VERSION,
)

class TestIrodsConfigRetrieveAPIView(SiteAppPermissionTestBase):

class TestIrodsConfigRetrieveAPIView(
SODARAPIPermissionTestMixin, SiteAppPermissionTestBase
):
"""Tests for irodsinfo API"""

media_type = IRODSINFO_API_MEDIA_TYPE
api_version = IRODSINFO_API_DEFAULT_VERSION

def test_get_irods_config(self):
"""Test IrodsConfigRetrieveAPIView GET"""
url = reverse('irodsinfo:api_env')
good_users = [self.superuser, self.regular_user]
bad_users = [self.anonymous]
self.assert_response(url, good_users, 200)
self.assert_response(url, bad_users, 401)
self.assert_response_api(url, good_users, 200)
self.assert_response_api(url, bad_users, 401)
7 changes: 7 additions & 0 deletions irodsinfo/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
from test_plus.test import TestCase

from irodsinfo.tests.test_views import PLUGINS_DISABLE_IRODS
from irodsinfo.views_api import (
IRODSINFO_API_MEDIA_TYPE,
IRODSINFO_API_DEFAULT_VERSION,
)


class TestIrodsConfigRetrieveAPIView(TestCase):
"""Tests for IrodsConfigRetrieveAPIView"""

media_type = IRODSINFO_API_MEDIA_TYPE
api_version = IRODSINFO_API_DEFAULT_VERSION

def setUp(self):
# Create users
self.superuser = self.make_user('superuser')
Expand Down
29 changes: 28 additions & 1 deletion irodsinfo/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import logging

from rest_framework.permissions import IsAuthenticated
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
from rest_framework.versioning import AcceptHeaderVersioning
from rest_framework.views import APIView

# Projectroles dependency
Expand All @@ -15,7 +17,32 @@
logger = logging.getLogger(__name__)


class IrodsEnvRetrieveAPIView(IrodsConfigMixin, APIView):
# Local constants
IRODSINFO_API_MEDIA_TYPE = 'application/vnd.bihealth.sodar.irodsinfo+json'
IRODSINFO_API_ALLOWED_VERSIONS = ['1.0']
IRODSINFO_API_DEFAULT_VERSION = '1.0'


class IrodsinfoAPIVersioningMixin:
"""
Irodsinfo API view versioning mixin for overriding media type and
accepted versions.
"""

class IrodsinfoAPIRenderer(JSONRenderer):
media_type = IRODSINFO_API_MEDIA_TYPE

class IrodsinfoAPIVersioning(AcceptHeaderVersioning):
allowed_versions = IRODSINFO_API_ALLOWED_VERSIONS
default_version = IRODSINFO_API_DEFAULT_VERSION

renderer_classes = [IrodsinfoAPIRenderer]
versioning_class = IrodsinfoAPIVersioning


class IrodsEnvRetrieveAPIView(
IrodsConfigMixin, IrodsinfoAPIVersioningMixin, APIView
):
"""
Retrieve iRODS environment file for the current user.
Expand Down

0 comments on commit 875e102

Please sign in to comment.