Skip to content

Commit

Permalink
Merge branch 'pin-rest-api-0.2' into 'master'
Browse files Browse the repository at this point in the history
Pin REST API version v0.2 and start on REST API v0.3

See merge request lava/lava!2346
  • Loading branch information
ivoire committed Jan 23, 2024
2 parents db69128 + bc4f3b0 commit e52f7a9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
2 changes: 2 additions & 0 deletions lava_rest_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

from lava_rest_app.v02.routers import router as router_v02
from lava_rest_app.v02.views import LavaObtainAuthToken
from lava_rest_app.v03.routers import router as router_v03
from lava_server.compat import url

from . import versions

urlpatterns = [
url(r"^(?P<version>(v0.2))/", include(router_v02.urls)),
url(r"^(?P<version>(v0.3))/", include(router_v03.urls)),
url(
r"^^(?P<version>(%s))/token/" % versions.urlpattern(),
LavaObtainAuthToken.as_view(),
Expand Down
5 changes: 5 additions & 0 deletions lava_rest_app/v03/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2024 Collabora Limited
#
# Author: Igor Ponomarev <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-or-later
8 changes: 8 additions & 0 deletions lava_rest_app/v03/routers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (C) 2024 Collabora Limited
#
# Author: Igor Ponomarev <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-or-later
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
2 changes: 1 addition & 1 deletion lava_rest_app/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

versions = ("v0.2",)
versions = ("v0.2", "v0.3")


def urlpattern():
Expand Down
52 changes: 22 additions & 30 deletions tests/lava_rest_app/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from lava_common.version import __version__
from lava_common.yaml import yaml_safe_load
from lava_rest_app import versions
from lava_rest_app.v02 import serializers
from lava_results_app import models as result_models
from lava_scheduler_app.models import (
Expand Down Expand Up @@ -90,7 +89,7 @@
class TestRestApi:
@pytest.fixture(autouse=True)
def setUp(self, db):
self.version = versions.versions[-1] # use latest version by default
self.version = "v0.2" # use v0.2 API

# create users
self.admin = User.objects.create(username="admin", is_superuser=True)
Expand Down Expand Up @@ -1767,38 +1766,31 @@ def test_delete_not_authenticated(self):
)
assert response.status_code == 403 # nosec

def test_view_root(self, client):
ret = client.get(reverse("api-root", args=(self.version,)) + "?format=api")
assert ret.status_code == 200

def test_view_root(client):
ret = client.get(reverse("api-root", args=[versions.versions[-1]]) + "?format=api")
assert ret.status_code == 200


def test_view_devices(client, db):
ret = client.get(
reverse("api-root", args=[versions.versions[-1]]) + "devices/?format=api"
)
assert ret.status_code == 200


def test_view_devicetypes(client, db):
ret = client.get(
reverse("api-root", args=[versions.versions[-1]]) + "devicetypes/?format=api"
)
assert ret.status_code == 200

def test_view_devices(self, client, db):
ret = client.get(
reverse("api-root", args=(self.version,)) + "devices/?format=api"
)
assert ret.status_code == 200

def test_view_jobs(client, db):
ret = client.get(
reverse("api-root", args=[versions.versions[-1]]) + "jobs/?format=api"
)
assert ret.status_code == 200
def test_view_devicetypes(self, client, db):
ret = client.get(
reverse("api-root", args=(self.version,)) + "devicetypes/?format=api"
)
assert ret.status_code == 200

def test_view_jobs(self, client, db):
ret = client.get(reverse("api-root", args=(self.version,)) + "jobs/?format=api")
assert ret.status_code == 200

def test_view_workers(client, db):
ret = client.get(
reverse("api-root", args=[versions.versions[-1]]) + "workers/?format=api"
)
assert ret.status_code == 200
def test_view_workers(self, client, db):
ret = client.get(
reverse("api-root", args=(self.version,)) + "workers/?format=api"
)
assert ret.status_code == 200


def test_serializers_partial():
Expand Down

0 comments on commit e52f7a9

Please sign in to comment.