From d068435a9b56dcc77743025c474c19ed58e43da3 Mon Sep 17 00:00:00 2001 From: James Socol Date: Mon, 17 Sep 2012 14:17:16 -0400 Subject: [PATCH] No more import side effects for monkey patches. --- commonware/response/cookies/models.py | 5 ++++- commonware/response/cookies/monkeypatch.py | 4 +++- commonware/response/cookies/tests.py | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/commonware/response/cookies/models.py b/commonware/response/cookies/models.py index c34e8fa..0095b7c 100644 --- a/commonware/response/cookies/models.py +++ b/commonware/response/cookies/models.py @@ -1,2 +1,5 @@ # Import monkeypatch code at startup. -import commonware.response.cookies.monkeypatch +from commonware.response.cookies.monkeypatch import patch_all + + +patch_all() diff --git a/commonware/response/cookies/monkeypatch.py b/commonware/response/cookies/monkeypatch.py index 5db5293..49a648b 100644 --- a/commonware/response/cookies/monkeypatch.py +++ b/commonware/response/cookies/monkeypatch.py @@ -55,4 +55,6 @@ def set_cookie_secure(f): return r return wrapped -HttpResponse.set_cookie = set_cookie_secure(HttpResponse.set_cookie) + +def patch_all(): + HttpResponse.set_cookie = set_cookie_secure(HttpResponse.set_cookie) diff --git a/commonware/response/cookies/tests.py b/commonware/response/cookies/tests.py index 29efc9f..ef8e945 100644 --- a/commonware/response/cookies/tests.py +++ b/commonware/response/cookies/tests.py @@ -2,7 +2,10 @@ from django.http import HttpResponse from mock import patch from nose.tools import eq_ -import commonware.response.cookies.monkeypatch +from commonware.response.cookies.monkeypatch import patch_all + + +patch_all() def test_secure_cookies():