Skip to content

Commit

Permalink
Merge pull request #306 from intuitem/CA-344-add-github-workflows-to-…
Browse files Browse the repository at this point in the history
…check-for-proper-formatting

Format code base and update linting workflows
  • Loading branch information
nas-tabchiche authored Apr 22, 2024
2 parents 679c699 + 136f2e4 commit cca89a2
Show file tree
Hide file tree
Showing 89 changed files with 1,958 additions and 1,634 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/backend-linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
working-directory: ${{env.working-directory}}
run: |
python -m pip install ruff
- name: ruff
- name: Run ruff format check
working-directory: ${{env.working-directory}}
run: ruff check .
run: ruff format --check .
# NOTE: The following will be uncommented once the codebase is cleaned up
# - name: ruff
# working-directory: ${{env.working-directory}}
# run: ruff check .
33 changes: 20 additions & 13 deletions .github/workflows/frontend-linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install latest npm
- name: Install prettier
working-directory: ${{env.working-directory}}
run: |
npm install -g npm &&
npm --version &&
npm list -g --depth 0
- name: Install dependencies
run: npm install --save-dev prettier
- name: Run prettier
working-directory: ${{env.working-directory}}
run: npm ci
- name: Run prettier check & eslint
working-directory: ${{env.working-directory}}
run: npm run lint
- name: Run svelte-check
working-directory: ${{env.working-directory}}
run: npm run check
run: npx prettier --check .
# NOTE: The following will be uncommented once the codebase is cleaned up
# - name: Install latest npm
# working-directory: ${{env.working-directory}}
# run: |
# npm install -g npm &&
# npm --version &&
# npm list -g --depth 0
# - name: Install dependencies
# working-directory: ${{env.working-directory}}
# run: npm ci
# - name: Run prettier check & eslint
# working-directory: ${{env.working-directory}}
# run: npm run lint
# - name: Run svelte-check
# working-directory: ${{env.working-directory}}
# run: npm run check
15 changes: 12 additions & 3 deletions backend/app_tests/api/test_api_compliance_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def test_get_compliance_assessments(self, test):
"framework": Framework.objects.all()[0],
},
{
"project": {"id": str(project.id), "str": project.folder.name + "/" + project.name},
"project": {
"id": str(project.id),
"str": project.folder.name + "/" + project.name,
},
"framework": {
"id": str(Framework.objects.all()[0].id),
"str": str(Framework.objects.all()[0]),
Expand Down Expand Up @@ -146,7 +149,10 @@ def test_create_compliance_assessments(self, test):
"framework": str(Framework.objects.all()[0].id),
},
{
"project": {"id": str(project.id), "str": project.folder.name + "/" + project.name},
"project": {
"id": str(project.id),
"str": project.folder.name + "/" + project.name,
},
"framework": {
"id": str(Framework.objects.all()[0].id),
"str": str(Framework.objects.all()[0]),
Expand Down Expand Up @@ -186,7 +192,10 @@ def test_update_compliance_assessments(self, test):
"framework": str(Framework.objects.all()[1].id),
},
{
"project": {"id": str(project.id), "str": project.folder.name + "/" + project.name},
"project": {
"id": str(project.id),
"str": project.folder.name + "/" + project.name,
},
"framework": {
"id": str(Framework.objects.all()[0].id),
"str": str(Framework.objects.all()[0]),
Expand Down
49 changes: 27 additions & 22 deletions backend/app_tests/api/test_api_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ def test_import_frameworks(self, test):
Framework.objects.all().count() == 0
), "libraries are already imported in the database"
EndpointTestsQueries.Auth.get_object(
test.client, "Frameworks", user_group=test.user_group,
test.client,
"Frameworks",
user_group=test.user_group,
)

EndpointTestsQueries.Auth.import_object(
test.client, "Framework", user_group=test.user_group
)

assert (
Framework.objects.all().count() == (1 if not EndpointTestsUtils.expected_request_response(
"add", "library", str(test.folder), test.user_group
)[0] else 0)
assert Framework.objects.all().count() == (
1
if not EndpointTestsUtils.expected_request_response(
"add", "library", str(test.folder), test.user_group
)[0]
else 0
), "Frameworks are not correctly imported in the database"

# Uses the API endpoint to assert that the library was properly imported
EndpointTestsQueries.Auth.get_object(
test.client,
Expand All @@ -93,8 +97,8 @@ def test_import_frameworks(self, test):
base_count=1,
user_group=test.user_group,
fails=EndpointTestsUtils.expected_request_response(
"add", "library", str(test.folder), test.user_group
)[0]
"add", "library", str(test.folder), test.user_group
)[0],
)

def test_delete_frameworks(self, test):
Expand Down Expand Up @@ -133,10 +137,12 @@ def test_import_risk_matrix(self, test):
test.client, "Risk matrix", user_group=test.user_group
)

assert (
RiskMatrix.objects.all().count() == (1 if not EndpointTestsUtils.expected_request_response(
"add", "library", str(test.folder), test.user_group
)[0] else 0)
assert RiskMatrix.objects.all().count() == (
1
if not EndpointTestsUtils.expected_request_response(
"add", "library", str(test.folder), test.user_group
)[0]
else 0
), "Risk matrices are not correctly imported in the database"

# Uses the API endpoint to assert that the library was properly imported
Expand All @@ -153,8 +159,8 @@ def test_import_risk_matrix(self, test):
base_count=1,
user_group=test.user_group,
fails=EndpointTestsUtils.expected_request_response(
"add", "library", str(test.folder), test.user_group
)[0]
"add", "library", str(test.folder), test.user_group
)[0],
)

def test_delete_matrix(self, test):
Expand All @@ -163,14 +169,13 @@ def test_delete_matrix(self, test):
EndpointTestsQueries.Auth.import_object(test.admin_client, "Risk matrix")
EndpointTestsQueries.Auth.delete_object(
test.client,
"Risk matrices",
RiskMatrix,
"Risk matrices",
RiskMatrix,
user_group=test.user_group,
scope="Global",
**({
"fails": True,
"expected_status": status.HTTP_403_FORBIDDEN
}
if test.user_group == "BI-UG-DMA" else {} # Domain Manager can't delete Global risk matrices (i.e. imported matrices)
)
**(
{"fails": True, "expected_status": status.HTTP_403_FORBIDDEN}
if test.user_group == "BI-UG-DMA"
else {} # Domain Manager can't delete Global risk matrices (i.e. imported matrices)
),
)
4 changes: 2 additions & 2 deletions backend/app_tests/api/test_api_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_get_projects(self, test):
"lc_status": PROJECT_STATUS[1],
},
user_group=test.user_group,
scope=str(test.folder)
scope=str(test.folder),
)

def test_create_projects(self, test):
Expand All @@ -121,7 +121,7 @@ def test_create_projects(self, test):
"lc_status": PROJECT_STATUS[1],
},
user_group=test.user_group,
scope=str(test.folder)
scope=str(test.folder),
)

def test_update_projects(self, test):
Expand Down
15 changes: 12 additions & 3 deletions backend/app_tests/api/test_api_risk_assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def test_get_risk_assessments(self, test):
"risk_matrix": risk_matrix,
},
{
"project": {"id": str(project.id), "str": project.folder.name + "/" + project.name},
"project": {
"id": str(project.id),
"str": project.folder.name + "/" + project.name,
},
"risk_matrix": {"id": str(risk_matrix.id), "str": str(risk_matrix)},
},
user_group=test.user_group,
Expand All @@ -147,7 +150,10 @@ def test_create_risk_assessments(self, test):
"risk_matrix": str(risk_matrix.id),
},
{
"project": {"id": str(project.id), "str": project.folder.name + "/" + project.name},
"project": {
"id": str(project.id),
"str": project.folder.name + "/" + project.name,
},
"risk_matrix": {"id": str(risk_matrix.id), "str": str(risk_matrix)},
},
user_group=test.user_group,
Expand Down Expand Up @@ -185,7 +191,10 @@ def test_update_risk_assessments(self, test):
"risk_matrix": str(risk_matrix2.id),
},
{
"project": {"id": str(project.id), "str": project.folder.name + "/" + project.name},
"project": {
"id": str(project.id),
"str": project.folder.name + "/" + project.name,
},
"risk_matrix": {"id": str(risk_matrix.id), "str": str(risk_matrix)},
},
user_group=test.user_group,
Expand Down
8 changes: 4 additions & 4 deletions backend/app_tests/api/test_api_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_get_users(self, test):
base_count=2,
item_search_field="email",
user_group=test.user_group,
scope="Global"
scope="Global",
)

def test_create_users(self, test):
Expand All @@ -100,7 +100,7 @@ def test_create_users(self, test):
base_count=2,
item_search_field="email",
user_group=test.user_group,
scope="Global"
scope="Global",
)

def test_update_users(self, test):
Expand All @@ -117,7 +117,7 @@ def test_update_users(self, test):
"last_name": "new" + USER_NAME,
},
user_group=test.user_group,
scope="Global"
scope="Global",
)

def test_delete_users(self, test):
Expand All @@ -129,7 +129,7 @@ def test_delete_users(self, test):
User,
{"email": USER_EMAIL, "first_name": USER_FIRSTNAME, "last_name": USER_NAME},
user_group=test.user_group,
scope="Global"
scope="Global",
)

def test_uniqueness_emails(self, test):
Expand Down
4 changes: 1 addition & 3 deletions backend/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ def startup(**kwargs):

print("startup handler: initialize database")

reader_permissions = Permission.objects.filter(
codename__in=READER_PERMISSIONS_LIST
)
reader_permissions = Permission.objects.filter(codename__in=READER_PERMISSIONS_LIST)

approver_permissions = Permission.objects.filter(
codename__in=APPROVER_PERMISSIONS_LIST
Expand Down
4 changes: 3 additions & 1 deletion backend/core/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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
16 changes: 12 additions & 4 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,24 @@ def get_sorted_requirement_nodes_rec(
for requirement_node in requirement_nodes
if requirement_node.parent_urn == node.urn
]
req_as = requirement_assessment_from_requirement_id[str(node.id)] if requirements_assessed else None
req_as = (
requirement_assessment_from_requirement_id[str(node.id)]
if requirements_assessed
else None
)
result[str(node.id)] = {
"urn": node.urn,
"parent_urn": node.parent_urn,
"ref_id": node.ref_id,
"name": node.name,
"ra_id": str(req_as.id) if requirements_assessed else None,
"status": req_as.status if requirements_assessed else None,
"status_display": req_as.get_status_display() if requirements_assessed else None,
"status_i18n": camel_case(req_as.status) if requirements_assessed else None,
"status_display": req_as.get_status_display()
if requirements_assessed
else None,
"status_i18n": camel_case(req_as.status)
if requirements_assessed
else None,
"node_content": node.display_long,
"style": "node",
"assessable": node.assessable,
Expand Down Expand Up @@ -494,7 +502,7 @@ def assessment_per_status(user: User, model: RiskAssessment | ComplianceAssessme
v = {"value": count, "itemStyle": {"color": color_map[st[0]]}}
values.append(v)
labels.append(st[1])
#add undefined as the first element in the labels to balance the values
# add undefined as the first element in the labels to balance the values
labels.insert(0, "undefined")
local_lables = [camel_case(str(label)) for label in labels]
return {"localLables": local_lables, "labels": labels, "values": values}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@


class Migration(migrations.Migration):

dependencies = [
('core', '0006_remove_securitymeasure_security_function_and_more'),
("core", "0006_remove_securitymeasure_security_function_and_more"),
]

operations = [
migrations.AlterField(
model_name='requirementlevel',
name='framework',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='requirement_levels', to='core.framework', verbose_name='Framework'),
model_name="requirementlevel",
name="framework",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="requirement_levels",
to="core.framework",
verbose_name="Framework",
),
),
migrations.AlterField(
model_name='requirementnode',
name='framework',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='requirement_nodes', to='core.framework', verbose_name='Framework'),
model_name="requirementnode",
name="framework",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="requirement_nodes",
to="core.framework",
verbose_name="Framework",
),
),
]
Loading

0 comments on commit cca89a2

Please sign in to comment.