Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
diogodafiti authored and dutradda committed Jan 5, 2017
1 parent 582ec75 commit fa4fd90
Show file tree
Hide file tree
Showing 62 changed files with 6,820 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[run]
omit =
version.py
*__init__*

branch = True
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# sublime-text
*.sublime-*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: python
python:
- "3.6"
services:
- mysql
- redis
script: py.test -c pytest-travis.ini
install:
- pip install -r requirements.txt -r requirements-dev.txt
- pip install coveralls
after_success:
- coveralls
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Diogo Dutra
Copyright (c) 2016 Diogo Dutra <dutradda@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include swaggerit/swagger_schema_extended.json
include swaggerit/swagger_template.json
include README.md
include requirements.txt
include requirements-dev.txt
include version.py
28 changes: 28 additions & 0 deletions bin/bash_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Sets the SWAGGERIT_DEV_HOME variable to your working directory
# export SWAGGERIT_DEV_HOME=$HOME/dev/swaggerit


function docker-compose-wrapper-swaggerit {
docker-compose -f $SWAGGERIT_DEV_HOME/docker/docker-compose.yml "${@}"
}


function swaggerit-exec {
docker-compose-wrapper-swaggerit exec swaggerit "${@}"
}


function swaggerit-up {
docker-compose-wrapper-swaggerit up -d "${@}"
}


function swaggerit-kill {
docker-compose-wrapper-swaggerit kill "${@}"
}


function swaggerit-tests {
swaggerit-up &>/dev/null
docker-compose-wrapper-swaggerit exec swaggerit run-tests "${@}"
}
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.6-alpine

MAINTAINER Diogo Dutra <dutradda@gmail.com>
RUN apk update && apk add bash alpine-sdk
RUN git clone http://github.com/dutradda/swaggerit --branch forking_from_falcon_swagger_with_redis_async /tmp/swaggerit
RUN pip install -r /tmp/swaggerit/requirements-dev.txt -r /tmp/swaggerit/requirements.txt
RUN rm -rf /tmp/swaggerit
ADD run_tests.sh /usr/bin/run-tests
ENTRYPOINT /bin/bash
25 changes: 25 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "2"
services:
mysql:
image: wangxian/alpine-mysql
container_name: swaggerit-mysql
environment:
MYSQL_ROOT_PASSWORD: root
redis:
image: redis:alpine
container_name: swaggerit-redis
swaggerit:
build: .
image: swaggerit
container_name: swaggerit
stdin_open: true
tty: true
depends_on:
- mysql
- redis
links:
- mysql:swaggerit-mysql
- redis:swaggerit-redis
volumes:
- $SWAGGERIT_DEV_HOME:/swaggerit
- $MYRECO_DEV_HOME:/myreco
5 changes: 5 additions & 0 deletions docker/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

cd /swaggerit
pip install -r requirements-dev.txt -r requirements.txt
py.test -c pytest-docker.ini $@
14 changes: 14 additions & 0 deletions pytest-docker-vars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"database": {
"host": "swaggerit-mysql",
"port": 3306,
"user": "root",
"password": "root",
"database": "swaggerit_test"
},
"redis": {
"host": "swaggerit-redis",
"port": 6379,
"db": 0
}
}
2 changes: 2 additions & 0 deletions pytest-docker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --cov=swaggerit --no-cov-on-fail --exitfirst --variables pytest-docker-vars.json
14 changes: 14 additions & 0 deletions pytest-travis-vars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"database": {
"host": "localhost",
"port": 3306,
"user": "root",
"password": null,
"database": "swaggerit_test"
},
"redis": {
"host": "localhost",
"port": 6379,
"db": 0
}
}
2 changes: 2 additions & 0 deletions pytest-travis.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --cov=swaggerit --no-cov-on-fail --exitfirst --variables pytest-travis-vars.json
14 changes: 14 additions & 0 deletions pytest-vars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"database": {
"host": "localhost",
"port": 3306,
"user": "root",
"password": "root",
"database": "swaggerit_test"
},
"redis": {
"host": "localhost",
"port": 6379,
"db": 5
}
}
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --cov=swaggerit --cov-report=html --no-cov-on-fail --exitfirst --variables pytest-vars.json
6 changes: 6 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest==3.0.5
pytest-cov==2.4.0
pytest-variables[hjson]==1.4
pytest-aiohttp==0.1.3
ipython==5.1.0
PyMySQL==0.7.9
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SQLAlchemy==1.1.1
jsonschema==2.5.1
ujson==1.35
hiredis==0.2.0
aioredis==0.2.9
aiohttp==1.2.0
uvloop==0.7.1
73 changes: 73 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# MIT License

# Copyright (c) 2016 Diogo Dutra <dutradda@gmail.com>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


from version import VERSION
from setuptools import setup, find_packages


long_description = ''


install_requires = []
with open('requirements.txt') as requirements:
install_requires = requirements.readlines()[:-1]


tests_require = []
with open('requirements-dev.txt') as requirements_dev:
tests_require = requirements_dev.readlines()


setup(
name='swaggerit',
packages=find_packages('.'),
include_package_data=True,
version=VERSION,
description='A Framework featuring Swagger, SQLAlchemy and Redis',
long_description=long_description,
author='Diogo Dutra',
author_email='dutradda@gmail.com',
url='https://github.com/dutradda/swaggerit',
download_url='http://github.com/dutradda/swaggerit/archive/master.zip',
license='MIT',
keywords='framework swagger openapi sqlalchemy redis crud',
setup_requires=[
'pytest-runner==2.9',
'setuptools==28.3.0'
],
tests_require=tests_require,
install_requires=install_requires,
dependency_links=[
'https://github.com/dutradda/sanic/archive/master.tar.gz'
],
classifiers=[
'License :: OSI Approved :: MIT License',
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Natural Language :: English',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware',
'Topic :: Database :: Front-Ends',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
Empty file added swaggerit/__init__.py
Empty file.
67 changes: 67 additions & 0 deletions swaggerit/aiohttp_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# MIT License

# Copyright (c) 2016 Diogo Dutra <dutradda@gmail.com>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


from swaggerit.api import SwaggerAPI
from swaggerit.request import SwaggerRequest
from aiohttp.web import Application, Response as AioHttpResponse
from urllib.parse import parse_qs
import ujson


class AioHttpAPI(SwaggerAPI, Application):

def __init__(self, models, *, sqlalchemy_bind=None, redis_bind=None,
swagger_json_template=None, title=None, version='1.0.0',
authorizer=None, get_swagger_req_auth=True, loop=None,
debug=False):
Application.__init__(self, loop=loop, debug=debug)
SwaggerAPI.__init__(self, models, sqlalchemy_bind, redis_bind, swagger_json_template,
title, version, authorizer, get_swagger_req_auth)

def _set_handler_decorator(self, method):
method = self._method_decorator(method)

async def _method_wrapper(req):
req = self._cast_request(req)
resp = await method(req)
return self._cast_response(resp)
return _method_wrapper

def _set_route(self, path, method, handler):
self.router.add_route(method.upper(), path, handler)
self.router.add_route(method.upper(), path + '/', handler)

def _cast_request(self, req):
query = {k: ','.join(v) for k, v in parse_qs(req.rel_url.query_string).items()}
headers = {k.decode().lower(): v.decode() for k, v in req.raw_headers}
body = req.content if req.has_body else None
return SwaggerRequest(
req.path, req.method.lower(),
path_params=dict(req.match_info),
query=query, headers=headers,
body=body)

def _cast_response(self, resp):
body = None if resp.body is None else resp.body.encode()
return AioHttpResponse(body=body, status=resp.status_code,
headers=resp.headers)
Loading

0 comments on commit fa4fd90

Please sign in to comment.