Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
Initial commit with project base.
Already dockerized.
Project's test setup configured.
  • Loading branch information
bernardohrl committed Sep 18, 2018
0 parents commit b0fd486
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env
.dockerignore
Dockerfile-dev
Dockerfile-prod
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
env
.vscode/
15 changes: 15 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Base Image
FROM python:3.6.5-alpine

# Setting working directory
WORKDIR /app

# Dealing with requirements
COPY ./requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Coping project
COPY . /app

# Running server
CMD python manage.py run -h 0.0.0.0
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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:

```docker-compose -f docker-compose-dev.yml build```

e

```docker-compose -f docker-compose-dev.yml up```

Acesse o servidor local no endereço apresentado abaixo:

http://localhost:5002/


Agora você já pode começar a contribuir!


## Testando

```docker-compose -f docker-compose-dev.yml run base python manage.py test```
14 changes: 14 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.6'
services:
base:
build:
context: .
dockerfile: Dockerfile-dev
volumes:
- '.:/app'
ports:
- 5007:5000
environment:
- FLASK_APP=project/__init__.py
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
20 changes: 20 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask.cli import FlaskGroup
from project import app
import unittest

cli = FlaskGroup(app)


# 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



if __name__ == '__main__':
cli()
15 changes: 15 additions & 0 deletions project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from flask import Flask, jsonify

# Instantiate the app
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 Exporter!'
})
Empty file added project/api/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions project/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class BaseConfig:
TESTING = False

class DevelopmentConfig(BaseConfig):
THIS = 'Development'

class TestingConfig(BaseConfig):
TESTING = True
THIS = 'Testing'

class ProductionConfig(BaseConfig):
THIS = 'Production'
Empty file added project/tests/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions project/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from flask_testing import TestCase
from project import app, db

class BaseTestCase(TestCase):

def create_app(self):
app.config.from_object('project.config.TestingConfig')
return app

def setUp(self):
db.create_all()
db.session.commit()

def tearDown(self):
db.session.remove()
db.drop_all()
43 changes: 43 additions & 0 deletions project/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import unittest
from flask import current_app
from flask_testing import TestCase
from project import app

class TestDevelopmentConfig(TestCase):
def create_app(self):
app.config.from_object('project.config.DevelopmentConfig')
return app

def test_app_is_development(self):
self.assertFalse(current_app is None)
self.assertTrue(
app.config['THIS'] == 'Development'
)


class TestTestingConfig(TestCase):
def create_app(self):
app.config.from_object('project.config.TestingConfig')
return app

def test_app_is_testing(self):
self.assertTrue(app.config['TESTING'])
self.assertFalse(app.config['PRESERVE_CONTEXT_ON_EXCEPTION'])
self.assertTrue(
app.config['THIS'] == 'Testing'
)


class TestProductionConfig(TestCase):
def create_app(self):
app.config.from_object('project.config.ProductionConfig')
return app

def test_app_is_production(self):
self.assertFalse(app.config['TESTING'])



if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==1.0.2
Flask-Testing==0.6.2

0 comments on commit b0fd486

Please sign in to comment.