Skip to content

Commit

Permalink
feat: run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Apr 24, 2024
1 parent 039a6e7 commit 42f994f
Show file tree
Hide file tree
Showing 43 changed files with 295 additions and 245 deletions.
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_applied_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from core.models import ReferenceControl, AppliedControl
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic applied control data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from core.models import Asset
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic asset data for tests
Expand Down
7 changes: 3 additions & 4 deletions backend/app_tests/api/test_api_compliance_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from core.models import Project
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic compliance assessment data for tests
Expand Down Expand Up @@ -126,7 +125,7 @@ def test_get_compliance_assessments(self, test):
"id": str(Framework.objects.all()[0].id),
"str": str(Framework.objects.all()[0]),
"min_score": 0,
"max_score": 100
"max_score": 100,
},
},
user_group=test.user_group,
Expand Down Expand Up @@ -159,7 +158,7 @@ def test_create_compliance_assessments(self, test):
"id": str(Framework.objects.all()[0].id),
"str": str(Framework.objects.all()[0]),
"min_score": Framework.objects.all()[0].min_score,
"max_score": Framework.objects.all()[0].max_score
"max_score": Framework.objects.all()[0].max_score,
},
},
user_group=test.user_group,
Expand Down Expand Up @@ -204,7 +203,7 @@ def test_update_compliance_assessments(self, test):
"id": str(Framework.objects.all()[0].id),
"str": str(Framework.objects.all()[0]),
"min_score": Framework.objects.all()[0].min_score,
"max_score": Framework.objects.all()[0].max_score
"max_score": Framework.objects.all()[0].max_score,
},
},
user_group=test.user_group,
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_evidences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from core.models import Evidence
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic evidence data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from rest_framework.test import APIClient
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic folder data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from iam.models import Folder
from rest_framework import status

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries, EndpointTestsUtils


Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from core.models import Policy
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic policy data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from core.models import Project
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic project data for tests
Expand Down
3 changes: 1 addition & 2 deletions backend/app_tests/api/test_api_reference_controls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pytest
from rest_framework.status import HTTP_403_FORBIDDEN, HTTP_400_BAD_REQUEST
from rest_framework.status import HTTP_403_FORBIDDEN
from rest_framework.test import APIClient
from core.models import ReferenceControl
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic reference control data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_requirement_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from core.models import Project, AppliedControl
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic requirement assessment data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_requirement_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from core.models import RequirementNode, Framework
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries, EndpointTestsUtils

# Generic requirement data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_risk_acceptances.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
)
from iam.models import Folder, UserGroup

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic risk acceptance data for tests
Expand Down
3 changes: 1 addition & 2 deletions backend/app_tests/api/test_api_risk_assessments.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
from rest_framework.test import APIClient
from core.models import Project, RiskAssessment, RiskMatrix
from iam.models import Folder, User
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic project data for tests
Expand Down
1 change: 0 additions & 1 deletion backend/app_tests/api/test_api_risk_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
)
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic project data for tests
Expand Down
3 changes: 1 addition & 2 deletions backend/app_tests/api/test_api_threats.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pytest
from rest_framework.status import HTTP_403_FORBIDDEN, HTTP_400_BAD_REQUEST
from rest_framework.status import HTTP_403_FORBIDDEN
from rest_framework.test import APIClient
from core.models import Threat
from iam.models import Folder

from test_vars import GROUPS_PERMISSIONS
from test_utils import EndpointTestsQueries

# Generic threat data for tests
Expand Down
3 changes: 1 addition & 2 deletions backend/app_tests/api/test_api_user_groups.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
from core.models import User

from iam.models import Folder, UserGroup, RoleAssignment
from iam.models import RoleAssignment
from test_vars import GROUPS_PERMISSIONS, TEST_USER_EMAIL
from test_utils import EndpointTestsQueries


@pytest.mark.django_db
Expand Down
2 changes: 1 addition & 1 deletion backend/app_tests/api/test_api_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rest_framework.test import APIClient
from iam.models import User

from test_vars import GROUPS_PERMISSIONS, USERS_ENDPOINT as API_ENDPOINT
from test_vars import USERS_ENDPOINT as API_ENDPOINT
from test_utils import EndpointTestsQueries

# Generic user data for tests
Expand Down
7 changes: 3 additions & 4 deletions backend/app_tests/api/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIClient
from ciso_assistant.settings import EMAIL_HOST, EMAIL_HOST_RESCUE

from test_vars import *

Expand Down Expand Up @@ -753,7 +752,7 @@ def update_object(
), f"{verbose_name} object detail can be accessed outside the domain"
else:
if (
verbose_name is not "Users"
verbose_name != "Users"
): # Users don't have permission to view users details
assert (
response.status_code == status.HTTP_200_OK
Expand Down Expand Up @@ -893,7 +892,7 @@ def delete_object(
), f"{verbose_name} object detail can be accessed outside the domain"
else:
if (
verbose_name is not "Users"
verbose_name != "Users"
): # Users don't have permission to view users details
assert (
response.status_code == status.HTTP_200_OK
Expand Down Expand Up @@ -1013,7 +1012,7 @@ def compare_results(
reference = authenticated_client.get(reference_url)
assert (
reference.status_code == status.HTTP_200_OK
), f"reference endpoint is not accessible"
), "reference endpoint is not accessible"

for object in reference.json()["objects"]["framework"][
object_name.lower().replace(" ", "_")
Expand Down
8 changes: 3 additions & 5 deletions backend/core/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from django.core.exceptions import ValidationError
import uuid

from ciso_assistant import settings


class AbstractBaseModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Expand Down Expand Up @@ -92,9 +90,9 @@ def clean(self) -> None:
if not self.is_unique_in_scope(scope=scope, fields_to_check=_fields_to_check):
for field in _fields_to_check:
if not self.is_unique_in_scope(scope=scope, fields_to_check=[field]):
field_errors[field] = (
f"{getattr(self, field)} is already used in this scope. Please choose another value."
)
field_errors[
field
] = f"{getattr(self, field)} is already used in this scope. Please choose another value."
super().clean()
if field_errors:
raise ValidationError(field_errors)
Expand Down
48 changes: 24 additions & 24 deletions backend/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def __init__(self, recommended_reference_controls=None, *args, **kwargs) -> None
def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
if self.recommended_reference_controls:
context["recommended_reference_controls"] = (
self.recommended_reference_controls
)
context[
"recommended_reference_controls"
] = self.recommended_reference_controls
return context


Expand Down Expand Up @@ -127,31 +127,31 @@ def __init__(self, *args, **kwargs):
f.widget.attrs["id"] = (
f"id_{model_name}_{fname}" if model_name else f"id_{fname}"
)
f.widget.attrs["class"] = (
"bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
)
f.widget.attrs[
"class"
] = "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
if input_type in select_inputs:
f.widget.attrs["id"] = f"id_{model_name}_{fname}"
f.widget.attrs["autocomplete"] = (
"off" # workaround for Firefox behavior: https://stackoverflow.com/questions/4831848/firefox-ignores-option-selected-selected
)
f.widget.attrs["class"] = (
"bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 disabled:opacity-50"
)
f.widget.attrs[
"autocomplete"
] = "off" # workaround for Firefox behavior: https://stackoverflow.com/questions/4831848/firefox-ignores-option-selected-selected
f.widget.attrs[
"class"
] = "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 disabled:opacity-50"
if input_type == Textarea:
f.widget.attrs["class"] = (
"block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500"
)
f.widget.attrs[
"class"
] = "block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500"
if input_type == CheckboxInput:
f.widget.attrs["id"] = f"id_{model_name}_{fname}"
f.widget.attrs["class"] = (
"w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500"
)
f.widget.attrs[
"class"
] = "w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500"
if input_type == DefaultDateInput:
f.widget.attrs["id"] = f"id_{model_name}_{fname}"
f.widget.attrs["class"] = (
"bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
)
f.widget.attrs[
"class"
] = "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
if input_type == Select:
self.default_if_one(fname)

Expand Down Expand Up @@ -181,9 +181,9 @@ def __init__(self, *args, **kwargs):
super(__class__, self).__init__(*args, **kwargs)
for password in self.fields.items():
password[1].widget.attrs["class"] = style
self.fields["terms_service"].widget.attrs["class"] = (
"ml-2 rounded border-gray-300 shadow-sm focus:border-indigo-600 focus:ring focus:ring-indigo-500 focus:ring-opacity-50 text-indigo-500"
)
self.fields["terms_service"].widget.attrs[
"class"
] = "ml-2 rounded border-gray-300 shadow-sm focus:border-indigo-600 focus:ring focus:ring-indigo-500 focus:ring-opacity-50 text-indigo-500"
self.fields["terms_service"].widget.attrs["id"] = "terms_service"

terms_service = forms.BooleanField(label=_("terms and conditions of use"))
4 changes: 3 additions & 1 deletion backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def get_sorted_requirement_nodes_rec(
"ra_id": str(req_as.id) if requirements_assessed else None,
"status": req_as.status if requirements_assessed else None,
"score": req_as.score if requirements_assessed else None,
"max_score": req_as.compliance_assessment.framework.max_score if requirements_assessed else None,
"max_score": req_as.compliance_assessment.framework.max_score
if requirements_assessed
else None,
"status_display": req_as.get_status_display()
if requirements_assessed
else None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Generated by Django 5.0.2 on 2024-03-04 20:07

import django.db.models.deletion
import iam.models
import uuid
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@


class Migration(migrations.Migration):

dependencies = [
('core', '0008_alter_complianceassessment_status_and_more'),
("core", "0008_alter_complianceassessment_status_and_more"),
]

operations = [
migrations.AddField(
model_name='framework',
name='max_score',
field=models.IntegerField(default=100, verbose_name='Maximum score'),
model_name="framework",
name="max_score",
field=models.IntegerField(default=100, verbose_name="Maximum score"),
),
migrations.AddField(
model_name='framework',
name='min_score',
field=models.IntegerField(default=0, verbose_name='Minimum score'),
model_name="framework",
name="min_score",
field=models.IntegerField(default=0, verbose_name="Minimum score"),
),
migrations.AddField(
model_name='requirementassessment',
name='score',
field=models.IntegerField(blank=True, null=True, verbose_name='Score'),
model_name="requirementassessment",
name="score",
field=models.IntegerField(blank=True, null=True, verbose_name="Score"),
),
]
11 changes: 6 additions & 5 deletions backend/core/migrations/0010_framework_score_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@


class Migration(migrations.Migration):

dependencies = [
('core', '0009_framework_max_score_framework_min_score_and_more'),
("core", "0009_framework_max_score_framework_min_score_and_more"),
]

operations = [
migrations.AddField(
model_name='framework',
name='score_definition',
field=models.JSONField(blank=True, null=True, verbose_name='Score definition'),
model_name="framework",
name="score_definition",
field=models.JSONField(
blank=True, null=True, verbose_name="Score definition"
),
),
]
Loading

0 comments on commit 42f994f

Please sign in to comment.