Skip to content

Commit

Permalink
Tests for github
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Sep 17, 2024
1 parent a8ef388 commit 0117309
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 55 deletions.
76 changes: 37 additions & 39 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
# name: Tests&Coverage
name: Tests&Coverage

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

# 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@v3
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"
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
# merchants
# Merchants

A gateway platform to process payments
[![PyPI version](https://badge.fury.io/py/merchants.svg)](https://badge.fury.io/py/merchants)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python Versions](https://img.shields.io/pypi/pyversions/merchants.svg)](https://pypi.org/project/merchants/)
[![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi)](https://fastapi.tiangolo.com)
[![Downloads](https://pepy.tech/badge/merchants)](https://pepy.tech/project/merchants)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

## Babel
A unified payment processing toolkit for FastAPI applications, inspired by django-payments.

poetry run pybabel extract merchants/ -o test.pot
## Overview

Merchants is an all-in-one payment processing solution designed to integrate seamlessly with FastAPI applications. This
modular payment integration system aims to simplify the implementation of various payment gateways and provide a
flexible interface for handling different payment methods.

## Features

- Easy integration with FastAPI applications
- Support for multiple payment gateways
- Customizable payment workflows
- Webhook handling for payment status updates
- Extensible architecture for adding new payment providers
- Unified API across different payment services

## Installation

```bash
poetry add fastapi-merchants
```

## Quick Start

```python
from fastapi import FastAPI
from fastapi_merchants import Merchants

app = FastAPI()
merchants = Merchants(app)

# Configure your payment providers
merchants.add_provider("stripe", api_key="your_stripe_api_key")
merchants.add_provider("paypal", client_id="your_paypal_client_id", client_secret="your_paypal_client_secret")

# Use Merchants in your routes
@app.post("/create-payment")
async def create_payment(amount: float, currency: str, provider: str):
return await merchants.create_payment(amount, currency, provider)
```

## Documentation

For detailed documentation, please visit [our documentation site](https://mariofix.github.io/fastapi-merchants).

## License

Merchants is released under the MIT License. See the [LICENSE](LICENSE) file for more details.

## Acknowledgements

This project was inspired by the django-payments library and aims to provide similar functionality for FastAPI
applications, some parts were made with Claude and/or ChatGPT.

## Changelog

See the [CHANGELOG](CHANGELOG) file for more details.
2 changes: 1 addition & 1 deletion merchants/FastapiApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def add_engines(self, request: Request):
)
app.add_middleware(
DebugToolbarMiddleware,
panels=["merchants.AppFastapi.SQLModelPanel"],
panels=["merchants.FastapiApp.SQLModelPanel"],
)

admin.mount_to(app)
Expand Down
13 changes: 4 additions & 9 deletions merchants/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import secrets
from typing import Annotated, Any

from pydantic import (
AnyUrl,
BeforeValidator,
HttpUrl,
computed_field,
)
from typing import List
from pydantic import HttpUrl, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict


Expand All @@ -20,7 +14,6 @@ class Settings(BaseSettings):
@computed_field # type: ignore[prop-decorator]
@property
def server_host(self) -> str:
# Use HTTPS for anything other than local development
if self.USE_HTTPS:
return f"https://{self.DOMAIN}"
return f"http://{self.DOMAIN}"
Expand All @@ -30,5 +23,7 @@ def server_host(self) -> str:

SQLALCHEMY_DATABASE_URI: str = "sqlite:///merchants.db"

ALLOWED_DOMAINS: List[str] | None = None


settings = Settings() # type: ignore
7 changes: 6 additions & 1 deletion merchants/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from sqlmodel import Session, create_engine, select
from merchants.config import settings

engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI))

engine = create_engine(
settings.SQLALCHEMY_DATABASE_URI,
pool_recycle=1800,
pool_pre_ping=True,
)
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ python-slugify = "^8.0.4"
starlette-admin = "^0.14.1"


[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
coverage = "^7.6.1"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra"
testpaths = ["tests"]
python_files = ["test*.py"]
Expand Down
22 changes: 22 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from fastapi.testclient import TestClient
from sqlmodel import Session
from merchants.FastapiApp import app
from merchants.database import engine

# Create a test client
client = TestClient(app)


# Mock database session
@pytest.fixture
def mock_db():
with Session(engine) as session:
yield session


# Test root endpoint
def test_root():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Hello World"}

0 comments on commit 0117309

Please sign in to comment.