python-dependency-injector/tests/unit/ext/test_flask_py2_py3.py
Roman Mogylatov fa469618dd
Readme update (#263)
* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Add files via upload

* Update README.rst

* Rename Blank Diagram (1).svg to di-map.svg

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Add files via upload

* Rename Blank Diagram (2).svg to di-map2.svg

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Add files via upload

* Add files via upload

* Rename README.svg to di-map3.svg

* Update README.rst

* Add files via upload

* Rename README - Page 3.svg to di-map4.svg

* Update README.rst

* Add files via upload

* Rename README - Copy of Page 3.svg to di-map5.svg

* Update README.rst

* Delete di-map.svg

* Delete di-map2.svg

* Delete di-map3.svg

* Delete di-map4.svg

* Update README.rst

* Update README.rst

* Add Github Navigator - Flask application

* Do more refactoring for ghnav-flask

* More refactoring

* Update README

* Add tests

* Update readme

* Add Flask extension

* Add Factory.provides attribute

* Add Flask extension module

* User flask extension in githubnavigator example

* Add README for ghnav-flask

* Update ghnav-flask README

* Update ghnav-flask README

* Update README with ghnav container example

* Move ghnav-flask to miniapps/ folder

* Fix auth token reading from env for ghnav-flask

* Update readme

* Fix ghnav-flask linter errors

* Add downloads and wheel badge

* Add tests for flask extension

* Fix flask tests

* Add requirements-ext.txt installation to tox.ini

* Add API docs for ext.flask module

* Update setup.py

* Add Flask to the list of keywords

* Update badges on docs README

* Update docs README title

* Fix ext.flask tests

* Fix syntax of ext.flask for Python 2.7, 3.4, 3.5

* Fix syntax of ext.flask for Python 2.7, 3.4, 3.5

* Fix imports in ext.flask for Python 2.7, 3.4, 3.5

* Update ghfnav-flask README

* Update ghfnav-flask README

* Remove setting of empty github token

* Add flask extras

* Update requirements

* Update requirements

* Add flask extra to python 3.4 tox.ini

* Update changelog

* Update changelog
2020-07-11 12:15:00 -04:00

76 lines
2.0 KiB
Python

"""Dependency injector Flask extension unit tests."""
import unittest2 as unittest
from flask import url_for
from flask.views import MethodView
from dependency_injector import containers, providers
from dependency_injector.ext import flask
def index():
return 'Hello World!'
def test():
return 'Test!'
class Test(MethodView):
def get(self):
return 'Test class-based!'
class Application(containers.DeclarativeContainer):
index_view = providers.Callable(index)
test_view = providers.Callable(test)
test_class_view = providers.Factory(Test)
app = providers.Factory(
flask.create_app,
name=__name__,
routes=[
flask.Route('/', view_provider=index_view),
flask.Route('/test', 'test-test', test_view),
flask.Route('/test-class', 'test-class', test_class_view)
],
)
class ApplicationTests(unittest.TestCase):
def setUp(self):
application = Application()
self.app = application.app()
self.app.config['SERVER_NAME'] = 'test-server.com'
self.client = self.app.test_client()
self.client.__enter__()
def tearDown(self):
self.client.__exit__(None, None, None)
def test_index(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, b'Hello World!')
def test_test(self):
response = self.client.get('/test')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, b'Test!')
def test_test_class_based(self):
response = self.client.get('/test-class')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, b'Test class-based!')
def test_endpoints(self):
with self.app.app_context():
self.assertEqual(url_for('index'), 'http://test-server.com/')
self.assertEqual(url_for('test-test'), 'http://test-server.com/test')
self.assertEqual(url_for('test-class'), 'http://test-server.com/test-class')