Skip to content

Commit

Permalink
ruff, bandit, PaymentStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Sep 19, 2024
1 parent d4792c7 commit 96e5004
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
15 changes: 14 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ repos:
args: ['--maxkb=1024']
- id: check-case-conflict
- id: mixed-line-ending
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
Expand All @@ -23,7 +30,7 @@ repos:
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py311-plus]
args: [--py310-plus]
- repo: https://github.com/hhatto/autopep8
rev: v2.3.1
hooks:
Expand All @@ -38,3 +45,9 @@ repos:
- flake8-polyfill
- toml
exclude: docs\/.*
- repo: https://github.com/PyCQA/bandit
rev: '1.7.9'
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""(re-7)Init
"""(re-8)Init
Revision ID: 96ae93cc9125
Revision ID: 6d833540bc9e
Revises:
Create Date: 2024-09-19 04:51:55.007209
Create Date: 2024-09-19 05:49:16.051421
"""

Expand All @@ -11,7 +11,7 @@
from alembic import op

# revision identifiers, used by Alembic.
revision = "96ae93cc9125"
revision = "6d833540bc9e"
down_revision = None
branch_labels = None
depends_on = None
Expand Down Expand Up @@ -55,7 +55,11 @@ def upgrade():
sa.Column("customer_email", sa.String(length=255), nullable=False),
sa.Column("integration_slug", sa.String(length=255), nullable=False),
sa.Column("integration_id", sa.Integer(), nullable=True),
sa.Column("status", sa.String(length=10), nullable=False),
sa.Column(
"status",
sa.Enum("created", "processing", "declined", "cancelled", "refunded", "paid", name="paymentstatus"),
nullable=False,
),
sa.Column("integration_payload", sa.JSON(), nullable=True),
sa.Column("integration_response", sa.JSON(), nullable=True),
sa.Column(
Expand Down
8 changes: 7 additions & 1 deletion merchants/FastapiAdmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ class IntegrationAdmin(ModelView):


class PaymentAdmin(ModelView):
exclude_fields_from_list = ["id", "integration_slug", "integration_payload", "integration_response", "modified_at"]
exclude_fields_from_list = [
"id",
"integration_slug",
"integration_payload",
"integration_response",
"modified_at",
]
exclude_fields_from_create = ["id"]
exclude_fields_from_edit = ["id"]

Expand Down
14 changes: 12 additions & 2 deletions merchants/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
import enum
from decimal import Decimal
from typing import Any

from pydantic import BaseModel, EmailStr
from sqlalchemy import JSON, DateTime, ForeignKey, Integer, Numeric, String, event
from sqlalchemy import JSON, DateTime, Enum, ForeignKey, Integer, Numeric, String, event
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql import func
from sqlalchemy_utils import generic_repr
Expand Down Expand Up @@ -45,6 +46,15 @@ class Integration(DatabaseModel):
)


class PaymentStatus(enum.Enum):
created = "created"
processing = "processing"
declined = "declined"
cancelled = "cancelled"
refunded = "refunded"
paid = "paid"


@generic_repr
class Payment(DatabaseModel):
__tablename__ = "payment"
Expand All @@ -56,7 +66,7 @@ class Payment(DatabaseModel):
customer_email: Mapped[EmailStr] = mapped_column(String(255), nullable=False)
integration_slug: Mapped[str] = mapped_column(String(255), nullable=False)
integration_id: Mapped[str] = mapped_column(String(255))
status: Mapped[str] = mapped_column(String(10))
status: Mapped[PaymentStatus] = mapped_column(Enum(PaymentStatus), default=PaymentStatus.created)
integration_payload: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
integration_response: Mapped[dict[str, Any] | None] = mapped_column(JSON, nullable=True)
integration_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("integration.id"))
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ sqlalchemy-utils = "^0.41.2"
pre-commit = "^3.8.0"



[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
coverage = "^7.6.1"
Expand All @@ -63,6 +62,13 @@ line-length = 119
target-version = ['py310']
include = '\.pyi?$'

[tool.ruff]
line-length = 119
target-version = "py310"

[tool.bandit]
exclude_dirs = ["tests"]
skips = ["B101", "B601"]

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 96e5004

Please sign in to comment.