Skip to content

Commit

Permalink
Merge pull request #153 from bcgov/development
Browse files Browse the repository at this point in the history
Merge from development to master
  • Loading branch information
sumesh-aot authored Feb 21, 2020
2 parents 7ff6526 + 039ce89 commit 8d127fc
Show file tree
Hide file tree
Showing 52 changed files with 698 additions and 241 deletions.
38 changes: 18 additions & 20 deletions bcol-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,46 @@ Flask-Moment==0.9.0
Flask-SQLAlchemy==2.4.1
Flask-Script==2.0.6
Flask==1.1.1
Jinja2==2.10.3
Jinja2==2.11.1
MarkupSafe==1.1.1
SQLAlchemy==1.3.11
Werkzeug==0.16.0
SQLAlchemy==1.3.13
Werkzeug==0.16.1
aniso8601==8.0.0
appdirs==1.4.3
attrs==19.1.0
blinker==1.4
cached-property==1.5.1
certifi==2019.9.11
certifi==2019.11.28
chardet==3.0.4
defusedxml==0.6.0
ecdsa==0.14.1
ecdsa==0.15
flask-jwt-oidc==0.1.5
flask-marshmallow==0.10.1
flask-marshmallow==0.11.0
flask-restplus==0.13.0
future==0.18.2
gunicorn==20.0.3
gunicorn==20.0.4
idna==2.8
importlib-metadata==0.23
importlib-metadata==1.5.0
isodate==0.6.0
itsdangerous==1.1.0
jsonschema==3.2.0
lxml==4.4.1
marshmallow-sqlalchemy==0.19.0
lxml==4.5.0
marshmallow-sqlalchemy==0.22.2
marshmallow==3.0.0rc7
more-itertools==7.2.0
psycopg2-binary==2.8.4
pyasn1-modules==0.2.7
pyasn1-modules==0.2.8
pyasn1==0.4.8
pyrsistent==0.15.6
python-dotenv==0.10.3
python-jose==3.0.1
pyrsistent==0.15.7
python-dotenv==0.11.0
python-jose==3.1.0
python-ldap==3.2.0
pytz==2019.3
requests-toolbelt==0.9.1
requests==2.22.0
rsa==4.0
sentry-sdk==0.13.3
six==1.13.0
urllib3==1.25.7
sentry-sdk==0.14.1
six==1.14.0
urllib3==1.25.8
zeep==3.4.0
zipp==0.6.0
zipp==2.2.0
-e git://github.com/pwei1018/jaeger-client-python.git@186f14e14758273ed108508c0d388a4f4de5c75b#egg=jaeger-client
-e git+https://github.com/bcgov/sbc-common-components.git#egg=sbc-common-components-1.0.0&subdirectory=python
3 changes: 2 additions & 1 deletion bcol-api/requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ requests
zeep
python-ldap
sentry-sdk[flask]
attrs<=19.1.0
attrs<=19.1.0
Werkzeug==0.16.1
5 changes: 2 additions & 3 deletions bcol-api/src/bcol_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import os

import sentry_sdk # noqa: I001; pylint: disable=ungrouped-imports; conflicts with Flake8
from flask import Flask
from sbc_common_components.exception_handling.exception_handler import ExceptionHandler
from sbc_common_components.utils.camel_case_response import convert_to_camel
from sentry_sdk.integrations.flask import FlaskIntegration # noqa: I001
import sentry_sdk # noqa: I001; pylint: disable=ungrouped-imports; conflicts with Flake8

import config
from bcol_api.resources import API_BLUEPRINT, OPS_BLUEPRINT
Expand All @@ -31,6 +31,7 @@
from bcol_api.utils.run_version import get_run_version
from config import _Config


setup_logging(os.path.join(_Config.PROJECT_ROOT, 'logging.conf')) # important to do this first


Expand Down Expand Up @@ -67,7 +68,6 @@ def add_version(response): # pylint: disable=unused-variable

def setup_jwt_manager(app, jwt_manager):
"""Use flask app to configure the JWTManager to work for a particular Realm."""

def get_roles(a_dict):
return a_dict['realm_access']['roles'] # pragma: no cover

Expand All @@ -78,7 +78,6 @@ def get_roles(a_dict):

def register_shellcontext(app):
"""Register shell context objects."""

def shell_context():
"""Shell context objects."""
return {'app': app, 'jwt': jwt} # pragma: no cover
Expand Down
1 change: 1 addition & 0 deletions bcol-api/src/bcol_api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .meta import API as META_API
from .ops import API as OPS_API


__all__ = ('API_BLUEPRINT', 'OPS_BLUEPRINT')

# This will add the Authorize button to the swagger docs
Expand Down
7 changes: 5 additions & 2 deletions bcol-api/src/bcol_api/resources/bcol_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from http import HTTPStatus

from flask import request
from flask import current_app, request
from flask_restplus import Namespace, Resource

from bcol_api.exceptions import BusinessException
Expand All @@ -25,6 +25,7 @@
from bcol_api.utils.trace import tracing as _tracing
from bcol_api.utils.util import cors_preflight


API = Namespace('bcol accounts', description='Payment System - BCOL Accounts')


Expand All @@ -40,10 +41,12 @@ def post():
"""Create a payment record in BCOL."""
try:
req_json = request.get_json()
current_app.logger.debug(req_json)
# Validate the input request
valid_format = schema_utils.validate(req_json, 'payment_request')
print(valid_format)
if not valid_format[0]:
current_app.logger.info('Validation Error with incoming request',
schema_utils.serialize(valid_format[1]))
response, status = {'code': 'BCOL999', 'message': 'Invalid Request'}, HTTPStatus.BAD_REQUEST
else:
response, status = BcolPayment().create_payment(req_json), HTTPStatus.OK
Expand Down
1 change: 1 addition & 0 deletions bcol-api/src/bcol_api/resources/bcol_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from bcol_api.utils.trace import tracing as _tracing
from bcol_api.utils.util import cors_preflight


API = Namespace('bcol profile', description='Payment System - BCOL Profiles')


Expand Down
1 change: 1 addition & 0 deletions bcol-api/src/bcol_api/schemas/schemas/payment_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"title": "Payment Request",
"required": [
"userId",
"feeCode",
"invoiceNumber",
"folioNumber"
],
Expand Down
8 changes: 8 additions & 0 deletions bcol-api/src/bcol_api/schemas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,11 @@ def validate(json_data: json,
except SchemaError as error:
# handle schema error
return False, error


def serialize(errors):
"""Serialize errors."""
error_message = []
for error in errors:
error_message.append(error.message)
return error_message
12 changes: 10 additions & 2 deletions bcol-api/src/bcol_api/services/bcol_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def create_payment(self, pay_request: Dict):
"""Create payment record in BCOL."""
current_app.logger.debug('<create_payment')
pay_response = None
padded_amount = self._pad_zeros(pay_request.get('amount', '0'))
# Call the query profile service to fetch profile
data = {
'Version': current_app.config.get('BCOL_DEBIT_ACCOUNT_VERSION'),
Expand All @@ -41,8 +42,8 @@ def create_payment(self, pay_request: Dict):
'Folio': pay_request.get('folioNumber'),
'FormNumber': pay_request.get('formNumber', ''),
'Quantity': pay_request.get('quantity', ''),
'Rate': pay_request.get('rate', ''),
'Amount': pay_request.get('amount', ''),
'Rate': padded_amount,
'Amount': padded_amount,
'Remarks': pay_request.get('remarks', 'BCOL Payment from BCROS'),
'RedundantFlag': pay_request.get('reduntantFlag', ' '),
'linkcode': current_app.config.get('BCOL_LINK_CODE')
Expand Down Expand Up @@ -86,3 +87,10 @@ def debit_account(self, data: Dict): # pragma: no cover # pylint: disable=no-se
"""Debit BCOL account."""
client = BcolSoap().get_payment_client()
return zeep.helpers.serialize_object(client.service.debitAccount(req=data))

def _pad_zeros(self, amount: str = '0'): # pylint: disable=no-self-use
"""Pad the amount with Zeroes to make sure the string is 10 chars."""
if not amount:
return None
amount = int(float(amount) * 100) # Multiply with 100, as for e.g, 50.00 needs to be 5000
return str(amount).zfill(10)
42 changes: 21 additions & 21 deletions bcol-api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from unittest.mock import patch

import pytest
from tests.utilities.ldap_mock import MockLDAP

from bcol_api import create_app
from bcol_api import jwt as _jwt
from tests.utilities.ldap_mock import MockLDAP


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -137,7 +137,6 @@ def query_profile_mock_error():
mock_query_profile_patcher.stop()



@pytest.fixture()
def payment_mock():
"""Mock Query Profile SOAP."""
Expand All @@ -146,29 +145,30 @@ def payment_mock():
)
mock_payment = mock_payment_patcher.start()
mock_payment.return_value = {
'RespType': 'RESPONSE',
'ReturnCode': '0000',
'ReturnMsg': 'LOOKS OK TO ME',
'Uniqueid': '',
'StatFee': '-700',
'Totamt': '-850',
'TSFee': '-150',
'Totgst': '+00',
'Totpst': '+00',
'TranID': {
'Account': '180670',
'UserID': 'PB25020 ',
'AppliedDate': '20191108',
'AppliedTime': '113405428',
'FeeCode': 'BSH105 ',
'Key': 'TEST12345678901',
'SequenceNo': '0001'
}
}
'RespType': 'RESPONSE',
'ReturnCode': '0000',
'ReturnMsg': 'LOOKS OK TO ME',
'Uniqueid': '',
'StatFee': '-700',
'Totamt': '-850',
'TSFee': '-150',
'Totgst': '+00',
'Totpst': '+00',
'TranID': {
'Account': '180670',
'UserID': 'PB25020 ',
'AppliedDate': '20191108',
'AppliedTime': '113405428',
'FeeCode': 'BSH105 ',
'Key': 'TEST12345678901',
'SequenceNo': '0001'
}
}

yield
mock_payment_patcher.stop()


@pytest.fixture()
def payment_mock_error():
"""Mock Payment SOAP."""
Expand Down
3 changes: 1 addition & 2 deletions bcol-api/tests/unit/conf/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
Test-Suite to ensure that the version utilities are working as expected.
"""
from tests import skip_in_pod

from bcol_api import utils
from bcol_api.version import __version__
from tests import skip_in_pod


@skip_in_pod
Expand Down
2 changes: 1 addition & 1 deletion pay-api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods

SERVICE_SCHEDULE = json.dumps(schedule_json)

AUTH_API_ENDPOINT = "https://mock-lear-tools.pathfinder.gov.bc.ca/rest/Auth+API/1.0.0/"
AUTH_API_ENDPOINT = "https://mock-lear-tools.pathfinder.gov.bc.ca/rest/SBC+Auth+API+Reference/1.0.0/"

NATS_SUBJECT = 'entity.filing.test'

Expand Down
54 changes: 54 additions & 0 deletions pay-api/migrations/versions/41bf37772240_bcol_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""bcol_changes
Revision ID: 41bf37772240
Revises: 78951cf14ae9
Create Date: 2020-01-29 16:15:07.585449
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '41bf37772240'
down_revision = '78951cf14ae9'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('payment_account', sa.Column('auth_account_id', sa.String(length=50), nullable=True))
op.add_column('payment_account', sa.Column('bcol_account_id', sa.String(length=50), nullable=True))
op.add_column('payment_account', sa.Column('bcol_user_id', sa.String(length=50), nullable=True))
op.alter_column('payment_account', 'corp_number',
existing_type=sa.VARCHAR(length=20),
nullable=True)
op.alter_column('payment_account', 'corp_type_code',
existing_type=sa.VARCHAR(length=10),
nullable=True)
op.create_index(op.f('ix_payment_account_auth_account_id'), 'payment_account', ['auth_account_id'], unique=False)
op.create_index(op.f('ix_payment_account_bcol_account_id'), 'payment_account', ['bcol_account_id'], unique=False)
op.create_index(op.f('ix_payment_account_bcol_user_id'), 'payment_account', ['bcol_user_id'], unique=False)
op.drop_index('ix_payment_account_user_id', table_name='payment_account')
op.drop_column('payment_account', 'user_id')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('payment_account', sa.Column('user_id', sa.VARCHAR(length=50), autoincrement=False, nullable=True))
op.create_index('ix_payment_account_user_id', 'payment_account', ['user_id'], unique=False)
op.drop_index(op.f('ix_payment_account_bcol_user_id'), table_name='payment_account')
op.drop_index(op.f('ix_payment_account_bcol_account_id'), table_name='payment_account')
op.drop_index(op.f('ix_payment_account_auth_account_id'), table_name='payment_account')
op.alter_column('payment_account', 'corp_type_code',
existing_type=sa.VARCHAR(length=10),
nullable=False)
op.alter_column('payment_account', 'corp_number',
existing_type=sa.VARCHAR(length=20),
nullable=False)
op.drop_column('payment_account', 'bcol_user_id')
op.drop_column('payment_account', 'bcol_account_id')
op.drop_column('payment_account', 'auth_account_id')
# ### end Alembic commands ###
Loading

0 comments on commit 8d127fc

Please sign in to comment.