forked from bcgov/lear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
21025 configuration GET endpoint (bcgov#2679)
* 21025 cofiguration GET endpoint * fix typo * fix missing
- Loading branch information
Showing
4 changed files
with
108 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 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 Configuration resource.""" | ||
from http import HTTPStatus | ||
|
||
from flask import Blueprint, jsonify | ||
from flask_cors import cross_origin | ||
|
||
from legal_api.models import Configuration, UserRoles | ||
from legal_api.utils.auth import jwt | ||
|
||
|
||
bp = Blueprint('CONFIGURATION', __name__, url_prefix='/api/v2/admin/configurations') | ||
|
||
|
||
@bp.route('', methods=['GET']) | ||
@cross_origin(origin='*') | ||
@jwt.has_one_of_roles([UserRoles.staff]) | ||
def get_configurations(): | ||
"""Return a list of configurations.""" | ||
configurations = Configuration.all() | ||
return jsonify({ | ||
'configurations': [ | ||
configuration.json for configuration in configurations | ||
] | ||
}), 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
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. | ||
|
||
"""Tests to assure the configuration end-point. | ||
Test-Suite to ensure that admin/configuration endpoints are working as expected. | ||
""" | ||
from http import HTTPStatus | ||
|
||
from legal_api.services.authz import BASIC_USER, STAFF_ROLE | ||
from tests.unit.services.utils import create_header | ||
|
||
|
||
def test_get_configurations(app, session, client, jwt): | ||
"""Assert that get results are returned.""" | ||
|
||
# test | ||
rv = client.get(f'/api/v2/admin/configurations', | ||
headers=create_header(jwt, [STAFF_ROLE], 'user')) | ||
|
||
# check | ||
assert rv.status_code == HTTPStatus.OK | ||
assert 'configurations' in rv.json | ||
results = rv.json['configurations'] | ||
assert len(results) == 4 | ||
|
||
names = {'NUM_DISSOLUTIONS_ALLOWED', 'MAX_DISSOLUTIONS_ALLOWED', 'DISSOLUTIONS_ON_HOLD', 'NEW_DISSOLUTIONS_SCHEDULE'} | ||
for res in results: | ||
assert res['name'] in names | ||
|
||
|
||
def test_get_configurations_with_invalid_user(app, session, client, jwt): | ||
"""Assert that is unauthorized.""" | ||
|
||
# test | ||
rv = client.get(f'/api/v2/admin/configurations', | ||
headers=create_header(jwt, [BASIC_USER], 'user')) | ||
|
||
# check | ||
assert rv.status_code == HTTPStatus.UNAUTHORIZED |