Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: assertRaises -> assert_raises
Browse files Browse the repository at this point in the history
closes #674
  • Loading branch information
pjenvey committed Oct 4, 2016
1 parent c01eb4d commit 3e8e19d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
10 changes: 5 additions & 5 deletions autopush/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def test_no_uaid_found(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
self.assertRaises(ItemNotFound, router.get_uaid, uaid)
assert_raises(ItemNotFound, router.get_uaid, uaid)

def test_uaid_provision_failed(self):
r = get_router_table()
Expand All @@ -414,7 +414,7 @@ def raise_error(*args, **kwargs):
raise ProvisionedThroughputExceededException(None, None)

router.table.get_item.side_effect = raise_error
with self.assertRaises(ProvisionedThroughputExceededException):
with assert_raises(ProvisionedThroughputExceededException):
router.get_uaid(uaid="asdf")

def test_register_user_provision_failed(self):
Expand All @@ -426,7 +426,7 @@ def raise_error(*args, **kwargs):
raise ProvisionedThroughputExceededException(None, None)

router.table.connection.update_item.side_effect = raise_error
with self.assertRaises(ProvisionedThroughputExceededException):
with assert_raises(ProvisionedThroughputExceededException):
router.register_user(dict(uaid=dummy_uaid, node_id="me",
connected_at=1234,
router_type="simplepush"))
Expand All @@ -440,7 +440,7 @@ def raise_error(*args, **kwargs):
raise ProvisionedThroughputExceededException(None, None)

router.table.connection.put_item.side_effect = raise_error
with self.assertRaises(ProvisionedThroughputExceededException):
with assert_raises(ProvisionedThroughputExceededException):
router.clear_node(Item(r, dict(uaid=dummy_uaid,
connected_at="1234",
node_id="asdf",
Expand All @@ -459,7 +459,7 @@ def test_incomplete_uaid(self):
router.register_user(dict(uaid=uaid))
except AutopushException:
pass
self.assertRaises(ItemNotFound, router.get_uaid, uaid)
assert_raises(ItemNotFound, router.get_uaid, uaid)
ok_(router.drop_user.called)

def test_save_new(self):
Expand Down
8 changes: 4 additions & 4 deletions autopush/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import twisted.internet.base

from nose.tools import ok_, eq_
from nose.tools import assert_raises, ok_, eq_
from mock import Mock, patch

from autopush.metrics import (
Expand All @@ -17,9 +17,9 @@ class IMetricsTestCase(unittest.TestCase):
def test_default(self):
im = IMetrics()
im.start()
self.assertRaises(NotImplementedError, im.increment, "test")
self.assertRaises(NotImplementedError, im.gauge, "test", 10)
self.assertRaises(NotImplementedError, im.timing, "test", 10)
assert_raises(NotImplementedError, im.increment, "test")
assert_raises(NotImplementedError, im.gauge, "test", 10)
assert_raises(NotImplementedError, im.timing, "test", 10)


class SinkMetricsTestCase(unittest.TestCase):
Expand Down
73 changes: 38 additions & 35 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ def __call__(self, *args, **kwargs):

class RouterInterfaceTestCase(TestCase):
def test_not_implemented(self):
self.assertRaises(NotImplementedError, IRouter, None, None)
assert_raises(NotImplementedError, IRouter, None, None)

def init(self, settings, router_conf):
pass
IRouter.__init__ = init
ir = IRouter(None, None)
self.assertRaises(NotImplementedError, ir.register, "uaid", {}, "")
self.assertRaises(NotImplementedError, ir.route_notification, "uaid",
{})
self.assertRaises(NotImplementedError, ir.amend_msg, {})
assert_raises(NotImplementedError, ir.register, "uaid", {}, "")
assert_raises(NotImplementedError, ir.route_notification, "uaid", {})
assert_raises(NotImplementedError, ir.amend_msg, {})


dummy_chid = str(uuid.uuid4())
Expand Down Expand Up @@ -146,14 +145,15 @@ def test_register(self):
eq_(result, {"rel_channel": "firefox", "token": "connect_data"})

def test_register_bad(self):
self.assertRaises(RouterException, self.router.register,
"uaid", router_data={}, app_id="firefox")
with assert_raises(RouterException):
self.router.register("uaid", router_data={}, app_id="firefox")

def test_register_bad_channel(self):
self.assertRaises(RouterException, self.router.register,
"uaid",
router_data={"token": "connect_data"},
app_id="unknown")
with assert_raises(RouterException):
self.router.register(
"uaid",
router_data={"token": "connect_data"},
app_id="unknown")

@inlineCallbacks
def test_route_notification(self):
Expand Down Expand Up @@ -316,8 +316,8 @@ def test_init(self):
hostname="localhost",
statsd_host=None,
)
self.assertRaises(IOError, GCMRouter, settings,
{"senderIDs": {}})
with assert_raises(IOError):
GCMRouter(settings, {"senderIDs": {}})

def test_register(self):
result = self.router.register("uaid",
Expand All @@ -329,17 +329,15 @@ def test_register(self):
"auth": "12345678abcdefg"}})

def test_register_bad(self):
self.assertRaises(RouterException, self.router.register,
"uaid", router_data={}, app_id="")
self.assertRaises(RouterException,
self.router.register,
"uaid",
router_data={},
app_id='')
self.assertRaises(RouterException,
self.router.register, "uaid",
router_data={"token": "abcd1234"},
app_id="invalid123")
with assert_raises(RouterException):
self.router.register("uaid", router_data={}, app_id="")
with assert_raises(RouterException):
self.router.register("uaid", router_data={}, app_id='')
with assert_raises(RouterException):
self.router.register(
"uaid",
router_data={"token": "abcd1234"},
app_id="invalid123")

@patch("gcmclient.GCM")
def test_gcmclient_fail(self, fgcm):
Expand All @@ -348,8 +346,8 @@ def test_gcmclient_fail(self, fgcm):
hostname="localhost",
statsd_host=None,
)
self.assertRaises(IOError, GCMRouter, settings,
{"senderIDs": {"test123": {"auth": "abcd"}}})
with assert_raises(IOError):
GCMRouter(settings, {"senderIDs": {"test123": {"auth": "abcd"}}})

def test_route_notification(self):
self.router.gcm['test123'] = self.gcm
Expand Down Expand Up @@ -541,9 +539,11 @@ def test_amend(self):
result)

def test_register_invalid_token(self):
self.assertRaises(RouterException, self.router.register,
uaid="uaid", router_data={"token": "invalid"},
app_id="invalid")
with assert_raises(RouterException):
self.router.register(
uaid="uaid",
router_data={"token": "invalid"},
app_id="invalid")


class FCMRouterTestCase(unittest.TestCase):
Expand Down Expand Up @@ -603,7 +603,8 @@ def throw_auth(*args, **kwargs):
raise Exception("oopsy")

ffcm.side_effect = throw_auth
self.assertRaises(IOError, FCMRouter, settings, {})
with assert_raises(IOError):
FCMRouter(settings, {})

def test_register(self):
result = self.router.register("uaid",
Expand All @@ -615,8 +616,8 @@ def test_register(self):
"auth": "12345678abcdefg"}})

def test_register_bad(self):
self.assertRaises(RouterException, self.router.register, "uaid",
router_data={})
with assert_raises(RouterException):
self.router.register("uaid", router_data={})

def test_route_notification(self):
self.router.fcm = self.fcm
Expand Down Expand Up @@ -804,9 +805,11 @@ def test_amend(self):
result)

def test_register_invalid_token(self):
self.assertRaises(RouterException, self.router.register,
uaid="uaid", router_data={"token": "invalid"},
app_id="invalid")
with assert_raises(RouterException):
self.router.register(
uaid="uaid",
router_data={"token": "invalid"},
app_id="invalid")


class SimplePushRouterTestCase(unittest.TestCase):
Expand Down

0 comments on commit 3e8e19d

Please sign in to comment.