Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/schemas/dfiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def parse_yaml(cls, yaml_string: str) -> dict[str, Any]:

@classmethod
def from_yaml(cls, yaml_string: str) -> "DFIQBase":
yaml_data = yaml.safe_load(yaml_string)
yaml_data = cls.parse_yaml(yaml_string)
return TYPE_MAPPING[yaml_data["type"]].from_yaml(yaml_string)

def to_yaml(self, sort_keys=False) -> str:
Expand Down
9 changes: 2 additions & 7 deletions core/web/apiv2/dfiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class NewDFIQRequest(BaseModel):
model_config = ConfigDict(extra="forbid")

dfiq_yaml: str
dfiq_type: dfiq.DFIQType
update_indicators: bool = False


Expand All @@ -40,7 +39,6 @@ class PatchDFIQRequest(BaseModel):

dfiq_yaml: str | None = None
dfiq_object: dfiq.DFIQTypes | None = None
dfiq_type: dfiq.DFIQType
update_indicators: bool = False


Expand Down Expand Up @@ -131,10 +129,7 @@ def from_archive(httpreq: Request, archive: UploadFile) -> dict[str, int]:
def new_from_yaml(httpreq: Request, request: NewDFIQRequest) -> dfiq.DFIQTypes:
"""Creates a new DFIQ object in the database."""
try:
new = cast(
"dfiq.DFIQTypes",
dfiq.TYPE_MAPPING[request.dfiq_type].from_yaml(request.dfiq_yaml),
)
new = cast("dfiq.DFIQTypes", dfiq.DFIQBase.from_yaml(request.dfiq_yaml))
except ValueError as error:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(error))

Expand Down Expand Up @@ -276,7 +271,7 @@ def to_archive(httpreq: Request, request: DFIQSearchRequest) -> FileResponse:
def validate_dfiq_yaml(request: DFIQValidateRequest) -> DFIQValidateResponse:
"""Validates a DFIQ YAML string."""
try:
obj = dfiq.TYPE_MAPPING[request.dfiq_type].from_yaml(request.dfiq_yaml)
obj = dfiq.DFIQBase.from_yaml(request.dfiq_yaml)
except ValidationError as error:
error_objs: list[dict] = []
for pydantic_error in error.errors():
Expand Down
21 changes: 4 additions & 17 deletions tests/apiv2/dfiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_config(self) -> None:
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.question,
},
)
data = response.json()
Expand All @@ -70,7 +69,6 @@ def test_new_dfiq_scenario(self) -> None:
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.scenario,
},
)
data = response.json()
Expand All @@ -92,7 +90,6 @@ def test_get_dfiq_by_name(self) -> None:
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.scenario,
},
)
data = response.json()
Expand Down Expand Up @@ -121,7 +118,6 @@ def test_new_dfiq_facet(self) -> None:
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.facet,
},
)
data = response.json()
Expand Down Expand Up @@ -161,7 +157,6 @@ def test_new_dfiq_question(self) -> None:
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.question,
},
)
data = response.json()
Expand Down Expand Up @@ -256,7 +251,7 @@ def test_dfiq_patch_yaml(self) -> None:

response = client.patch(
f"/api/v2/dfiq/{scenario.id}",
json={"dfiq_yaml": yaml_string, "dfiq_type": scenario.type},
json={"dfiq_yaml": yaml_string},
)
data = response.json()
self.assertEqual(response.status_code, 200, data)
Expand Down Expand Up @@ -323,7 +318,7 @@ def test_dfiq_patch_object(self):
question_json = json.loads(question.model_dump_json())
response = client.patch(
f"/api/v2/dfiq/{question.id}",
json={"dfiq_object": question_json, "dfiq_type": question.type},
json={"dfiq_object": question_json},
)
data = response.json()
self.assertEqual(response.status_code, 200, data)
Expand Down Expand Up @@ -370,7 +365,7 @@ def test_dfiq_patch_updates_parents(self) -> None:

response = client.patch(
f"/api/v2/dfiq/{facet.id}",
json={"dfiq_yaml": facet.to_yaml(), "dfiq_type": facet.type},
json={"dfiq_yaml": facet.to_yaml()},
)
data = response.json()
self.assertEqual(response.status_code, 200, data)
Expand Down Expand Up @@ -428,7 +423,7 @@ def test_dfiq_patch_prunes_parents(self) -> None:

response = client.patch(
f"/api/v2/dfiq/{facet.id}",
json={"dfiq_yaml": facet.to_yaml(), "dfiq_type": facet.type},
json={"dfiq_yaml": facet.to_yaml()},
)
data = response.json()
self.assertEqual(response.status_code, 200, data)
Expand Down Expand Up @@ -490,7 +485,6 @@ def test_dfiq_patch_question_updates_indicators(self) -> None:
f"/api/v2/dfiq/{question.id}",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": question.type,
"update_indicators": False,
},
)
Expand All @@ -504,7 +498,6 @@ def test_dfiq_patch_question_updates_indicators(self) -> None:
f"/api/v2/dfiq/{question.id}",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": question.type,
"update_indicators": True,
},
)
Expand All @@ -522,7 +515,6 @@ def test_wrong_parent(self) -> None:
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.facet,
},
)
data = response.json()
Expand All @@ -539,7 +531,6 @@ def test_valid_dfiq_yaml(self) -> None:
"/api/v2/dfiq/validate",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.scenario,
"check_id": True,
},
)
Expand All @@ -554,7 +545,6 @@ def test_valid_dfiq_yaml(self) -> None:
"/api/v2/dfiq/validate",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.facet,
"check_id": True,
},
)
Expand All @@ -569,7 +559,6 @@ def test_valid_dfiq_yaml(self) -> None:
"/api/v2/dfiq/validate",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.question,
"check_id": True,
},
)
Expand All @@ -585,7 +574,6 @@ def test_standalone_question_creation(self):
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.question,
},
)
data = response.json()
Expand Down Expand Up @@ -701,7 +689,6 @@ def test_get_multiple(self):
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": dfiq.DFIQType.scenario,
},
)
data = response.json()
Expand Down
3 changes: 0 additions & 3 deletions tests/apiv2/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ def test_new_dfiq_makes_timeline_log(self):
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": "question",
"update_indicators": True,
},
)
Expand Down Expand Up @@ -430,7 +429,6 @@ def test_delete_dfiq_makes_timeline_log(self):
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": "facet",
},
)

Expand All @@ -445,7 +443,6 @@ def test_delete_dfiq_makes_timeline_log(self):
"/api/v2/dfiq/from_yaml",
json={
"dfiq_yaml": yaml_string,
"dfiq_type": "question",
},
)
data = response.json()
Expand Down
Loading