Skip to content

Commit f9afb50

Browse files
authored
fix(api): standardize JSON:API resource types for Lighthouse endpoints (#9085)
Co-authored-by: Chandrapal Badshah <[email protected]>
1 parent 3b95aad commit f9afb50

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

api/src/backend/api/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ class Meta(RowLevelSecurityProtectedModel.Meta):
21042104
]
21052105

21062106
class JSONAPIMeta:
2107-
resource_name = "lighthouse-config"
2107+
resource_name = "lighthouse-configurations"
21082108

21092109

21102110
class LighthouseProviderModels(RowLevelSecurityProtectedModel):
@@ -2153,3 +2153,6 @@ class Meta(RowLevelSecurityProtectedModel.Meta):
21532153
name="lh_prov_models_cfg_idx",
21542154
),
21552155
]
2156+
2157+
class JSONAPIMeta:
2158+
resource_name = "lighthouse-models"

api/src/backend/api/tests/test_views.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8923,7 +8923,7 @@ def test_lighthouse_tenant_config_create_via_patch(self, authenticated_client):
89238923
"""Test creating a tenant config successfully via PATCH (upsert)"""
89248924
payload = {
89258925
"data": {
8926-
"type": "lighthouse-config",
8926+
"type": "lighthouse-configurations",
89278927
"attributes": {
89288928
"business_context": "Test business context for security analysis",
89298929
"default_provider": "",
@@ -8932,7 +8932,7 @@ def test_lighthouse_tenant_config_create_via_patch(self, authenticated_client):
89328932
}
89338933
}
89348934
response = authenticated_client.patch(
8935-
reverse("lighthouse-config"),
8935+
reverse("lighthouse-configurations"),
89368936
data=payload,
89378937
content_type=API_JSON_CONTENT_TYPE,
89388938
)
@@ -8949,7 +8949,7 @@ def test_lighthouse_tenant_config_upsert_behavior(self, authenticated_client):
89498949
"""Test that PATCH creates config if not exists and updates if exists (upsert)"""
89508950
payload = {
89518951
"data": {
8952-
"type": "lighthouse-config",
8952+
"type": "lighthouse-configurations",
89538953
"attributes": {
89548954
"business_context": "First config",
89558955
},
@@ -8958,7 +8958,7 @@ def test_lighthouse_tenant_config_upsert_behavior(self, authenticated_client):
89588958

89598959
# First PATCH creates the config
89608960
response = authenticated_client.patch(
8961-
reverse("lighthouse-config"),
8961+
reverse("lighthouse-configurations"),
89628962
data=payload,
89638963
content_type=API_JSON_CONTENT_TYPE,
89648964
)
@@ -8969,7 +8969,7 @@ def test_lighthouse_tenant_config_upsert_behavior(self, authenticated_client):
89698969
# Second PATCH updates the same config (not creating a duplicate)
89708970
payload["data"]["attributes"]["business_context"] = "Updated config"
89718971
response = authenticated_client.patch(
8972-
reverse("lighthouse-config"),
8972+
reverse("lighthouse-configurations"),
89738973
data=payload,
89748974
content_type=API_JSON_CONTENT_TYPE,
89758975
)
@@ -9025,7 +9025,7 @@ def test_lighthouse_tenant_config_retrieve(
90259025
)
90269026

90279027
# Retrieve and verify the configuration
9028-
response = authenticated_client.get(reverse("lighthouse-config"))
9028+
response = authenticated_client.get(reverse("lighthouse-configurations"))
90299029
assert response.status_code == status.HTTP_200_OK
90309030
data = response.json()["data"]
90319031
assert data["id"] == str(config.id)
@@ -9035,7 +9035,7 @@ def test_lighthouse_tenant_config_retrieve(
90359035

90369036
def test_lighthouse_tenant_config_retrieve_not_found(self, authenticated_client):
90379037
"""Test GET when config doesn't exist returns 404"""
9038-
response = authenticated_client.get(reverse("lighthouse-config"))
9038+
response = authenticated_client.get(reverse("lighthouse-configurations"))
90399039
assert response.status_code == status.HTTP_404_NOT_FOUND
90409040
assert "not found" in response.json()["errors"][0]["detail"].lower()
90419041

@@ -9056,14 +9056,14 @@ def test_lighthouse_tenant_config_partial_update(
90569056
# Update it
90579057
payload = {
90589058
"data": {
9059-
"type": "lighthouse-config",
9059+
"type": "lighthouse-configurations",
90609060
"attributes": {
90619061
"business_context": "Updated context for cloud security",
90629062
},
90639063
}
90649064
}
90659065
response = authenticated_client.patch(
9066-
reverse("lighthouse-config"),
9066+
reverse("lighthouse-configurations"),
90679067
data=payload,
90689068
content_type=API_JSON_CONTENT_TYPE,
90699069
)
@@ -9088,14 +9088,14 @@ def test_lighthouse_tenant_config_update_invalid_provider(
90889088
# Try to set invalid provider
90899089
payload = {
90909090
"data": {
9091-
"type": "lighthouse-config",
9091+
"type": "lighthouse-configurations",
90929092
"attributes": {
90939093
"default_provider": "nonexistent-provider",
90949094
},
90959095
}
90969096
}
90979097
response = authenticated_client.patch(
9098-
reverse("lighthouse-config"),
9098+
reverse("lighthouse-configurations"),
90999099
data=payload,
91009100
content_type=API_JSON_CONTENT_TYPE,
91019101
)
@@ -9116,7 +9116,7 @@ def test_lighthouse_tenant_config_update_invalid_json_format(
91169116

91179117
# Send invalid JSON
91189118
response = authenticated_client.patch(
9119-
reverse("lighthouse-config"),
9119+
reverse("lighthouse-configurations"),
91209120
data="invalid json",
91219121
content_type=API_JSON_CONTENT_TYPE,
91229122
)

api/src/backend/api/v1/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3197,7 +3197,7 @@ class LighthouseTenantConfigSerializer(RLSSerializer):
31973197

31983198
def get_url(self, obj):
31993199
request = self.context.get("request")
3200-
return reverse("lighthouse-config", request=request)
3200+
return reverse("lighthouse-configurations", request=request)
32013201

32023202
class Meta:
32033203
model = LighthouseTenantConfiguration

api/src/backend/api/v1/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
LighthouseTenantConfigViewSet.as_view(
157157
{"get": "list", "patch": "partial_update"}
158158
),
159-
name="lighthouse-config",
159+
name="lighthouse-configurations",
160160
),
161161
# API endpoint to start SAML SSO flow
162162
path(

0 commit comments

Comments
 (0)