Skip to content

Commit

Permalink
tests(agent): racksdb routes when disabled/enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rezib committed Jan 17, 2025
1 parent 6143fae commit 89aa093
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
6 changes: 5 additions & 1 deletion slurmweb/tests/lib/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


import werkzeug
from flask import Blueprint
from flask import Blueprint, jsonify

from rfl.authentication.user import AuthenticatedUser
from slurmweb.apps import SlurmwebConfSeed
Expand Down Expand Up @@ -42,6 +42,10 @@ class FakeRacksDBWebBlueprint(Blueprint):

def __init__(self, **kwargs):
super().__init__("Fake RacksDB web blueprint", __name__)
self.add_url_rule("fake", view_func=self.basic)

def basic(self):
return jsonify({"test": "ok"})


class TestAgentBase(unittest.TestCase):
Expand Down
55 changes: 55 additions & 0 deletions slurmweb/tests/views/test_agent_racksdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2025 Rackslab
#
# This file is part of Slurm-web.
#
# SPDX-License-Identifier: GPL-3.0-or-later


import textwrap

from ..lib.agent import TestAgentBase


class TestAgentRacksDBEnabledRequest(TestAgentBase):

def setUp(self):
self.setup_client()

def test_request_racksdb(self):
# Check FakeRacksDBWebBlueprint is called when racksdb is enabled (by default).
response = self.client.get("/racksdb/fake")
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.json,
{"test": "ok"},
)


class TestAgentRacksDBDisabledRequest(TestAgentBase):

def setUp(self):
self.setup_client(
additional_conf=textwrap.dedent(
"""
[racksdb]
enabled=no
"""
)
)

def test_request_racksdb(self):
# Check FakeRacksDBWebBlueprint is not registered when racksdb is disabled.
response = self.client.get("/racksdb/fake")
self.assertEqual(response.status_code, 404)
self.assertEqual(
response.json,
{
"code": 404,
"description": (
"The requested URL was not found on the server. If you entered "
"the URL manually please check your spelling and try again."
),
"name": "Not Found",
},
)

0 comments on commit 89aa093

Please sign in to comment.