Skip to content

Commit

Permalink
Mixin Work
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Jun 29, 2024
1 parent bc98fe4 commit 79c73bb
Show file tree
Hide file tree
Showing 20 changed files with 387 additions and 165 deletions.
56 changes: 28 additions & 28 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# # To get started with Dependabot version updates, you'll need to specify which
# # package ecosystems to update and where the package manifests are located.
# # Please see the documentation for all configuration options:
# # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
allow:
- dependency-type: "all"
assignees:
- "mariofix"
commit-message:
prefix: "poetry prod"
prefix-development: "poetry dev"
include: "scope"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
allow:
- dependency-type: "all"
commit-message:
prefix: "actions prod"
prefix-development: "actions dev"
include: "scope"
# version: 2
# updates:
# - package-ecosystem: "pip"
# directory: "/"
# schedule:
# interval: "weekly"
# allow:
# - dependency-type: "all"
# assignees:
# - "mariofix"
# commit-message:
# prefix: "poetry prod"
# prefix-development: "poetry dev"
# include: "scope"
# - package-ecosystem: "github-actions"
# directory: "/"
# schedule:
# interval: "weekly"
# allow:
# - dependency-type: "all"
# commit-message:
# prefix: "actions prod"
# prefix-development: "actions dev"
# include: "scope"
78 changes: 39 additions & 39 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
name: Tests&Coverage
# name: Tests&Coverage

on:
push:
branches: ["sandbox"]
pull_request:
branches: ["main"]
# on:
# push:
# branches: ["sandbox"]
# pull_request:
# branches: ["main"]

jobs:
tests:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
poetry-version: ["1.8.3"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set Up Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install merchants
run: poetry install --with dev
- name: Run Tests and coverage
run: poetry run coverage run -m pytest
- name: Coverage report (xml)
run: poetry run coverage xml
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: "coverage.xml"
language: "python"
# jobs:
# tests:
# strategy:
# fail-fast: false
# matrix:
# python-version: ["3.9", "3.10", "3.11", "3.12"]
# poetry-version: ["1.8.3"]
# os: [ubuntu-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v4
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# - name: Set Up Poetry
# uses: abatilo/actions-poetry@v2
# with:
# poetry-version: ${{ matrix.poetry-version }}
# - name: Install merchants
# run: poetry install --with dev
# - name: Run Tests and coverage
# run: poetry run coverage run -m pytest
# - name: Coverage report (xml)
# run: poetry run coverage xml
# - name: Coveralls GitHub Action
# uses: coverallsapp/github-action@v2
# - name: Run codacy-coverage-reporter
# uses: codacy/codacy-coverage-reporter-action@v1
# with:
# project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
# coverage-reports: "coverage.xml"
# language: "python"
Empty file added examples/fastapi_sqla/README.md
Empty file.
41 changes: 41 additions & 0 deletions examples/fastapi_sqla/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from decimal import Decimal

from fastapi import FastAPI
from icecream import ic
from sqlalchemy import create_engine
from sqlalchemy.orm import Mapped, declarative_base, mapped_column, sessionmaker
from starlette_admin.contrib.sqla import Admin, ModelView

from merchants.orm.sqla import PaymentMixin

SQLALCHEMY_DATABASE_URL = "sqlite:///./examples/fastapi_sqla/merchants.sqlite3"

engine = create_engine(SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()


class Payment(PaymentMixin, Base):
__tablename__ = "payments"

id: Mapped[int] = mapped_column(primary_key=True)

def make_payment(self):
ic(self)


Base.metadata.create_all(engine)

session = SessionLocal()

payment = Payment(account="timestamp_test", amount=Decimal("100.00"), currency="USD", status="CREATED")

session.add(payment)
session.commit()


app = FastAPI()
admin = Admin(engine, title="merchants: SQLAlchemy")
admin.add_view(ModelView(Payment))
admin.mount_to(app)
17 changes: 17 additions & 0 deletions examples/fastapi_sqla/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "fastapi-sqla"
version = "0.1.0"
description = "Example for FastAPI using SQLAlchemy"
authors = ["Mario Hernandez <mariofix@proton.me>"]
license = "MIT"
readme = "README.md"


[tool.poetry.dependencies]
python = "^3.10"
fastapi = "^0.111.0"
sqlalchemy = "^2.0.31"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion merchants/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .config import base_settings as settings
from .config import default_settings as settings

__all__ = ["settings"]
23 changes: 0 additions & 23 deletions merchants/cli.py

This file was deleted.

6 changes: 3 additions & 3 deletions merchants/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def _available_integrations() -> list:
class MerchantsSettings:
available_integrations: list = field(default_factory=_available_integrations)
enabled_accounts: list = field(default_factory=list)
process_on_save: bool = True
process_on_save: bool = True # Ejecuta el pago al momento de guardar el objeto.

load_from_database: bool = True
load_from_database: bool = True # Obtiene settings desde archivo o db

def __post__init__(self):
pass
Expand All @@ -49,4 +49,4 @@ def load_variants(self, config: dict) -> list:
return self.enabled_accounts


base_settings = MerchantsSettings()
default_settings = MerchantsSettings()
4 changes: 4 additions & 0 deletions merchants/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import httpx

# Cliente httpx para definir parametros especificos
client = httpx.Client(headers={"user-agent": "merchants/2024.6"})
10 changes: 10 additions & 0 deletions merchants/core/fastapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from fastapi import APIRouter

merchants = APIRouter()


# Acá irán las URL para los callbacks
# Dejar así hasta llegar a esa etapa
@merchants.get("/")
async def default_root():
return {"Hello": "World"}
24 changes: 14 additions & 10 deletions merchants/core/schemas.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from dataclasses import dataclass
from enum import Enum


@dataclass
class ModelStatus:
CREATED: str = "Created"
PROCESSING: str = "Processing"
ERROR: str = "Error"
REJECTED: str = "Rejected"
COMPLETED: str = "Completed"
REFUNDED: str = "Refunded"
REVERSED: str = "Reversed"
class ModelStatus(Enum):
"""
Enumeration of possible payment statuses.
"""

CREATED = "CREATED"
PROCESSING = "PROCESSING"
ERROR = "ERROR"
REJECTED = "REJEDTED"
COMPLETED = "COMPLETED"
FULL_REFUND = "FULL_REFUND"
PARTIAL_REFUND = "PARTIAL_REFUND"
REVERSED = "REVERSED"
6 changes: 3 additions & 3 deletions merchants/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from ..config import base_settings
from ..config import default_settings


def local_factory(slug: str):
if slug not in base_settings.available_providers:
if slug not in default_settings.available_providers:
raise NotImplementedError(f"The provider {slug} is not supported.")

return slug


def create_provider(slug: str):
if slug not in base_settings.available_providers:
if slug not in default_settings.available_providers:
raise NotImplementedError(f"The provider {slug} is not supported.")

return slug
17 changes: 7 additions & 10 deletions merchants/integrations/dummy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from dataclasses import dataclass
from .settings import settings

__version__ = "0.1.0"
__merchants_name__ = "dummy"
__merchants_slug__ = "dummy"


@dataclass
class Settings:
endpoint: str = "https://api.example.com"
api_key: str = "key_123456"
api_secret: str = "secret_123456"


settings = Settings()
__all__ = [
"__version__",
"__merchants_name__",
"__merchants_slug__",
"settings",
]
12 changes: 12 additions & 0 deletions merchants/integrations/dummy/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import uuid

from pydantic import BaseModel

# from .settings import settings


class DummyPayment(BaseModel):
transaction_id: uuid.UUID


def create_payment() -> DummyPayment: ...
11 changes: 11 additions & 0 deletions merchants/integrations/dummy/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import dataclass


@dataclass
class Settings:
endpoint: str = "https://api.example.com"
api_key: str = "key_123456"
api_secret: str = "secret_123456"


settings = Settings()
Loading

0 comments on commit 79c73bb

Please sign in to comment.