incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: fix unit tests requiring global request to mock it
Date Fri, 01 Nov 2013 19:43:36 GMT
Updated Branches:
  refs/heads/master 944056dfd -> 2ccaae5a5


fix unit tests requiring global request to mock it


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/2ccaae5a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/2ccaae5a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/2ccaae5a

Branch: refs/heads/master
Commit: 2ccaae5a5723a14fde79a5820af8b66b99141765
Parents: 944056d
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Nov 1 19:30:02 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Nov 1 19:43:19 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/model/test_artifact.py   |  7 ++++--
 Allura/allura/tests/model/test_auth.py       |  4 +++-
 Allura/allura/tests/model/test_filesystem.py | 29 ++++++++++++++++-------
 3 files changed, 28 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2ccaae5a/Allura/allura/tests/model/test_artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_artifact.py b/Allura/allura/tests/model/test_artifact.py
index cc27a7b..3a4fec7 100644
--- a/Allura/allura/tests/model/test_artifact.py
+++ b/Allura/allura/tests/model/test_artifact.py
@@ -26,10 +26,11 @@ from datetime import datetime
 from pylons import tmpl_context as c
 from nose.tools import assert_raises
 from nose import with_setup
-
+from mock import patch
 from ming.orm.ormsession import ThreadLocalORMSession
 from ming.orm import Mapper
 from bson import ObjectId
+from webob import Request
 
 import allura
 from allura import model as M
@@ -146,7 +147,9 @@ def test_artifact_messageid():
 @with_setup(setUp, tearDown)
 def test_versioning():
     pg = WM.Page(title='TestPage3')
-    pg.commit()
+    with patch('allura.model.artifact.request',
+               Request.blank('/', remote_addr='1.1.1.1')):
+        pg.commit()
     ThreadLocalORMSession.flush_all()
     pg.text = 'Here is some text'
     pg.commit()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2ccaae5a/Allura/allura/tests/model/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 433a6be..523298d 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -23,6 +23,7 @@ Model tests for auth
 from nose.tools import with_setup, assert_equal
 from pylons import tmpl_context as c, app_globals as g
 from webob import Request
+from mock import patch
 
 from pymongo.errors import DuplicateKeyError
 from ming.orm.ormsession import ThreadLocalORMSession
@@ -57,7 +58,8 @@ def test_email_address():
     assert addr2
     addr4 = M.EmailAddress.upsert('test@SF.NET')
     assert addr4 is addr2
-    addr.send_verification_link()
+    with patch('allura.lib.app_globals.request', Request.blank('/')):
+        addr.send_verification_link()
     assert addr is c.user.address_object('test_admin@sf.net')
     c.user.claim_address('test@SF.NET')
     assert 'test@sf.net' in c.user.email_addresses

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2ccaae5a/Allura/allura/tests/model/test_filesystem.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_filesystem.py b/Allura/allura/tests/model/test_filesystem.py
index 7573f65..a10b0ef 100644
--- a/Allura/allura/tests/model/test_filesystem.py
+++ b/Allura/allura/tests/model/test_filesystem.py
@@ -22,10 +22,11 @@ from unittest import TestCase
 from cStringIO import StringIO
 from io import BytesIO
 
-from pylons import response
 from pylons import tmpl_context as c
 from ming.orm import session, Mapper
 from nose.tools import assert_equal
+from mock import patch
+from webob import Request, Response
 
 from allura import model as M
 from alluratest.controller import setup_unit_test
@@ -119,16 +120,26 @@ class TestFile(TestCase):
         assert self.db.fs.chunks.count() == 2
         self._assert_content(f, 'test2')
 
-    def test_serve(self):
+    def test_serve_embed(self):
         f = File.from_data(u'te s\u0b6e1.txt', 'test1')
         self.session.flush()
-        assert [ 'test1' ] == list(f.serve())
-        assert response.content_type == f.content_type
-        assert 'Content-Disposition' not in response.headers
-        assert [ 'test1' ] == list(f.serve(False))
-        assert response.content_type == f.content_type
-        assert response.headers['Content-Disposition'] == \
-            'attachment;filename="te s\xe0\xad\xae1.txt"'
+        with patch('allura.lib.utils.tg.request', Request.blank('/')), \
+                patch('allura.lib.utils.pylons.response', Response()) as response:
+            response_body = list(f.serve())
+            assert_equal([ 'test1' ], response_body)
+            assert_equal(response.content_type, f.content_type)
+            assert 'Content-Disposition' not in response.headers
+
+    def test_serve_embed_false(self):
+        f = File.from_data(u'te s\u0b6e1.txt', 'test1')
+        self.session.flush()
+        with patch('allura.lib.utils.tg.request', Request.blank('/')), \
+                patch('allura.lib.utils.pylons.response', Response()) as response:
+            response_body = list(f.serve(embed=False))
+            assert_equal([ 'test1' ], response_body)
+            assert_equal(response.content_type, f.content_type)
+            assert_equal(response.headers['Content-Disposition'],
+                'attachment;filename="te s\xe0\xad\xae1.txt"')
 
     def test_image(self):
         path = os.path.join(


Mime
View raw message