Skip to content

Commit

Permalink
Merge branch 'main' into CA-747-Add-optional-secondary-score
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Jan 10, 2025
2 parents 656c86a + f94facf commit f385c0d
Show file tree
Hide file tree
Showing 13 changed files with 2,458 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend-linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Install ruff
working-directory: ${{env.working-directory}}
run: |
python -m pip install ruff
python -m pip install ruff==0.9.0
- name: Run ruff format check
working-directory: ${{env.working-directory}}
run: ruff format --check .
Expand Down
18 changes: 9 additions & 9 deletions backend/app_tests/api/test_api_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_import_frameworks(self, test):
lib_detail_response = lib_detail_response["framework"]

# Asserts that the library is not already loaded
assert (
Framework.objects.all().count() == 0
), "libraries are already loaded in the database"
assert Framework.objects.all().count() == 0, (
"libraries are already loaded in the database"
)
EndpointTestsQueries.Auth.get_object(
test.client,
"Frameworks",
Expand Down Expand Up @@ -114,9 +114,9 @@ def test_delete_frameworks(self, test):
"""test to delete frameworks with the API with authentication"""

EndpointTestsQueries.Auth.import_object(test.admin_client, "Framework")
assert (
Framework.objects.all().count() == 1
), "Frameworks are not correctly imported in the database"
assert Framework.objects.all().count() == 1, (
"Frameworks are not correctly imported in the database"
)

EndpointTestsQueries.Auth.delete_object(
test.client,
Expand All @@ -140,9 +140,9 @@ def test_import_risk_matrix(self, test):
lib_detail_response = lib_detail_response["risk_matrix"][0]

# Asserts that the library is not already loaded
assert (
RiskMatrix.objects.all().count() == 0
), "libraries are already loaded in the database"
assert RiskMatrix.objects.all().count() == 0, (
"libraries are already loaded in the database"
)
EndpointTestsQueries.Auth.get_object(
test.client, "Risk matrices", user_group=test.user_group
)
Expand Down
6 changes: 3 additions & 3 deletions backend/app_tests/api/test_api_user_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def test_group_permissions(self, test):
User.objects.get(email=TEST_USER_EMAIL)
)
for perm in GROUPS_PERMISSIONS[test.user_group]["perms"]:
assert (
perm in user_permissions.keys()
), f"Permission {perm} not found in user permissions (group: {test.user_group})"
assert perm in user_permissions.keys(), (
f"Permission {perm} not found in user permissions (group: {test.user_group})"
)
24 changes: 12 additions & 12 deletions backend/app_tests/api/test_api_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ def test_uniqueness_emails(self, test):
response = test.admin_client.post(url, data, format="json")

# Asserts that the user was not created
assert (
response.status_code == status.HTTP_400_BAD_REQUEST
), "users can be created with an already used email"
assert response.json() == {
"email": ["user with this email already exists."]
}, "users can be created with an already used email"
assert response.status_code == status.HTTP_400_BAD_REQUEST, (
"users can be created with an already used email"
)
assert response.json() == {"email": ["user with this email already exists."]}, (
"users can be created with an already used email"
)

def test_invalid_emails(self, test):
"""test to create users with the API with authentication and invalid emails"""
Expand All @@ -182,9 +182,9 @@ def test_invalid_emails(self, test):
response = test.admin_client.post(url, data, format="json")

# Asserts that the user was not created
assert (
response.status_code == status.HTTP_400_BAD_REQUEST
), f"users can be created with an invalid email ({email})"
assert response.json() == {
"email": ["Enter a valid email address."]
}, f"users can be created with an invalid email ({email})"
assert response.status_code == status.HTTP_400_BAD_REQUEST, (
f"users can be created with an invalid email ({email})"
)
assert response.json() == {"email": ["Enter a valid email address."]}, (
f"users can be created with an invalid email ({email})"
)
271 changes: 140 additions & 131 deletions backend/app_tests/api/test_utils.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/core/migrations/0040_riskscenario_ref_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_default_ref_id(risk_assessment):
x.ref_id for x in risk_assessment.risk_scenarios.all() if x.ref_id
]
nb_scenarios = len(scenarios_ref_ids) + 1
candidates = [f"R.{i+1}" for i in range(nb_scenarios)]
candidates = [f"R.{i + 1}" for i in range(nb_scenarios)]
return next(x for x in candidates if x not in scenarios_ref_ids)

for risk_assessment in RiskAssessment.objects.all():
Expand Down
2 changes: 1 addition & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ def get_security_objectives_display(self) -> list[dict[str, str]]:
key=lambda x: self.DEFAULT_SECURITY_OBJECTIVES.index(x[0]),
)
if content.get("is_enabled", False)
and content.get("value", -1) in range(0, 5)
and content.get("value", -1) in range(0, 4)
]

def get_disaster_recovery_objectives_display(self) -> list[dict[str, str]]:
Expand Down
2 changes: 1 addition & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ def get_build(request):
total, used, free = disk_info
disk_response = {
"Disk space": f"{humanize.naturalsize(total)}",
"Used": f"{humanize.naturalsize(used)} ({int((used/total)*100)} %)",
"Used": f"{humanize.naturalsize(used)} ({int((used / total) * 100)} %)",
}
else:
disk_response = {
Expand Down
Loading

0 comments on commit f385c0d

Please sign in to comment.