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

23701 - Format with black and isort - PAY-API only #1771

Merged
merged 8 commits into from
Oct 8, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 15 additions & 3 deletions pay-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,27 @@ install: clean
#################################################################################
# COMMANDS - CI #
#################################################################################
ci: lint flake8 test ## CI flow
ci: isort-ci black-ci lint flake8 test ## CI flow

isort:
poetry run isort .

isort-ci:
poetry run isort --check .

black: ## Linting with black
poetry run black .

black-ci:
poetry run black --check .

pylint: ## Linting with pylint
poetry run pylint --rcfile=setup.cfg src/$(PROJECT_NAME)
poetry run pylint src/$(PROJECT_NAME)

flake8: ## Linting with flake8
poetry run flake8 src/$(PROJECT_NAME) tests

lint: pylint flake8 ## run all lint type scripts
lint: isort black pylint flake8 ## run all lint type scripts

test: ## Unit testing
poetry run pytest
Expand Down
16 changes: 8 additions & 8 deletions pay-api/gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import os

# https://docs.gunicorn.org/en/stable/settings.html#workers
workers = int(os.environ.get('GUNICORN_PROCESSES', '1')) # gunicorn default - 1
worker_class = os.environ.get('GUNICORN_WORKER_CLASS', 'sync') # gunicorn default - sync
worker_connections = int(os.environ.get('GUNICORN_WORKER_CONNECIONS', '1000')) # gunicorn default - 1000
threads = int(os.environ.get('GUNICORN_THREADS', '3')) # gunicorn default - 1
timeout = int(os.environ.get('GUNICORN_TIMEOUT', '100')) # gunicorn default - 30
keepalive = int(os.environ.get('GUNICORN_KEEPALIVE', '2')) # gunicorn default - 2
workers = int(os.environ.get("GUNICORN_PROCESSES", "1")) # gunicorn default - 1
worker_class = os.environ.get("GUNICORN_WORKER_CLASS", "sync") # gunicorn default - sync
worker_connections = int(os.environ.get("GUNICORN_WORKER_CONNECIONS", "1000")) # gunicorn default - 1000
threads = int(os.environ.get("GUNICORN_THREADS", "3")) # gunicorn default - 1
timeout = int(os.environ.get("GUNICORN_TIMEOUT", "100")) # gunicorn default - 30
keepalive = int(os.environ.get("GUNICORN_KEEPALIVE", "2")) # gunicorn default - 2
# WHEN MIGRATING TO GCP - GUNICORN_THREADS = 8, GUNICORN_TIMEOUT = 0, GUNICORN_PROCESSES = 1


forwarded_allow_ips = '*' # pylint: disable=invalid-name
secure_scheme_headers = {'X-Forwarded-Proto': 'https'} # pylint: disable=invalid-name
forwarded_allow_ips = "*" # pylint: disable=invalid-name
secure_scheme_headers = {"X-Forwarded-Proto": "https"} # pylint: disable=invalid-name
7 changes: 3 additions & 4 deletions pay-api/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
from pay_api import create_app
from pay_api.models import db


APP = create_app(run_mode='migration')
APP = create_app(run_mode="migration")
MIGRATE = Migrate(APP, db)

if __name__ == '__main__':
logging.log(logging.INFO, 'Running the Manager')
if __name__ == "__main__":
logging.log(logging.INFO, "Running the Manager")
33 changes: 22 additions & 11 deletions pay-api/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from logging.config import fileConfig

from alembic import context

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
Expand All @@ -20,29 +21,35 @@
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
logger = logging.getLogger("alembic.env")

config.set_main_option('sqlalchemy.url',
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
target_metadata = current_app.extensions['migrate'].db.metadata
config.set_main_option(
"sqlalchemy.url", current_app.config.get("SQLALCHEMY_DATABASE_URI")
)
target_metadata = current_app.extensions["migrate"].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def get_list_from_config(config, key):
arr = config.get_main_option(key, [])
if arr:
# split on newlines and commas, then trim (I mean strip)
arr = [token for a in arr.split('\n') for b in a.split(',') if (token := b.strip())]
arr = [
token for a in arr.split("\n") for b in a.split(",") if (token := b.strip())
]
return arr


exclude_tables = get_list_from_config(config, "exclude_tables")


def include_object(object, name, type_, reflected, compare_to):
return not (type_ == 'table' and name in exclude_tables)
return not (type_ == "table" and name in exclude_tables)


def run_migrations_offline():
"""Run migrations in 'offline' mode.
Expand All @@ -58,7 +65,11 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True, include_object=include_object
url=url,
target_metadata=target_metadata,
literal_binds=True,
compare_type=True,
include_object=include_object,
)

with context.begin_transaction():
Expand All @@ -77,15 +88,15 @@ def run_migrations_online():
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
if getattr(config.cmd_opts, "autogenerate", False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
logger.info("No changes in schema detected.")

connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

Expand All @@ -95,7 +106,7 @@ def process_revision_directives(context, revision, directives):
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
include_object=include_object,
**current_app.extensions['migrate'].configure_args
**current_app.extensions["migrate"].configure_args,
)

with context.begin_transaction():
Expand Down
104 changes: 66 additions & 38 deletions pay-api/migrations/versions/00467a306afd_bcorp_filing_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2019-12-16 09:08:29.440422

"""

from datetime import datetime, timezone

import sqlalchemy as sa
Expand All @@ -14,18 +15,28 @@


# revision identifiers, used by Alembic.
revision = '00467a306afd'
down_revision = '1a4e08683cb2'
revision = "00467a306afd"
down_revision = "1a4e08683cb2"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('fee_schedule', sa.Column('future_effective_fee_code', sa.String(length=10), nullable=True))
op.add_column('fee_schedule', sa.Column('priority_fee_code', sa.String(length=10), nullable=True))
op.create_foreign_key(None, 'fee_schedule', 'fee_code', ['priority_fee_code'], ['code'])
op.create_foreign_key(None, 'fee_schedule', 'fee_code', ['future_effective_fee_code'], ['code'])
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"fee_schedule",
sa.Column("future_effective_fee_code", sa.String(length=10), nullable=True),
)
op.add_column(
"fee_schedule",
sa.Column("priority_fee_code", sa.String(length=10), nullable=True),
)
op.create_foreign_key(
None, "fee_schedule", "fee_code", ["priority_fee_code"], ["code"]
)
op.create_foreign_key(
None, "fee_schedule", "fee_code", ["future_effective_fee_code"], ["code"]
)
# ### end Alembic commands ###

# Delete existing BCORP fee codes
Expand All @@ -34,11 +45,11 @@ def upgrade():
op.execute("update corp_type set description='BC Company' where code='BC'")

fee_code_table = table("fee_code", column("code", String), column("amount", Float))

filing_type_table = table(
"filing_type", column("code", String), column("description", String)
)

fee_schedule_table = table(
"fee_schedule",
column("filing_type_code", String),
Expand All @@ -47,41 +58,58 @@ def upgrade():
column("fee_start_date", Date),
column("fee_end_date", Date),
column("future_effective_fee_code", String),
column("priority_fee_code", String)
column("priority_fee_code", String),
)

# Fee Codes
op.bulk_insert(
fee_code_table, [
fee_code_table,
[
{"code": "EN109", "amount": 350},
{"code": "FUT01", "amount": 100},
{"code": "PRI01", "amount": 100}
]
{"code": "PRI01", "amount": 100},
],
)

# Filing Types
op.bulk_insert(
filing_type_table,
[
{'code': 'BCANN', 'description': 'Annual Report'},
{'code': 'BCADD', 'description': 'Change of Registered Office Address'},
{'code': 'BCCDR', 'description': 'Change of Director'},
{'code': 'BCINC', 'description': 'Incorporation'},
{'code': 'BCCGM', 'description': 'Notice of Change'},
{'code': 'BCFDR', 'description': 'Change of Director'},
{'code': 'BCAMR', 'description': 'Amalgamation Application (Regular)'},
{'code': 'BCAMH', 'description': 'Amalgamation Application Short Form (Horizontal)'},
{'code': 'BCAMV', 'description': 'Amalgamtion Application Short Form (Vertical)'},
{'code': 'BCRSF', 'description': 'Restoration Application - Full for a BC Benefit Company'},
{'code': 'BCRSL', 'description': 'Restoration Application - Limited for a BC Benefit Company'},
{'code': 'BCRSC', 'description': 'Restoration Application (Convert Limited to Full) for a BC Benefit Company'},
{'code': 'BCRSX', 'description': 'Restoration Application (Extend time Limit) for a BC Benefit Company'},
{'code': 'BCREG', 'description': 'Registration'}

]
{"code": "BCANN", "description": "Annual Report"},
{"code": "BCADD", "description": "Change of Registered Office Address"},
{"code": "BCCDR", "description": "Change of Director"},
{"code": "BCINC", "description": "Incorporation"},
{"code": "BCCGM", "description": "Notice of Change"},
{"code": "BCFDR", "description": "Change of Director"},
{"code": "BCAMR", "description": "Amalgamation Application (Regular)"},
{
"code": "BCAMH",
"description": "Amalgamation Application Short Form (Horizontal)",
},
{
"code": "BCAMV",
"description": "Amalgamtion Application Short Form (Vertical)",
},
{
"code": "BCRSF",
"description": "Restoration Application - Full for a BC Benefit Company",
},
{
"code": "BCRSL",
"description": "Restoration Application - Limited for a BC Benefit Company",
},
{
"code": "BCRSC",
"description": "Restoration Application (Convert Limited to Full) for a BC Benefit Company",
},
{
"code": "BCRSX",
"description": "Restoration Application (Extend time Limit) for a BC Benefit Company",
},
{"code": "BCREG", "description": "Registration"},
],
)


op.bulk_insert(
fee_schedule_table,
[
Expand Down Expand Up @@ -210,21 +238,21 @@ def upgrade():
"fee_end_date": None,
"future_effective_fee_code": None,
"priority_fee_code": "PRI01",
}
},
],
)


def downgrade():
#Delete fee related master data
op.execute('DELETE FROM fee_schedule where corp_type_code=\'BC\'')
op.execute("DELETE FROM filing_type where code in ('BCANN','BCADD','BCCDR', 'BCINC', 'BCCGM', 'BCFDR', 'BCAMR', 'BCAMH', 'BCAMV', 'BCRSF', 'BCRSL', 'BCRSC', 'BCRSX', 'BCREG')")
# Delete fee related master data
op.execute("DELETE FROM fee_schedule where corp_type_code='BC'")
op.execute(
"DELETE FROM filing_type where code in ('BCANN','BCADD','BCCDR', 'BCINC', 'BCCGM', 'BCFDR', 'BCAMR', 'BCAMH', 'BCAMV', 'BCRSF', 'BCRSL', 'BCRSC', 'BCRSX', 'BCREG')"
)
op.execute("DELETE FROM fee_code where code in ('EN109','FUT01','PRI01')")
# ###Delete End

# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('fee_schedule', 'priority_fee_code')
op.drop_column('fee_schedule', 'future_effective_fee_code')
op.drop_column("fee_schedule", "priority_fee_code")
op.drop_column("fee_schedule", "future_effective_fee_code")
# ### end Alembic commands ###


Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,34 @@
from sqlalchemy import text

# revision identifiers, used by Alembic.
revision = '03b2c7caed21'
down_revision = 'c871202927f0'
revision = "03b2c7caed21"
down_revision = "c871202927f0"
branch_labels = None
depends_on = None


def upgrade():
conn = op.get_bind()
res = conn.execute(text(f"select id, invoice_number from payments where receipt_number is null;"))
res = conn.execute(
text(f"select id, invoice_number from payments where receipt_number is null;")
)
results = res.fetchall()
for result in results:
pay_id = result[0]
invoice_number = result[1]
res = conn.execute(text(f"select r.receipt_number from receipts r left join invoice_references ir "
f"on ir.invoice_id=r.invoice_id where ir.status_code='COMPLETED' "
f"and invoice_number='{invoice_number}'"))
res = conn.execute(
text(
f"select r.receipt_number from receipts r left join invoice_references ir "
f"on ir.invoice_id=r.invoice_id where ir.status_code='COMPLETED' "
f"and invoice_number='{invoice_number}'"
)
)
receipt_number_result = res.fetchall()
if receipt_number_result:
receipt_number = receipt_number_result[0][0]
op.execute(f"update payments set receipt_number='{receipt_number}' where id = {pay_id}")
op.execute(
f"update payments set receipt_number='{receipt_number}' where id = {pay_id}"
)


def downgrade():
Expand Down
Loading
Loading