16. Flask-SQLAlchemy
Example configuration from docs:
from flask import Flask
from flaskext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] =
'sqlite:////tmp/test.db'
db = SQLAlchemy(app)
27. Flask-Script
1. Create manage.py script within your project directory and put
(which is quite similar to Django's manage.py):
from flaskext.script import Manager
from app import app
manager = Manager(app)
@manager.command
def hello():
print "hello"
if __name__ == "__main__":
manager.run()
28. Flask-Script
maxk$ python manage.py
shell Runs a Python shell inside
Flask application context.
hello
runserver Runs the Flask development
server i.e. app.run()
maxk$ python manage.py hello
hello
29. Flask-Script
With Flask-Script you able to:
• Write custom management commands
• Use existing ones like in flask-assets
• Getting user's input
• Use command line options
All of abilities above already automated with Flask-Script and
it's really easy-to-use.
31. JS/CSS minification and so on
Flask-Assets based on Webassets. To integrate we
need some work to do:
1. Install Flask-Assets
2. Initialize Flask-Assets environment
3. Add Assets Bundles
4. Configure compressors/minifiers etc. to optimize
our assets
5. Generate bundles with management command
33. Flask-Assets: Adding files
I will show work with JavaScript only but feel free to use same
approach with CSS files.
JavaScript files directory structure:
- static
- js
- src
- core
* jquery.js
* underscore.js
- app
* module1.js
* module2.js
44. Testing: Unit & Behavior
To test templates, views etc we need to have request context
Before execution:
self.app.test_request_context().push()
After execution:
self.app.test_request_context().pop()
45. Behavior Testes with Lettuce
Example feature and scenario:
Feature: Auth
Scenario: Sign In as featured expert
When I go to "auth.login" view
Then I see that response code is 200
And There's form with following fields:
| form__username |
| form__password |
Fill the field "form__username" with "featured"
46. lettuce-web
Lettuce-web is a library which very close to headless testing
using twill. lettuce-web doesn't require browser. You can
write your features using lettuce-web predefined steps.
More here:
https://github.com/joymax/lettuce-web