diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9039563 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +env +.dockerignore +Dockerfile-dev +Dockerfile-prod \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc15f85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +env +.vscode/ \ No newline at end of file diff --git a/Dockerfile-dev b/Dockerfile-dev new file mode 100644 index 0000000..4103d03 --- /dev/null +++ b/Dockerfile-dev @@ -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 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..87c0fd4 --- /dev/null +++ b/README.md @@ -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). + + +
+ +## 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``` \ No newline at end of file diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000..3a2a7e9 --- /dev/null +++ b/docker-compose-dev.yml @@ -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 \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..85d596c --- /dev/null +++ b/manage.py @@ -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() \ No newline at end of file diff --git a/project/__init__.py b/project/__init__.py new file mode 100644 index 0000000..50bd7a7 --- /dev/null +++ b/project/__init__.py @@ -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!' + }) \ No newline at end of file diff --git a/project/api/__init__.py b/project/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/config.py b/project/config.py new file mode 100644 index 0000000..5a545a9 --- /dev/null +++ b/project/config.py @@ -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' \ No newline at end of file diff --git a/project/tests/__init__.py b/project/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/project/tests/base.py b/project/tests/base.py new file mode 100644 index 0000000..9a5c86d --- /dev/null +++ b/project/tests/base.py @@ -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() \ No newline at end of file diff --git a/project/tests/test_config.py b/project/tests/test_config.py new file mode 100644 index 0000000..7658c8e --- /dev/null +++ b/project/tests/test_config.py @@ -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() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..34ae3d4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==1.0.2 +Flask-Testing==0.6.2 \ No newline at end of file