Remove stub() test helper.

This commit is contained in:
Steve Howell
2016-07-27 13:09:33 -07:00
committed by Tim Abbott
parent ec6c9ba436
commit 51bae8abc4
2 changed files with 5 additions and 12 deletions

View File

@@ -59,14 +59,6 @@ API_KEYS = {} # type: Dict[text_type, text_type]
skip_py3 = unittest.skipIf(six.PY3, "Expected failure on Python 3")
@contextmanager
def stub(obj, name, f):
# type: (Any, str, Callable[..., Any]) -> Generator[None, None, None]
old_f = getattr(obj, name)
setattr(obj, name, f)
yield
setattr(obj, name, old_f)
@contextmanager
def simulated_queue_client(client):
# type: (type) -> Generator[None, None, None]

View File

@@ -6,7 +6,7 @@ from typing import Any, Dict, List, Mapping, Optional, Sequence
from zerver.lib import cache
from zerver.lib.test_helpers import (
AuthedTestCase, queries_captured, stub, tornado_redirected_to_list
AuthedTestCase, queries_captured, tornado_redirected_to_list
)
from zerver.decorator import (
@@ -31,6 +31,7 @@ from zerver.lib.actions import (
)
from django.http import HttpResponse
import mock
import random
import ujson
import six
@@ -1111,16 +1112,16 @@ class SubscriptionAPITest(AuthedTestCase):
def test_user_settings_for_adding_streams(self):
# type: () -> None
with stub(UserProfile, 'can_create_streams', lambda self: False):
with mock.patch('zerver.models.UserProfile.can_create_streams', return_value=False):
result = self.common_subscribe_to_streams(self.test_email, ['stream1'])
self.assert_json_error(result, 'User cannot create streams.')
with stub(UserProfile, 'can_create_streams', lambda self: True):
with mock.patch('zerver.models.UserProfile.can_create_streams', return_value=True):
result = self.common_subscribe_to_streams(self.test_email, ['stream2'])
self.assert_json_success(result)
# User should still be able to subscribe to an existing stream
with stub(UserProfile, 'can_create_streams', lambda self: False):
with mock.patch('zerver.models.UserProfile.can_create_streams', return_value=False):
result = self.common_subscribe_to_streams(self.test_email, ['stream2'])
self.assert_json_success(result)