Skip to content

Commit ea1435e

Browse files
author
Michal Kloczko
committed
Merge branch 'v/-2.3'
2 parents 84c3d25 + d3a8e96 commit ea1435e

29 files changed

+547
-183
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.pyc
22
.venv/
3+
.tmp/
4+
src/logs
35
app.log

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
**Current version: 0.2**
2-
3-
***Main Features***
4-
- Authentication by revoking token v1
5-
6-
***Smaller Features***
7-
- Logging to file with RotatingFileHandler
8-
- Simple database operations with flask-mysql
9-
10-
***Available Endpoints***
11-
- /login
12-
- /user/{id}
1+
**Current version: 0.3**
2+
3+
***Main Features***
4+
- Authentication by revoking token v1
5+
6+
***Smaller Features***
7+
- Logging to file with RotatingFileHandler
8+
- Unit tests with inittest module
9+
- SQLAlchemy for db operations
10+
11+
***Available Endpoints***
12+
- POST /login - get auth token
13+
- GET /user/{id} - get user
14+
- POST /user - createuser

api/__init__.pyc

-125 Bytes
Binary file not shown.

api/user.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

app.log

Lines changed: 0 additions & 71 deletions
This file was deleted.

app.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

db/schema.sql

Lines changed: 0 additions & 11 deletions
This file was deleted.

manage.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import unittest
2+
import coverage
3+
import os
4+
5+
from src.app import app
6+
from src import db
7+
from src.model.user import User
8+
9+
from flask_script import Manager
10+
11+
manager = Manager(app)
12+
13+
14+
@manager.command
15+
def test():
16+
tests = unittest.TestLoader().discover('tests')
17+
result = unittest.TextTestRunner(verbosity=2).run(tests)
18+
19+
if result.wasSuccessful():
20+
return 0
21+
22+
return 1
23+
24+
25+
@manager.command
26+
def cov():
27+
"""Runs the unit tests with coverage."""
28+
cov = coverage.Coverage(
29+
branch=True,
30+
cover_pylib=False,
31+
data_file='.coverage',
32+
include=[
33+
'tests/*',
34+
'app/api/*'
35+
],
36+
omit='.venv/*'
37+
)
38+
cov.start()
39+
40+
tests = unittest.TestLoader().discover('tests')
41+
result = unittest.TextTestRunner(verbosity=2).run(tests)
42+
43+
if result.wasSuccessful():
44+
cov.stop()
45+
cov.save()
46+
print('\n\nCoverage Summary:\n')
47+
cov.report()
48+
basedir = os.path.abspath(os.path.dirname(__file__))
49+
covdir = os.path.join(basedir, '.tmp/coverage')
50+
cov.html_report(directory=covdir)
51+
print('\n\nHTML version: file://%s/index.html\n' % covdir)
52+
cov.erase()
53+
return 0
54+
55+
return 1
56+
57+
58+
@manager.command
59+
def create_db_tables():
60+
if db.create_all():
61+
return 0
62+
63+
return 1
64+
65+
66+
@manager.option('-p', '--password', dest='password')
67+
def create_admin(password):
68+
if not password:
69+
password = 'password'
70+
71+
admin = User('admin', password, True, 'ADMIN')
72+
db.session.add(admin)
73+
74+
if db.session.commit():
75+
return 0
76+
77+
return 1
78+
79+
80+
if __name__ == '__main__':
81+
manager.run()

src/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
3+
from flask import Flask
4+
from flask_restful import Api
5+
6+
from logging.handlers import RotatingFileHandler
7+
8+
from flask_sqlalchemy import SQLAlchemy
9+
from src.utils.auth import Auth
10+
11+
12+
app = Flask(__name__)
13+
api = Api(app)
14+
15+
# load settings from proper config file
16+
# for prod, set APP_SETTINGS env variable to src.config.Production
17+
# export APP_SETTINGS='src.config.Production'
18+
app_settings = os.getenv(
19+
'APP_SETTINGS', 'src.config.Development')
20+
app.config.from_object(app_settings)
21+
22+
# connect to db
23+
db = SQLAlchemy(app)
24+
25+
# init auth utils for generating api tokens etc.
26+
auth = Auth(app)
27+
28+
# init log handler
29+
log_handler = RotatingFileHandler(
30+
app.config['LOGFILE_PATH'],
31+
maxBytes=app.config['LOGFILE_MAX_BYTES'],
32+
backupCount=app.config['LOGFILE_BACKUP_COUNT']
33+
)
34+
log_handler.setLevel(app.config['LOG_LEVEL'])
35+
app.logger.addHandler(log_handler)
File renamed without changes.

0 commit comments

Comments
 (0)