mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Revert "Tests: Refactor test initialization"
This reverts commit 6c8999d4ba8fc0d494428e6cc4e8c3f14aaf13ec. That commit was preventing plugin hooks from registering in reddit-run and reddit-shell contexts.
This commit is contained in:
@@ -425,8 +425,6 @@ class RedditApp(PylonsApp):
|
||||
|
||||
def setup_app_env(self, environ, start_response):
|
||||
PylonsApp.setup_app_env(self, environ, start_response)
|
||||
if environ.get('paste.testing'):
|
||||
return
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
|
||||
@@ -442,7 +442,6 @@ class Globals(object):
|
||||
raise AttributeError
|
||||
|
||||
def setup(self):
|
||||
self.env = 'unit_test' if 'test' in sys.argv[0] else ''
|
||||
self.queues = queues.declare_queues(self)
|
||||
|
||||
self.extension_subdomains = dict(
|
||||
@@ -916,14 +915,9 @@ class Globals(object):
|
||||
def load_db_params(self):
|
||||
self.databases = tuple(ConfigValue.to_iter(self.config.raw_data['databases']))
|
||||
self.db_params = {}
|
||||
self.predefined_type_ids = {}
|
||||
if not self.databases:
|
||||
return
|
||||
|
||||
if self.env == 'unit_test':
|
||||
from mock import MagicMock
|
||||
return MagicMock()
|
||||
|
||||
dbm = db_manager.db_manager()
|
||||
db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
|
||||
'pool_size', 'max_overflow')
|
||||
@@ -965,6 +959,7 @@ class Globals(object):
|
||||
return params, flags
|
||||
|
||||
prefix = 'db_table_'
|
||||
self.predefined_type_ids = {}
|
||||
for k, v in self.config.raw_data.iteritems():
|
||||
if not k.startswith(prefix):
|
||||
continue
|
||||
|
||||
@@ -533,8 +533,7 @@ class DataThing(object):
|
||||
class ThingMeta(type):
|
||||
def __init__(cls, name, bases, dct):
|
||||
if name == 'Thing' or hasattr(cls, '_nodb') and cls._nodb: return
|
||||
if g.env == 'unit_test':
|
||||
return
|
||||
#print "checking thing", name
|
||||
|
||||
#TODO exceptions
|
||||
cls._type_name = name.lower()
|
||||
@@ -667,9 +666,6 @@ class RelationMeta(type):
|
||||
if name == 'RelationCls': return
|
||||
#print "checking relation", name
|
||||
|
||||
if g.env == 'unit_test':
|
||||
return
|
||||
|
||||
cls._type_name = name.lower()
|
||||
try:
|
||||
cls._type_id = tdb.rel_types_name[cls._type_name].type_id
|
||||
|
||||
@@ -39,7 +39,19 @@ pkg_resources.working_set.add_entry(conf_dir)
|
||||
pkg_resources.require('Paste')
|
||||
pkg_resources.require('PasteScript')
|
||||
|
||||
_app_context = False
|
||||
|
||||
def stage_for_paste():
|
||||
wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
|
||||
test_app = paste.fixture.TestApp(wsgiapp)
|
||||
|
||||
# this is basically what 'paster run' does (see r2/commands.py)
|
||||
test_response = test_app.get("/_test_vars")
|
||||
request_id = int(test_response.body)
|
||||
test_app.pre_request_hook = lambda self: \
|
||||
paste.registry.restorer.restoration_end()
|
||||
test_app.post_request_hook = lambda self: \
|
||||
paste.registry.restorer.restoration_begin(request_id)
|
||||
paste.registry.restorer.restoration_begin(request_id)
|
||||
|
||||
|
||||
class RedditTestCase(TestCase):
|
||||
@@ -49,20 +61,6 @@ class RedditTestCase(TestCase):
|
||||
this isn't necessary as it'll save time.
|
||||
|
||||
"""
|
||||
if not _app_context:
|
||||
wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
|
||||
test_app = paste.fixture.TestApp(wsgiapp)
|
||||
|
||||
# this is basically what 'paster run' does (see r2/commands.py)
|
||||
test_response = test_app.get("/_test_vars")
|
||||
request_id = int(test_response.body)
|
||||
test_app.pre_request_hook = lambda self: \
|
||||
paste.registry.restorer.restoration_end()
|
||||
test_app.post_request_hook = lambda self: \
|
||||
paste.registry.restorer.restoration_begin(request_id)
|
||||
paste.registry.restorer.restoration_begin(request_id)
|
||||
|
||||
_app_context = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
stage_for_paste()
|
||||
TestCase.__init__(self, *args, **kwargs)
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
stage_for_paste()
|
||||
|
||||
import unittest
|
||||
|
||||
from r2.lib.media import _get_scrape_url
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
|
||||
stage_for_paste()
|
||||
|
||||
from r2.lib.permissions import PermissionSet, ModeratorPermissionSet
|
||||
|
||||
class TestPermissionSet(PermissionSet):
|
||||
|
||||
@@ -21,8 +21,10 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
stage_for_paste()
|
||||
|
||||
import unittest
|
||||
from r2.tests import RedditTestCase
|
||||
|
||||
from pylons import g
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
stage_for_paste()
|
||||
|
||||
import unittest
|
||||
|
||||
from r2.lib.providers.image_resizing.no_op import NoOpImageResizingProvider
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
stage_for_paste()
|
||||
|
||||
import unittest
|
||||
|
||||
from r2.lib.providers.image_resizing.unsplashit import UnsplashitImageResizingProvider
|
||||
|
||||
@@ -24,14 +24,15 @@
|
||||
import unittest
|
||||
|
||||
from r2.lib.utils import UrlParser
|
||||
from r2.tests import RedditTestCase
|
||||
from r2.tests import stage_for_paste
|
||||
from pylons import g
|
||||
|
||||
|
||||
class TestIsRedditURL(RedditTestCase):
|
||||
class TestIsRedditURL(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
stage_for_paste()
|
||||
cls._old_offsite = g.offsite_subdomains
|
||||
g.offsite_subdomains = ["blog"]
|
||||
|
||||
@@ -145,7 +146,8 @@ class TestIsRedditURL(RedditTestCase):
|
||||
self.assertIsSafeRedditUrl(u"/foo/bar/\xa0baz")
|
||||
|
||||
|
||||
class TestSwitchSubdomainByExtension(RedditTestCase):
|
||||
|
||||
class TestSwitchSubdomainByExtension(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls._old_domain = g.domain
|
||||
|
||||
@@ -22,7 +22,9 @@
|
||||
###############################################################################
|
||||
|
||||
import unittest
|
||||
from r2.tests import RedditTestCase
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
stage_for_paste()
|
||||
|
||||
from pylons import c
|
||||
from r2.lib.errors import errors, ErrorSet
|
||||
|
||||
@@ -29,7 +29,8 @@ from webob.exc import HTTPException
|
||||
|
||||
# Needs to be done before other r2 imports, since some code run on module import
|
||||
# expects a sane pylons env
|
||||
from r2.tests import RedditTestCase
|
||||
from r2.tests import stage_for_paste
|
||||
stage_for_paste()
|
||||
|
||||
from r2.lib.db.thing import NotFound
|
||||
from r2.lib.errors import errors, ErrorSet, UserRequiredException
|
||||
@@ -41,14 +42,26 @@ class TestVVerifyPassword(unittest.TestCase):
|
||||
"""Test that only the current user's password satisfies VVerifyPassword"""
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls._backup_user = c.user
|
||||
cls._backup_loggedin = c.user_is_loggedin
|
||||
|
||||
# Create a dummy account for testing with; won't touch the database
|
||||
# as long as we don't `._commit()`
|
||||
name = "unit_tester_%s" % uuid.uuid4().hex
|
||||
cls._password = uuid.uuid4().hex
|
||||
cls._account = Account(
|
||||
name=name,
|
||||
password=bcrypt_password(cls._password)
|
||||
)
|
||||
try:
|
||||
Account._by_name(name)
|
||||
raise AccountExists
|
||||
except NotFound:
|
||||
cls._account = Account(
|
||||
name=name,
|
||||
password=bcrypt_password(cls._password)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
c.user_is_loggedin = cls._backup_loggedin
|
||||
c.user = cls._backup_user
|
||||
|
||||
def setUp(self):
|
||||
c.user_is_loggedin = True
|
||||
|
||||
@@ -19,3 +19,7 @@
|
||||
# All portions of the code written by reddit are Copyright (c) 2006-2015 reddit
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
from r2.tests import stage_for_paste
|
||||
|
||||
stage_for_paste()
|
||||
|
||||
@@ -35,9 +35,9 @@ class TestPermissionSet(PermissionSet):
|
||||
class SRMemberTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
a = Account()
|
||||
a._id = 1
|
||||
a._commit()
|
||||
sr = Subreddit()
|
||||
sr._id = 2
|
||||
sr._commit()
|
||||
self.rel = SRMember(sr, a, 'test')
|
||||
|
||||
def test_get_permissions(self):
|
||||
|
||||
@@ -91,8 +91,8 @@ setup(
|
||||
# Extra dependencies that aren't needed for running the app.
|
||||
# * https://pythonhosted.org/setuptools/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies
|
||||
# * https://github.com/pypa/sampleproject/blob/300f04dc44df51492deb859ac98ba521d2c7a17a/setup.py#L71-L77
|
||||
extras_require={
|
||||
'test': ['mock', 'nose'],
|
||||
extras_require = {
|
||||
'test': ['mock'],
|
||||
},
|
||||
dependency_links=[
|
||||
"https://github.com/reddit/snudown/archive/v1.1.3.tar.gz#egg=snudown-1.1.3",
|
||||
|
||||
Reference in New Issue
Block a user