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
eb270ab
commit bdbf0f1
Showing
5 changed files
with
80 additions
and
0 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
51 changes: 51 additions & 0 deletions
51
compliance-api/src/compliance_api/resources/document_type.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,51 @@ | ||
# 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 document type 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 DocumentTypeService | ||
from compliance_api.utils.util import cors_preflight | ||
|
||
from .apihelper import Api as ApiHelper | ||
|
||
|
||
API = Namespace( | ||
"document-types", | ||
description="Endpoints for Document Type 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 DocumentTypes(Resource): | ||
"""Resource for managing document types.""" | ||
|
||
@staticmethod | ||
@API.response(code=200, description="Success", model=[key_value_list_model]) | ||
@ApiHelper.swagger_decorators(API, endpoint_description="Fetch all document types") | ||
@auth.require | ||
def get(): | ||
"""Fetch all document types.""" | ||
document_types = DocumentTypeService.get_all() | ||
list_schema = KeyValueSchema(many=True) | ||
return list_schema.dump(document_types), 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
12 changes: 12 additions & 0 deletions
12
compliance-api/src/compliance_api/services/document_type.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 @@ | ||
"""Document Type service.""" | ||
|
||
from compliance_api.models import DocumentType as DocumentTypeModel | ||
|
||
|
||
class DocumentTypeService: | ||
"""DocumentTypeService.""" | ||
|
||
@classmethod | ||
def get_all(cls): | ||
"""Get enforcement actions.""" | ||
return DocumentTypeModel.get_all(sort_by="sort_order") |
14 changes: 14 additions & 0 deletions
14
compliance-api/tests/integration/api/test_document_type.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 document type.""" | ||
from http import HTTPStatus | ||
from urllib.parse import urljoin | ||
|
||
|
||
API_BASE_URL = "/api/" | ||
|
||
|
||
def test_get_document_type(client, auth_header): | ||
"""Get document type.""" | ||
url = urljoin(API_BASE_URL, "document-types") | ||
result = client.get(url, headers=auth_header) | ||
assert len(result.json) == 2 | ||
assert result.status_code == HTTPStatus.OK |