-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Kalkuli/develop
Solve 125 Criar Release do Projeto
- Loading branch information
Showing
18 changed files
with
1,483 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__pycache__ | ||
env | ||
.vscode/ | ||
.vscode/ | ||
htmlcov/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sudo: required | ||
services: | ||
- docker | ||
env: | ||
DOCKER_COMPOSE_VERSION: 1.21.1 | ||
before_install: | ||
- sudo rm /usr/local/bin/docker-compose | ||
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose | ||
- chmod +x docker-compose | ||
- sudo mv docker-compose /usr/local/bin | ||
before_script: | ||
- docker-compose -f docker-compose-dev.yml up --build -d | ||
script: | ||
- docker-compose -f docker-compose-dev.yml run base python manage.py test | ||
after_script: | ||
- docker-compose -f docker-compose-dev.yml down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
# Base Image | ||
FROM python:3.6.5-alpine | ||
FROM python:3.6.5-alpine | ||
|
||
|
||
# Install dependencies | ||
RUN apk update && \ | ||
apk add --virtual build-deps gcc python-dev musl-dev && \ | ||
apk add postgresql-dev && \ | ||
apk add netcat-openbsd | ||
|
||
|
||
# Setting working directory | ||
WORKDIR /usr/src/app | ||
WORKDIR /app | ||
|
||
|
||
# Dealing with requirements | ||
COPY ./requirements.txt /usr/src/app/requirements.txt | ||
RUN pip install -r requirements.txt | ||
COPY ./requirements.txt /app/requirements.txt | ||
RUN pip install -r requirements.txt | ||
|
||
|
||
# Coping project | ||
COPY . /usr/src/app | ||
COPY . /app | ||
|
||
|
||
# Add entrypoint.sh | ||
COPY ./entrypoint.sh /app/entrypoint.sh | ||
RUN chmod +x /app/entrypoint.sh | ||
|
||
|
||
# Running server | ||
CMD python manage.py run -h 0.0.0.0 | ||
CMD ["/app/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,59 @@ | ||
# Configurando o ambiente | ||
Para instruções de como instalar o Docker e o Docker-compose clique [aqui](https://github.com/Kalkuli/2018.2-Kalkuli_Front-End/blob/master/README.md). | ||
# Serviço de Apresentação de Notas | ||
|
||
<div style="text-align: center"> | ||
|
||
<a href="[![Build Status](https://travis-ci.com/Kalkuli/2018.2-Kalkuli_Receipts.svg?branch=master)](https://travis-ci.com/Kalkuli/2018.2-Kalkuli_Receipts)"><img src="https://travis-ci.com/Kalkuli/2018.2-Kalkuli_Receipts.svg?branch=master" /></a> | ||
<a href="https://codeclimate.com/github/Kalkuli/2018.2-Kalkuli_Receipts/test_coverage"><img src="https://api.codeclimate.com/v1/badges/320b61421f14848cee61/test_coverage" /></a> | ||
<a href="https://codeclimate.com/github/Kalkuli/2018.2-Kalkuli_Receipts/maintainability"><img src="https://api.codeclimate.com/v1/badges/320b61421f14848cee61/maintainability" /></a> | ||
<a href="https://opensource.org/licenses/GPL-3.0"><img src="https://img.shields.io/badge/license-GPL-%235DA8C1.svg"/></a> | ||
|
||
</div> | ||
|
||
|
||
## Configurando o ambiente | ||
|
||
Para instruções de como instalar o _Docker_ e o _Docker-Compose_ clique [aqui](https://github.com/Kalkuli/2018.2-Kalkuli_Front-End/blob/master/README.md). | ||
|
||
*** | ||
|
||
<br> | ||
|
||
## Colocando no ar | ||
Com o Docker e Docker-Compose instalados, basta apenas utilizar os comandos: | ||
Com o _Docker_ e _Docker-Compose_ instalados, basta apenas utilizar os comandos: | ||
|
||
``` | ||
chmod +x entrypoint.sh | ||
docker-compose -f docker-compose-dev.yml build | ||
```docker-compose -f docker-compose-dev.yml build``` | ||
docker-compose -f docker-compose-dev.yml up | ||
``` | ||
|
||
e | ||
Abra outro terminal, e execute o comando: | ||
|
||
|
||
``` | ||
docker-compose -f docker-compose-dev.yml run base python manage.py recreatedb | ||
``` | ||
|
||
```docker-compose -f docker-compose-dev.yml up``` | ||
|
||
Acesse o servidor local no endereço apresentado abaixo: | ||
|
||
http://localhost:5006/ | ||
[localhost:5006](http://localhost:5006/) | ||
|
||
|
||
Agora você já pode começar a contribuir! | ||
|
||
|
||
## Testando | ||
|
||
Execute o comando abaixo para executar os testes: | ||
|
||
``` | ||
docker-compose -f docker-compose-dev.yml run base python manage.py test | ||
``` | ||
|
||
Execute o comando abaixo para checar a cobertura: | ||
|
||
Agora você já pode começar a contribuir! | ||
``` | ||
docker-compose -f docker-compose-dev.yml run base python manage.py cov | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
version: '3.6' | ||
services: | ||
users: | ||
base: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile-dev | ||
volumes: | ||
- '.:/usr/src/app' | ||
- '.:/app' | ||
ports: | ||
- 5006:5000 | ||
environment: | ||
- FLASK_APP=project/__init__.py | ||
- FLASK_ENV=development | ||
- APP_SETTINGS=project.config.DevelopmentConfig | ||
- APP_SETTINGS=project.config.DevelopmentConfig | ||
- DATABASE_URL=postgres://postgres:postgres@db:5432/receipts_dev | ||
- DATABASE_TEST_URL=postgres://postgres:postgres@db:5432/receipts_test | ||
depends_on: | ||
- db | ||
|
||
|
||
db: | ||
build: | ||
context: ./project/db | ||
dockerfile: Dockerfile | ||
ports: | ||
- 5106:5432 | ||
environment: | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_PASSWORD=postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
echo "Waiting for postgres..." | ||
|
||
while ! nc -z db 5432; do | ||
sleep 0.1 | ||
done | ||
|
||
echo "PostgreSQL started" | ||
|
||
python manage.py run -h 0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,56 @@ | ||
from flask.cli import FlaskGroup | ||
from project import app | ||
import coverage | ||
|
||
cli = FlaskGroup(app) | ||
COV = coverage.coverage( | ||
branch=True, | ||
include='project/*', | ||
omit=[ | ||
'project/tests/*', | ||
'project/config.py' | ||
] | ||
) | ||
COV.start() | ||
|
||
if __name__ == '__main__': | ||
cli() | ||
from flask.cli import FlaskGroup | ||
from project import app, db | ||
from project.api.models import Receipt, Product | ||
import unittest | ||
|
||
cli = FlaskGroup(app) | ||
|
||
|
||
# Create command | ||
@cli.command() | ||
def recreatedb(): | ||
db.drop_all() | ||
db.create_all() | ||
db.session.commit() | ||
|
||
|
||
# Registers comand to run tests | ||
@cli.command() | ||
def test(): | ||
tests = unittest.TestLoader().discover('project/tests', pattern='test*.py') | ||
result = unittest.TextTestRunner(verbosity=2).run(tests) | ||
if result.wasSuccessful(): | ||
return 0 | ||
return 1 | ||
|
||
|
||
@cli.command() | ||
def cov(): | ||
"""Runs the unit tests with coverage.""" | ||
tests = unittest.TestLoader().discover('project/tests') | ||
result = unittest.TextTestRunner(verbosity=2).run(tests) | ||
if result.wasSuccessful(): | ||
COV.stop() | ||
COV.save() | ||
print('Coverage Summary:') | ||
COV.report() | ||
COV.html_report() | ||
COV.erase() | ||
return 0 | ||
return 1 | ||
|
||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import os | ||
from flask import Flask, jsonify | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
|
||
# Instantiate the app | ||
app = Flask(__name__) | ||
app = Flask(__name__) | ||
|
||
|
||
# Set Configuration | ||
app_settings = os.getenv('APP_SETTINGS') | ||
app.config.from_object(app_settings) | ||
|
||
@app.route('/', methods=['GET']) | ||
def ping_pong(): | ||
return jsonify({ | ||
'data': 'Welcome to Kalkuli Receipts Service' | ||
}) | ||
|
||
# Instanciate Database | ||
db = SQLAlchemy(app) | ||
|
||
from project.api.views import receipts_blueprint | ||
app.register_blueprint(receipts_blueprint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from project import db | ||
|
||
from sqlalchemy.sql import func | ||
|
||
|
||
class Receipt(db.Model): | ||
__tablename__ = 'receipt' | ||
|
||
id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||
company_id = db.Column(db.Integer, nullable=False) | ||
emission_date = db.Column(db.DateTime, nullable=False) | ||
emission_place = db.Column(db.String(128), nullable=False) | ||
cnpj = db.Column(db.String, nullable=False) | ||
tax_value = db.Column(db.Float, nullable=False) | ||
total_price = db.Column(db.Float, nullable=False) | ||
|
||
def __init__(self, company_id, emission_date, emission_place, cnpj, tax_value, total_price): | ||
self.company_id = company_id | ||
self.emission_date = emission_date | ||
self.emission_place = emission_place | ||
self.cnpj = cnpj | ||
self.tax_value = tax_value | ||
self.total_price = total_price | ||
|
||
def to_json(self): | ||
return { | ||
'id': self.id, | ||
'company_id': self.company_id, | ||
'emission_date': self.emission_date.date().isoformat(), | ||
'emission_place': self.emission_place, | ||
'cnpj': self.cnpj, | ||
'tax_value': self.tax_value, | ||
'total_price': self.total_price | ||
} | ||
|
||
|
||
class Product(db.Model): | ||
__tablename__ = 'product' | ||
id = db.Column(db.Integer, primary_key=True, autoincrement=True) | ||
receipt_id = db.Column(db.Integer, db.ForeignKey('receipt.id'), nullable=False) | ||
receipt = db.relationship('Receipt', backref=db.backref('products', lazy=True)) | ||
quantity = db.Column(db.Integer, nullable=False) | ||
unit_price = db.Column(db.Float, nullable=False) | ||
|
||
def __init__(self, receipt_id, quantity, unit_price): | ||
self.receipt_id = receipt_id | ||
self.quantity = quantity | ||
self.unit_price = unit_price | ||
|
||
def to_json(self): | ||
return { | ||
'id':self.id, | ||
'receipt_id':self.receipt_id, | ||
'quantity':self.quantity, | ||
'unit_price':self.unit_price | ||
} |
Oops, something went wrong.