mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 20:33:13 +03:00
Migrate ext.flasks tests
This commit is contained in:
parent
56c39554e7
commit
31d2c3b992
|
@ -3,3 +3,4 @@ testpaths = tests/unit
|
||||||
python_files = test_*_py2_py3.py
|
python_files = test_*_py2_py3.py
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
|
|
@ -3,3 +3,4 @@ testpaths = tests/unit
|
||||||
python_files = test_*_py3.py
|
python_files = test_*_py3.py
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
|
|
@ -3,3 +3,4 @@ testpaths = tests/unit
|
||||||
python_files = test_*_py3*.py
|
python_files = test_*_py3*.py
|
||||||
filterwarnings =
|
filterwarnings =
|
||||||
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
"""Dependency injector Flask extension unit tests."""
|
"""Flask extension tests."""
|
||||||
|
|
||||||
import unittest
|
|
||||||
from flask import Flask, url_for
|
|
||||||
from flask.views import MethodView
|
|
||||||
|
|
||||||
from dependency_injector import containers
|
from dependency_injector import containers
|
||||||
from dependency_injector.ext import flask
|
from dependency_injector.ext import flask
|
||||||
|
from flask import Flask, url_for
|
||||||
|
from flask.views import MethodView
|
||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
|
@ -30,47 +29,47 @@ class ApplicationContainer(containers.DeclarativeContainer):
|
||||||
test_class_view = flask.ClassBasedView(Test)
|
test_class_view = flask.ClassBasedView(Test)
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
@fixture
|
||||||
|
def app():
|
||||||
container = ApplicationContainer()
|
container = ApplicationContainer()
|
||||||
app = container.app()
|
app = container.app()
|
||||||
app.container = container
|
app.container = container
|
||||||
|
app.config["SERVER_NAME"] = "test-server.com"
|
||||||
app.add_url_rule("/", view_func=container.index_view.as_view())
|
app.add_url_rule("/", view_func=container.index_view.as_view())
|
||||||
app.add_url_rule("/test", "test-test", view_func=container.test_view.as_view())
|
app.add_url_rule("/test", "test-test", view_func=container.test_view.as_view())
|
||||||
app.add_url_rule("/test-class", view_func=container.test_class_view.as_view("test-class"))
|
app.add_url_rule("/test-class", view_func=container.test_class_view.as_view("test-class"))
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
class ApplicationTests(unittest.TestCase):
|
@fixture
|
||||||
|
def client(app):
|
||||||
|
with app.test_client() as client:
|
||||||
|
yield client
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.app = create_app()
|
|
||||||
self.app.config["SERVER_NAME"] = "test-server.com"
|
|
||||||
self.client = self.app.test_client()
|
|
||||||
self.client.__enter__()
|
|
||||||
|
|
||||||
def tearDown(self):
|
def test_index(client):
|
||||||
self.client.__exit__(None, None, None)
|
response = client.get("/")
|
||||||
|
|
||||||
def test_index(self):
|
assert response.status_code == 200
|
||||||
response = self.client.get("/")
|
assert response.data == b"Hello World!"
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
self.assertEqual(response.data, b"Hello World!")
|
|
||||||
|
|
||||||
def test_test(self):
|
def test_test(client):
|
||||||
response = self.client.get("/test")
|
response = client.get("/test")
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
assert response.status_code == 200
|
||||||
self.assertEqual(response.data, b"Test!")
|
assert response.data == b"Test!"
|
||||||
|
|
||||||
def test_test_class_based(self):
|
|
||||||
response = self.client.get("/test-class")
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
def test_test_class_based(client):
|
||||||
self.assertEqual(response.data, b"Test class-based!")
|
response = client.get("/test-class")
|
||||||
|
|
||||||
def test_endpoints(self):
|
assert response.status_code == 200
|
||||||
with self.app.app_context():
|
assert response.data == b"Test class-based!"
|
||||||
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")
|
def test_endpoints(app):
|
||||||
|
with app.app_context():
|
||||||
|
assert url_for("index") == "http://test-server.com/"
|
||||||
|
assert url_for("test-test") == "http://test-server.com/test"
|
||||||
|
assert url_for("test-class") == "http://test-server.com/test-class"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user