Skip to content

Commit

Permalink
Merge pull request #2 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.2
  • Loading branch information
pomponchik authored Oct 18, 2023
2 parents 28250cd + b9f67d5 commit 83c6a4e
Showing 9 changed files with 154 additions and 15 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: tests

on:
push

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install the library
shell: bash
run: python setup.py install

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Run tests and show coverage on the command line
run: coverage run --source=cbfa --omit="*tests*" -m pytest --cache-clear && coverage report -m

- name: Upload reports to codecov
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
if: runner.os == 'Linux'
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
find . -iregex "codecov.*"
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -8,3 +8,5 @@ __pycache__
*.egg-info
dist
build
venv
.pytest_cache
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# cbfa

[![Downloads](https://static.pepy.tech/badge/cbfa/month)](https://pepy.tech/project/cbfa)
[![Downloads](https://static.pepy.tech/badge/cbfa)](https://pepy.tech/project/cbfa)
[![codecov](https://codecov.io/gh/pomponchik/cbfa/graph/badge.svg?token=7XDY2T7S68)](https://codecov.io/gh/pomponchik/cbfa)
[![Test-Package](https://github.com/pomponchik/cbfa/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/cbfa/actions/workflows/tests_and_coverage.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/cbfa.svg)](https://pypi.python.org/pypi/cbfa)
[![PyPI version](https://badge.fury.io/py/cbfa.svg)](https://badge.fury.io/py/cbfa)


Немного манки-патчинга для FastAPI, хендлеры на основе классов. Пока без поддержки ```self```.

Устанавливаем:
8 changes: 4 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wheel==0.33.1
pip==19.0.3
twine==1.13.0
pyparsing>=2.0.2
pytest==7.4.2
coverage==7.2.7
twine==4.0.2
wheel==0.40.0
35 changes: 24 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
from setuptools import setup, find_packages

with open("README.md", "r") as readme_file:

with open('README.md', 'r', encoding='utf8') as readme_file:
readme = readme_file.read()

requirements = []

setup(
name="cbfa",
version="0.0.1",
author="Evgeniy Blinov",
author_email="zheni-b@yandex.ru",
description="Class-based views for the FastAPI",
name='cbfa',
version='0.0.2',
author='Evgeniy Blinov',
author_email='zheni-b@yandex.ru',
description='Class-based views for the FastAPI',
long_description=readme,
long_description_content_type="text/markdown",
url="https://github.com/pomponchik/cbfa",
packages=find_packages(),
long_description_content_type='text/markdown',
url='https://github.com/pomponchik/cbfa',
packages=find_packages(exclude='tests'),
install_requires=requirements,
classifiers=[
"Programming Language :: Python :: 3.8",
"License :: OSI Approved :: MIT License",
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
'Framework :: FastAPI',
],
)
Empty file added tests/__init__.py
Empty file.
Empty file added tests/smokes/__init__.py
Empty file.
Empty file added tests/units/__init__.py
Empty file.
75 changes: 75 additions & 0 deletions tests/units/test_class_based.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from cbfa import ClassBased


class PseudoApp:
def __init__(self):
self.calls = []

def get(self, url):
self.calls.append(('get', url))
return lambda x: x
def post(self, url):
self.calls.append(('post', url))
return lambda x: x
def put(self, url):
self.calls.append(('put', url))
return lambda x: x
def delete(self, url):
self.calls.append(('delete', url))
return lambda x: x
def trace(self, url):
self.calls.append(('trace', url))
return lambda x: x
def head(self, url):
self.calls.append(('head', url))
return lambda x: x
def options(self, url):
self.calls.append(('options', url))
return lambda x: x
def connect(self, url):
self.calls.append(('connect', url))
return lambda x: x
def patch(self, url):
self.calls.append(('patch', url))
return lambda x: x


def test_wrap_only_get():
app = PseudoApp()
wrapper = ClassBased(app)

@wrapper('/kek')
class SomeItem:
def get():
pass

assert app.calls == [('get', '/kek')]


def test_wrap_all():
url = '/kek'
app = PseudoApp()
wrapper = ClassBased(app)

@wrapper(url)
class SomeItem:
def get():
pass
def post():
pass
def put():
pass
def delete():
pass
def trace():
pass
def head():
pass
def options():
pass
def connect():
pass
def patch():
pass

assert app.calls == [('get', url), ('post', url), ('put', url), ('delete', url), ('trace', url), ('head', url), ('options', url), ('connect', url), ('patch', url)]

0 comments on commit 83c6a4e

Please sign in to comment.