-
Notifications
You must be signed in to change notification settings - Fork 375
feat: created backend checking if the objects on creation/edit are relevant in domain context #1769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
78367fb
555a4c1
a2a367f
799605c
c0d0881
c2dd884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -160,6 +160,52 @@ def test_create_evidences(self, test): | |||||||||||||||||||
def test_update_evidences(self, test): | ||||||||||||||||||||
"""test to update evidences with the API with authentication""" | ||||||||||||||||||||
|
||||||||||||||||||||
folder = Folder.objects.create(name="test2") | ||||||||||||||||||||
applied_control = AppliedControl.objects.create(name="test", folder=test.folder) | ||||||||||||||||||||
applied_control2 = AppliedControl.objects.create( | ||||||||||||||||||||
name="test2", folder=test.folder | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
Comment on lines
+163
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused variable to eliminate code smell. The variable - folder = Folder.objects.create(name="test2") 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.8.2)163-163: Local variable Remove assignment to unused variable (F841) |
||||||||||||||||||||
with open( | ||||||||||||||||||||
path.join(path.dirname(path.dirname(__file__)), EVIDENCE_ATTACHMENT), "rb" | ||||||||||||||||||||
) as file: | ||||||||||||||||||||
EndpointTestsQueries.Auth.update_object( | ||||||||||||||||||||
test.client, | ||||||||||||||||||||
"Evidences", | ||||||||||||||||||||
Evidence, | ||||||||||||||||||||
{ | ||||||||||||||||||||
"name": EVIDENCE_NAME, | ||||||||||||||||||||
"description": EVIDENCE_DESCRIPTION, | ||||||||||||||||||||
"link": EVIDENCE_LINK, | ||||||||||||||||||||
"folder": test.folder, | ||||||||||||||||||||
"applied_controls": [applied_control], | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
"name": "new " + EVIDENCE_NAME, | ||||||||||||||||||||
"description": "new " + EVIDENCE_DESCRIPTION, | ||||||||||||||||||||
"link": EVIDENCE_LINK + "/new", | ||||||||||||||||||||
"folder": str(test.folder.id), | ||||||||||||||||||||
"applied_controls": [str(applied_control2.id)], | ||||||||||||||||||||
"attachment": file, | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
"folder": {"id": str(test.folder.id), "str": test.folder.name}, | ||||||||||||||||||||
"applied_controls": [ | ||||||||||||||||||||
{ | ||||||||||||||||||||
"id": str(applied_control.id), | ||||||||||||||||||||
"str": applied_control.name, | ||||||||||||||||||||
} | ||||||||||||||||||||
], | ||||||||||||||||||||
}, | ||||||||||||||||||||
{ | ||||||||||||||||||||
"attachment": EVIDENCE_ATTACHMENT, | ||||||||||||||||||||
}, | ||||||||||||||||||||
query_format="multipart", | ||||||||||||||||||||
user_group=test.user_group, | ||||||||||||||||||||
) | ||||||||||||||||||||
|
||||||||||||||||||||
"""def test_update_evidences_fails_with_out_of_scope_object(self, test): | ||||||||||||||||||||
|
||||||||||||||||||||
folder = Folder.objects.create(name="test2") | ||||||||||||||||||||
applied_control = AppliedControl.objects.create(name="test", folder=test.folder) | ||||||||||||||||||||
applied_control2 = AppliedControl.objects.create(name="test2", folder=folder) | ||||||||||||||||||||
|
@@ -200,7 +246,7 @@ def test_update_evidences(self, test): | |||||||||||||||||||
}, | ||||||||||||||||||||
query_format="multipart", | ||||||||||||||||||||
user_group=test.user_group, | ||||||||||||||||||||
) | ||||||||||||||||||||
)""" | ||||||||||||||||||||
|
||||||||||||||||||||
def test_delete_evidences(self, test): | ||||||||||||||||||||
"""test to delete evidences with the API with authentication""" | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -209,6 +209,93 @@ def test_create_requirement_assessments(self, test): | |||||||
def test_update_requirement_assessments(self, test): | ||||||||
"""test to update requirement assessments with the API with authentication""" | ||||||||
|
||||||||
EndpointTestsQueries.Auth.import_object(test.admin_client, "Framework") | ||||||||
folder = Folder.objects.create(name="test2") | ||||||||
Comment on lines
+212
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused variable to maintain clarity. The - folder = Folder.objects.create(name="test2") 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.8.2)213-213: Local variable Remove assignment to unused variable (F841) |
||||||||
compliance_assessment = ComplianceAssessment.objects.create( | ||||||||
name="test", | ||||||||
perimeter=Perimeter.objects.create(name="test", folder=test.folder), | ||||||||
framework=Framework.objects.all()[0], | ||||||||
) | ||||||||
compliance_assessment2 = ComplianceAssessment.objects.create( | ||||||||
name="test2", | ||||||||
perimeter=Perimeter.objects.create(name="test2", folder=test.folder), | ||||||||
framework=Framework.objects.all()[0], | ||||||||
) | ||||||||
applied_control = AppliedControl.objects.create(name="test", folder=test.folder) | ||||||||
|
||||||||
EndpointTestsQueries.Auth.update_object( | ||||||||
test.client, | ||||||||
"Requirement Assessments", | ||||||||
RequirementAssessment, | ||||||||
{ | ||||||||
"status": REQUIREMENT_ASSESSMENT_STATUS, | ||||||||
"observation": REQUIREMENT_ASSESSMENT_OBSERVATION, | ||||||||
"folder": test.folder, | ||||||||
"compliance_assessment": compliance_assessment, | ||||||||
"requirement": RequirementNode.objects.all()[0], | ||||||||
"score": None, | ||||||||
}, | ||||||||
{ | ||||||||
"status": REQUIREMENT_ASSESSMENT_STATUS2, | ||||||||
"observation": "new " + REQUIREMENT_ASSESSMENT_OBSERVATION, | ||||||||
"folder": str(test.folder.id), | ||||||||
"compliance_assessment": str(compliance_assessment2.id), | ||||||||
"requirement": str(RequirementNode.objects.all()[1].id), | ||||||||
"applied_controls": [str(applied_control.id)], | ||||||||
"score": 3, | ||||||||
}, | ||||||||
{ | ||||||||
"folder": {"id": str(test.folder.id), "str": test.folder.name}, | ||||||||
"compliance_assessment": { | ||||||||
"id": str(compliance_assessment.id), | ||||||||
"str": compliance_assessment.name, | ||||||||
}, | ||||||||
"requirement": { | ||||||||
"id": str(RequirementNode.objects.all()[0].id), | ||||||||
"urn": RequirementNode.objects.all()[0].urn, | ||||||||
"annotation": RequirementNode.objects.all()[0].annotation, | ||||||||
"name": RequirementNode.objects.all()[0].name, | ||||||||
"description": RequirementNode.objects.all()[0].description, | ||||||||
"typical_evidence": RequirementNode.objects.all()[ | ||||||||
0 | ||||||||
].typical_evidence, | ||||||||
"ref_id": RequirementNode.objects.all()[0].ref_id, | ||||||||
"associated_reference_controls": RequirementNode.objects.all()[ | ||||||||
0 | ||||||||
].associated_reference_controls, | ||||||||
"associated_threats": RequirementNode.objects.all()[ | ||||||||
0 | ||||||||
].associated_threats, | ||||||||
"parent_requirement": { | ||||||||
"str": RequirementNode.objects.all()[0].parent_requirement.get( | ||||||||
"str" | ||||||||
), | ||||||||
"urn": RequirementNode.objects.all()[0].parent_requirement.get( | ||||||||
"urn" | ||||||||
), | ||||||||
"id": str( | ||||||||
RequirementNode.objects.all()[0].parent_requirement.get( | ||||||||
"id" | ||||||||
) | ||||||||
), | ||||||||
"ref_id": RequirementNode.objects.all()[ | ||||||||
0 | ||||||||
].parent_requirement.get("ref_id"), | ||||||||
"name": RequirementNode.objects.all()[0].parent_requirement.get( | ||||||||
"name" | ||||||||
), | ||||||||
"description": RequirementNode.objects.all()[ | ||||||||
0 | ||||||||
].parent_requirement.get("description"), | ||||||||
} | ||||||||
if RequirementNode.objects.all()[0].parent_requirement | ||||||||
else None, | ||||||||
}, | ||||||||
}, | ||||||||
user_group=test.user_group, | ||||||||
) | ||||||||
|
||||||||
"""def test_update_requirement_assessments_fails_with_out_of_scope_object(self, test): | ||||||||
EndpointTestsQueries.Auth.import_object(test.admin_client, "Framework") | ||||||||
folder = Folder.objects.create(name="test2") | ||||||||
compliance_assessment = ComplianceAssessment.objects.create( | ||||||||
|
@@ -293,7 +380,7 @@ def test_update_requirement_assessments(self, test): | |||||||
}, | ||||||||
}, | ||||||||
user_group=test.user_group, | ||||||||
) | ||||||||
)""" | ||||||||
|
||||||||
def test_get_status_choices(self, test): | ||||||||
"""test to get requirement assessments status choices from the API with authentication""" | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,56 @@ def test_create_risk_acceptances(self, test): | |
def test_update_risk_acceptances(self, test): | ||
"""test to update risk acceptances with the API with authentication""" | ||
|
||
EndpointTestsQueries.Auth.import_object(test.admin_client, "Framework") | ||
approver = User.objects.create_user(email="[email protected]") | ||
UserGroup.objects.get(name="BI-UG-GAP").user_set.add(approver) | ||
approver2 = User.objects.create_user(email="[email protected]") | ||
UserGroup.objects.get(name="BI-UG-GAP").user_set.add(approver2) | ||
risk_scenario = RiskScenario.objects.create( | ||
name="test scenario", | ||
description="test description", | ||
risk_assessment=RiskAssessment.objects.create( | ||
name="test", | ||
perimeter=Perimeter.objects.create(name="test", folder=test.folder), | ||
risk_matrix=RiskMatrix.objects.create(name="test", folder=test.folder), | ||
), | ||
) | ||
|
||
EndpointTestsQueries.Auth.update_object( | ||
test.client, | ||
"Risk Acceptances", | ||
RiskAcceptance, | ||
{ | ||
"name": RISK_ACCEPTANCE_NAME, | ||
"description": RISK_ACCEPTANCE_DESCRIPTION, | ||
"expiry_date": RISK_ACCEPTANCE_EXPIRY_DATE, | ||
# 'state': RISK_ACCEPTANCE_STATE[0], | ||
"folder": test.folder, | ||
"approver": approver, | ||
}, | ||
{ | ||
"name": "new " + RISK_ACCEPTANCE_NAME, | ||
"description": "new " + RISK_ACCEPTANCE_DESCRIPTION, | ||
"expiry_date": "2024-05-05", | ||
"folder": str(test.folder.id), | ||
"approver": str(approver2.id), | ||
"risk_scenarios": [str(risk_scenario.id)], | ||
}, | ||
{ | ||
"folder": {"id": str(test.folder.id), "str": test.folder.name}, | ||
"approver": { | ||
"id": str(approver.id), | ||
"str": approver.email, | ||
"last_name": approver.last_name, | ||
"first_name": approver.first_name, | ||
}, | ||
# 'state': RISK_ACCEPTANCE_STATE[1], | ||
}, | ||
user_group=test.user_group, | ||
) | ||
|
||
"""def test_update_risk_acceptances(self, test): | ||
|
||
EndpointTestsQueries.Auth.import_object(test.admin_client, "Framework") | ||
folder = Folder.objects.create(name="test2") | ||
approver = User.objects.create_user(email="[email protected]") | ||
|
@@ -227,7 +277,7 @@ def test_update_risk_acceptances(self, test): | |
# 'state': RISK_ACCEPTANCE_STATE[1], | ||
}, | ||
user_group=test.user_group, | ||
) | ||
)""" | ||
|
||
def test_delete_risk_acceptances(self, test): | ||
"""test to delete risk acceptances with the API with authentication""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency in expected response structure
The test correctly updates the compliance assessment with new perimeter (perimeter2) and framework (Framework.objects.all()[1]), but the expected response structure still references the original objects.
Consider updating the expected response to match the updated values:
📝 Committable suggestion