Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Whatsnew endpoint. #1864

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 107 additions & 11 deletions status-api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class _Config(object): # pylint: disable=too-few-public-methods
SERVICE_SCHEDULE = os.getenv('SERVICE_SCHEDULE')
PAYBC_OUTAGE_MESSAGE = os.getenv('PAYBC_OUTAGE_MESSAGE')

WHATSNEW = os.getenv('WHATSNEW')

TESTING = False
DEBUG = True

Expand All @@ -75,19 +77,53 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods
{
"service_name": "PAYBC",
"available": [
{"dayofweek": "1", "from": "6:00", "to": "21:00"},
{"dayofweek": "2", "from": "6:00", "to": "21:00"},
{"dayofweek": "3", "from": "6:00", "to": "21:00"},
{"dayofweek": "4", "from": "15:05", "to": "21:00"},
{"dayofweek": "5", "from": "6:00", "to": "21:00"},
{"dayofweek": "6", "from": "6:30", "to": "21:00"},
{"dayofweek": "7", "from": "6:30", "to": "21:00"}
{
"dayofweek": "1",
"from": "6:00",
"to": "21:00"
},
{
"dayofweek": "2",
"from": "6:00",
"to": "21:00"
},
{
"dayofweek": "3",
"from": "6:00",
"to": "21:00"
},
{
"dayofweek": "4",
"from": "6:00",
"to": "21:00"
},
{
"dayofweek": "5",
"from": "6:00",
"to": "21:00"
},
{
"dayofweek": "6",
"from": "6:30",
"to": "21:00"
},
{
"dayofweek": "7",
"from": "6:30",
"to": "21:00"
}
],
"outage": [
{"start": "2019-10-23 16:00", "end": "2019-10-23 18:00"},
{"start": "2019-10-23 16:00", "end": "2019-10-23 17:00"},
{"start": "2019-10-23 13:00", "end": "2019-10-25 15:05"}
]
{
"start": "2019-11-05 10:00",
"end": "2019-11-05 10:10"
}
],
"custom": {
"start": "2021-06-10 09:57",
"end": "2021-06-12 06:00",
"message": "TEST - Credit card payments will be unavailable for cooperative and benefit company filings from 9:00 PM September 4th until 6:00 AM September 8th. We apologize for the inconvenience."
}
}
]

Expand All @@ -97,6 +133,66 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods
DEBUG = True
TESTING = True

WHATSNEW = [{"id": 1,
"date": "2022-01-01",
"labels": "New Feature",
"title": "Modernization Update",
"description": "<p><p>Hey there, </p> \
<p>We introduce a new sign-in flow to let you log in</p> \
<p>with BC services card. This will help you keep track</p> \
<p>of this and that more effectively.</p> \
<ul>\
<li>Business Dashboard</li>\
<li>Name Request</li>\
<li>PPR</li> \
</ul> \
<p><b>Please check it out! </b></p>",
"app": "ALL",
"priority": True,
"read": False
},
{"id": 2,
"date": "2022-01-03",
"labels": "Improvement",
"title": "Modernization Update",
"description": "<p><p>Hey there, </p> \
<p>We intro Starting and managing Benefit</p> \
<p>Companies, Cooperative Associations and Name</p>\
<p>Requests. BC OnLine will continue to be used</p>\
<p>for all other applications.</p>",
"app": "ALL",
"priority": False,
"read": False
},
{"id": 3,
"date": "2022-01-19",
"labels": "Announcement",
"title": "Coming soon",
"description": "<ul>\
<li>Wills Search and Registration - 2021 </li>\
<li>Personal Property Registry - 2022</li>\
<li>OneStop Sole Proprietorship, General Partnership Registrations and maintenance filings - 2022</li> \
<li>Stages so users can track progress</li> \
</ul>",
"app": "ALL",
"priority": False,
"read": False
},
{"id": 4,
"date": "2022-02-19",
"labels": "Announcement",
"title": "Coming soon",
"description": "<ul>\
<li>Wills Search and Registration - 2021 </li>\
<li>Personal Property Registry - 2022</li>\
<li>OneStop Sole Proprietorship, General Partnership Registrations and maintenance filings - 2022</li> \
<li>Stages so users can track progress</li> \
</ul>",
"app": "ALL",
"priority": True,
"read": False
}]


class ProdConfig(_Config): # pylint: disable=too-few-public-methods
"""Production environment configuration."""
Expand Down
16 changes: 9 additions & 7 deletions status-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@ Jinja2==2.11.3
MarkupSafe==2.0.1
Werkzeug==1.0.1
aniso8601==9.0.1
arrow==1.2.0
arrow==1.2.1
attrs==21.2.0
blinker==1.4
cachelib==0.4.1
certifi==2021.10.8
charset-normalizer==2.0.7
charset-normalizer==2.0.9
click==7.1.2
ecdsa==0.17.0
flask-jwt-oidc==0.3.0
flask-restx==0.5.1
gunicorn==20.1.0
idna==3.3
importlib-resources==5.4.0
itsdangerous==1.1.0
jsonschema==4.1.0
psycopg2-binary==2.9.1
jsonschema==4.3.0
psycopg2-binary==2.9.2
pyasn1==0.4.8
pyrsistent==0.18.0
python-dateutil==2.8.2
python-dotenv==0.19.1
python-dotenv==0.19.2
python-jose==3.3.0
pytz==2021.3
requests==2.26.0
rsa==4.7.2
sentry-sdk==1.4.3
rsa==4.8
sentry-sdk==1.5.1
six==1.16.0
urllib3==1.26.7
zipp==3.6.0
-e git+https://github.com/bcgov/sbc-common-components.git#egg=sbc-common-components&subdirectory=python
2 changes: 2 additions & 0 deletions status-api/src/status_api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .meta import API as META_API
from .ops import API as OPS_API
from .status import API as STATUS_API
from .whatsnew import API as WHATSNEW_API


__all__ = ('API_BLUEPRINT', 'OPS_BLUEPRINT')
Expand Down Expand Up @@ -64,3 +65,4 @@

API.add_namespace(META_API, path='/meta')
API.add_namespace(STATUS_API, path='/status/<string:service_name>')
API.add_namespace(WHATSNEW_API, path='/whatsnew')
39 changes: 39 additions & 0 deletions status-api/src/status_api/resources/whatsnew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright © 2019 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.
"""Resource for Service status endpoints."""
import json
from http import HTTPStatus

from flask import current_app
from flask_restx import Namespace, Resource, cors

from status_api.utils.util import cors_preflight


API = Namespace('whatsnew', description='Whats New')


@cors_preflight('GET')
@API.route('', methods=['GET', 'OPTIONS'])
class WhatsNew(Resource):
"""Endpoint resource to calculate fee."""

@staticmethod
@cors.crossdomain(origin='*')
@API.response(200, 'OK')
def get():
"""Get the service schedule and return status and next schedule date/time."""
print(current_app.config.get('WHATSNEW'))
response, status = current_app.config.get('WHATSNEW'), HTTPStatus.OK
return json.dumps(response), status
6 changes: 3 additions & 3 deletions status-api/src/status_api/services/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def get_schedules(service_name: str):
@staticmethod
def get_available_schedules(service_schedule: list, check_date_local: arrow.Arrow):
"""Get available schedules from schedules."""
week_dates: list = list()
date_availables: list = list()
week_dates: list = []
date_availables: list = []

check_date_only: arrow.Arrow = check_date_local.replace(hour=0, minute=0, second=0, microsecond=0)
for day_week in range(-1, 7):
Expand All @@ -115,7 +115,7 @@ def get_available_schedules(service_schedule: list, check_date_local: arrow.Arro
@staticmethod
def get_outage_schedules(service_schedule: list):
"""Get outage schedules from schedules."""
date_outages: list = list()
date_outages: list = []

if 'outage' in service_schedule[0]:
for outage_time in service_schedule[0]['outage']:
Expand Down
4 changes: 2 additions & 2 deletions status-api/src/status_api/utils/util_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def setup_logging(conf):
"""
if conf and path.isfile(conf):
logging.config.fileConfig(conf)
print('Configure logging, from conf:{}'.format(conf), file=sys.stdout)
print(f'Configure logging, from conf:{conf}', file=sys.stdout)
else:
print('Unable to configure logging, attempted conf:{}'.format(conf), file=sys.stderr)
print(f'Unable to configure logging, attempted conf:{conf}', file=sys.stderr)
21 changes: 21 additions & 0 deletions status-api/tests/unit/api/test_whatsnew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright © 2019 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 whatsnew end-point."""


def test_whatsnew(client):
"""Assert that the endpoint returns 200 with actual result."""
rv = client.get('/api/v1/whatsnew')
assert rv.status_code == 200