generated from bcgov/EPIC.scaffold
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04fe26e
commit dd9b572
Showing
9 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
compliance-api/src/compliance_api/resources/compliance_finding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""API endpoints for managing compliance finding resource.""" | ||
|
||
from http import HTTPStatus | ||
|
||
from flask_restx import Namespace, Resource | ||
|
||
from compliance_api.auth import auth | ||
from compliance_api.schemas import KeyValueSchema | ||
from compliance_api.services import ComplianceFindingService | ||
from compliance_api.utils.util import cors_preflight | ||
|
||
from .apihelper import Api as ApiHelper | ||
|
||
|
||
API = Namespace( | ||
"compliance-findings", | ||
description="Endpoints for compliance finding Management", | ||
) | ||
|
||
key_value_list_model = ApiHelper.convert_ma_schema_to_restx_model( | ||
API, KeyValueSchema(), "List" | ||
) | ||
|
||
|
||
@cors_preflight("GET, OPTIONS") | ||
@API.route("", methods=["GET", "OPTIONS"]) | ||
class ComplianceFindings(Resource): | ||
"""Resource for managing compliance findings.""" | ||
|
||
@staticmethod | ||
@API.response(code=200, description="Success", model=[key_value_list_model]) | ||
@ApiHelper.swagger_decorators( | ||
API, endpoint_description="Fetch all compliance findings" | ||
) | ||
@auth.require | ||
def get(): | ||
"""Fetch all compliance findings.""" | ||
compliance_findings = ComplianceFindingService.get_compliance_findings() | ||
list_schema = KeyValueSchema(many=True) | ||
return list_schema.dump(compliance_findings), HTTPStatus.OK |
53 changes: 53 additions & 0 deletions
53
compliance-api/src/compliance_api/resources/enforcement_action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright © 2024 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""API endpoints for managing enforcement action resource.""" | ||
|
||
from http import HTTPStatus | ||
|
||
from flask_restx import Namespace, Resource | ||
|
||
from compliance_api.auth import auth | ||
from compliance_api.schemas import KeyValueSchema | ||
from compliance_api.services import EnforcementActionService | ||
from compliance_api.utils.util import cors_preflight | ||
|
||
from .apihelper import Api as ApiHelper | ||
|
||
|
||
API = Namespace( | ||
"enforcement-actions", | ||
description="Endpoints for Enforcement Action Management", | ||
) | ||
|
||
key_value_list_model = ApiHelper.convert_ma_schema_to_restx_model( | ||
API, KeyValueSchema(), "List" | ||
) | ||
|
||
|
||
@cors_preflight("GET, OPTIONS") | ||
@API.route("", methods=["GET", "OPTIONS"]) | ||
class EnforcementActions(Resource): | ||
"""Resource for managing enforcement actions.""" | ||
|
||
@staticmethod | ||
@API.response(code=200, description="Success", model=[key_value_list_model]) | ||
@ApiHelper.swagger_decorators( | ||
API, endpoint_description="Fetch all enforcement actions" | ||
) | ||
@auth.require | ||
def get(): | ||
"""Fetch all enforcement actions.""" | ||
enforcement_actions = EnforcementActionService.get_enforcement_actions() | ||
list_schema = KeyValueSchema(many=True) | ||
return list_schema.dump(enforcement_actions), HTTPStatus.OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
compliance-api/src/compliance_api/services/compliance_finding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Compliance finding service.""" | ||
|
||
from compliance_api.models import ComplianceFindingOption as ComplianceFindingOptionModel | ||
|
||
|
||
class ComplianceFindingService: | ||
"""Compliance finding service.""" | ||
|
||
@classmethod | ||
def get_compliance_findings(cls): | ||
"""Get compliance finding options.""" | ||
return ComplianceFindingOptionModel.get_all(sort_by="sort_order") |
12 changes: 12 additions & 0 deletions
12
compliance-api/src/compliance_api/services/enforcement_action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Enforcement Action service.""" | ||
|
||
from compliance_api.models import EnforcementActionOption as EnforcementActionOptionModel | ||
|
||
|
||
class EnforcementActionService: | ||
"""Enforcement action service.""" | ||
|
||
@classmethod | ||
def get_enforcement_actions(cls): | ||
"""Get enforcement actions.""" | ||
return EnforcementActionOptionModel.get_all(sort_by="sort_order") |
14 changes: 14 additions & 0 deletions
14
compliance-api/tests/integration/api/test_compliance_finding.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""test suit for compliance findings.""" | ||
from http import HTTPStatus | ||
from urllib.parse import urljoin | ||
|
||
|
||
API_BASE_URL = "/api/" | ||
|
||
|
||
def test_get_compliance_findings(client, auth_header): | ||
"""Get compliance findings.""" | ||
url = urljoin(API_BASE_URL, "compliance-findings") | ||
result = client.get(url, headers=auth_header) | ||
assert len(result.json) == 3 | ||
assert result.status_code == HTTPStatus.OK |
14 changes: 14 additions & 0 deletions
14
compliance-api/tests/integration/api/test_enforcement_action.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""test suit for enforcement actions.""" | ||
from http import HTTPStatus | ||
from urllib.parse import urljoin | ||
|
||
|
||
API_BASE_URL = "/api/" | ||
|
||
|
||
def test_get_enforcement_actions(client, auth_header): | ||
"""Get enforcement actions.""" | ||
url = urljoin(API_BASE_URL, "enforcement-actions") | ||
result = client.get(url, headers=auth_header) | ||
assert len(result.json) == 9 | ||
assert result.status_code == HTTPStatus.OK |