From 59097576a73d49fe42fddc173b3c60d04d1a3fb8 Mon Sep 17 00:00:00 2001 From: Massimiliano Bertinetti Date: Tue, 8 Feb 2022 14:55:57 +0100 Subject: [PATCH 1/4] fix: broken test suite --- examples/bloggy/tests.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/bloggy/tests.py b/examples/bloggy/tests.py index 62177447..e0d391df 100644 --- a/examples/bloggy/tests.py +++ b/examples/bloggy/tests.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- +from multiprocessing import context import pytest -from emmett import response, session +from emmett import request, response, session, T +from emmett.orm.migrations.utils import generate_runtime_migration from bloggy import app, db, User, auth, setup_admin @@ -14,11 +16,14 @@ def client(): @pytest.fixture(scope='module', autouse=True) def _prepare_db(request): with db.connection(): + migration = generate_runtime_migration(db) + migration.up() setup_admin() yield with db.connection(): User.all().delete() auth.delete_group('admin') + migration.down() @pytest.fixture(scope='module') @@ -26,28 +31,28 @@ def logged_client(): c = app.test_client() with c.get('/auth/login').context as ctx: c.post('/auth/login', data={ - 'email': 'walter@massivedynamics.com', - 'password': 'pocketuniverse', + 'email': 'doc@emmettbrown.com', + 'password': 'fluxcapacitor', '_csrf_token': list(ctx.session._csrf)[-1] }, follow_redirects=True) return c def test_empty_db(client): - rv = client.get('/') - assert 'No posts here so far' in rv.data + r = client.get('/') + assert 'No posts here so far' in r.data def test_login(logged_client): - logged_client.get('/') - assert session.auth.user is not None + r = logged_client.get('/') + assert r.context.session.auth.user is not None def test_no_admin_access(client): - client.get('/new') - assert response.status == 303 + r = client.get('/new') + assert r.context.response.status == 303 def test_admin_access(logged_client): - logged_client.get('/new') - assert response.status == 200 + r = logged_client.get('/new') + assert r.context.response.status == 200 From c5b6483a3f2fcec39c2258264b88fb3b13eba6ff Mon Sep 17 00:00:00 2001 From: Giovanni Barillari Date: Tue, 8 Feb 2022 15:00:24 +0100 Subject: [PATCH 2/4] Bump version to 2.4.3 --- emmett/__version__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/emmett/__version__.py b/emmett/__version__.py index 60be088d..5a8e0983 100644 --- a/emmett/__version__.py +++ b/emmett/__version__.py @@ -1 +1 @@ -__version__ = "2.4.2" +__version__ = "2.4.3" diff --git a/pyproject.toml b/pyproject.toml index be3133cc..5cf90b27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "Emmett" -version = "2.4.2" +version = "2.4.3" description = "The web framework for inventors" authors = ["Giovanni Barillari "] license = "BSD-3-Clause" From 08861bf7bcf273e3c6d4dde85181f39b3124fc0c Mon Sep 17 00:00:00 2001 From: Giovanni Barillari Date: Tue, 8 Feb 2022 15:11:18 +0100 Subject: [PATCH 3/4] chore: cleanup --- examples/bloggy/tests.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/bloggy/tests.py b/examples/bloggy/tests.py index e0d391df..4c00d36c 100644 --- a/examples/bloggy/tests.py +++ b/examples/bloggy/tests.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -from multiprocessing import context import pytest -from emmett import request, response, session, T from emmett.orm.migrations.utils import generate_runtime_migration from bloggy import app, db, User, auth, setup_admin From 26b8ea9b7d05ebea79cc5820495273b8734f1eb9 Mon Sep 17 00:00:00 2001 From: Giovanni Barillari Date: Tue, 8 Feb 2022 15:12:24 +0100 Subject: [PATCH 4/4] fix: regression in testing client cloning response --- emmett/testing/client.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/emmett/testing/client.py b/emmett/testing/client.py index c3caab23..38a6a86f 100644 --- a/emmett/testing/client.py +++ b/emmett/testing/client.py @@ -30,12 +30,20 @@ from .urls import get_host, url_parse, url_unparse -class ClientContext(object): - def __init__(self): - self.request = Request(current.request._scope, None, None) - self.response = Response() - self.response.__dict__.update(current.response.__dict__) - self.session = copy.deepcopy(current.session) +class ClientContextResponse(Response): + def __init__(self, original_response: Response): + super().__init__() + self.status = original_response.status + self.headers._data.update(original_response.headers._data) + self.cookies.update(original_response.cookies.copy()) + self.__dict__.update(original_response.__dict__) + + +class ClientContext: + def __init__(self, ctx): + self.request = Request(ctx.request._scope, None, None) + self.response = ClientContextResponse(ctx.response) + self.session = copy.deepcopy(ctx.session) self.T = current.T def __enter__(self): @@ -77,7 +85,7 @@ async def dynamic_handler(self, scope, receive, send): headers=ctx.response.headers ) finally: - scope['emt.ctx'] = ClientContext() + scope['emt.ctx'] = ClientContext(ctx) current._close_(ctx_token) return http