Skip to content

Commit f3e638e

Browse files
skypank-codernorthdpole
authored andcommitted
fix: address CodeRabbit review on /api/capabilities
Use patch.dict for CRE_ENABLE_MYOPENCRE in tests so any preexisting value is restored and tests aren't order-dependent. Add docstrings to is_myopencre_enabled, get_capabilities, and the capabilities tests to satisfy docstring coverage.
1 parent 7a0da5c commit f3e638e

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

application/feature_flags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ def is_health_endpoint_enabled() -> bool:
1919

2020

2121
def is_myopencre_enabled() -> bool:
22+
"""Return True when the MyOpenCRE feature is enabled via CRE_ENABLE_MYOPENCRE."""
2223
return os.getenv("CRE_ENABLE_MYOPENCRE", "").strip().lower() in TRUE_VALUES

application/tests/web_main_test.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,29 +1527,31 @@ def test_health_db_unreachable_returns_503(self) -> None:
15271527
os.environ.pop("CRE_ENABLE_HEALTH", None)
15281528

15291529
def test_capabilities_endpoint_returns_myopencre_key(self) -> None:
1530-
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)
1531-
with self.app.test_client() as client:
1532-
response = client.get("/api/capabilities")
1533-
self.assertEqual(200, response.status_code)
1534-
body = json.loads(response.data.decode())
1535-
self.assertIn("myopencre", body)
1536-
self.assertIsInstance(body["myopencre"], bool)
1530+
"""GET /api/capabilities returns 200 with a boolean myopencre key."""
1531+
with patch.dict(os.environ, {}, clear=False):
1532+
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)
1533+
with self.app.test_client() as client:
1534+
response = client.get("/api/capabilities")
1535+
self.assertEqual(200, response.status_code)
1536+
body = json.loads(response.data.decode())
1537+
self.assertIn("myopencre", body)
1538+
self.assertIsInstance(body["myopencre"], bool)
15371539

15381540
def test_capabilities_myopencre_false_by_default(self) -> None:
1539-
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)
1540-
with self.app.test_client() as client:
1541-
response = client.get("/api/capabilities")
1542-
self.assertEqual(200, response.status_code)
1543-
body = json.loads(response.data.decode())
1544-
self.assertFalse(body["myopencre"])
1541+
"""myopencre is False when CRE_ENABLE_MYOPENCRE is unset."""
1542+
with patch.dict(os.environ, {}, clear=False):
1543+
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)
1544+
with self.app.test_client() as client:
1545+
response = client.get("/api/capabilities")
1546+
self.assertEqual(200, response.status_code)
1547+
body = json.loads(response.data.decode())
1548+
self.assertFalse(body["myopencre"])
15451549

15461550
def test_capabilities_myopencre_true_when_flag_set(self) -> None:
1547-
os.environ["CRE_ENABLE_MYOPENCRE"] = "1"
1548-
try:
1551+
"""myopencre is True when CRE_ENABLE_MYOPENCRE is set to a truthy value."""
1552+
with patch.dict(os.environ, {"CRE_ENABLE_MYOPENCRE": "1"}, clear=False):
15491553
with self.app.test_client() as client:
15501554
response = client.get("/api/capabilities")
15511555
self.assertEqual(200, response.status_code)
15521556
body = json.loads(response.data.decode())
15531557
self.assertTrue(body["myopencre"])
1554-
finally:
1555-
os.environ.pop("CRE_ENABLE_MYOPENCRE", None)

application/web/web_main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ def get_config() -> Any:
12021202

12031203
@app.route("/api/capabilities", methods=["GET"])
12041204
def get_capabilities() -> Any:
1205+
"""Expose frontend feature capabilities, e.g. whether MyOpenCRE is enabled."""
12051206
return jsonify({"myopencre": is_myopencre_enabled()})
12061207

12071208

0 commit comments

Comments
 (0)