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

Commit

Permalink
Merge pull request #681 from mozilla-services/fix/674
Browse files Browse the repository at this point in the history
issue 674: kill asserts
  • Loading branch information
pjenvey authored Oct 4, 2016
2 parents 3ee93db + fd3f8ec commit 5cbfd81
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 173 deletions.
42 changes: 21 additions & 21 deletions autopush/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ def test_custom_tablename(self):
db = DynamoDBConnection()
db_name = "storage_%s" % uuid.uuid4()
dblist = db.list_tables()["TableNames"]
assert db_name not in dblist
ok_(db_name not in dblist)

create_storage_table(db_name)
dblist = db.list_tables()["TableNames"]
assert db_name in dblist
ok_(db_name in dblist)

def test_provisioning(self):
db_name = "storage_%s" % uuid.uuid4()

s = create_storage_table(db_name, 8, 11)
assert s.throughput["read"] == 8
assert s.throughput["write"] == 11
eq_(s.throughput["read"], 8)
eq_(s.throughput["write"], 11)

def test_dont_save_older(self):
s = get_storage_table()
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_register(self):
# Verify its in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert(len(results) == 1)
eq_(len(results), 1)

def test_unregister(self):
chid = str(uuid.uuid4())
Expand All @@ -247,15 +247,15 @@ def test_unregister(self):
# Verify its in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert(len(results) == 1)
eq_(len(results), 1)
eq_(results[0]["chids"], set([chid]))

message.unregister_channel(self.uaid, chid)

# Verify its not in the db
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert(len(results) == 1)
eq_(len(results), 1)
eq_(results[0]["chids"], None)

# Test for the very unlikely case that there's no 'chid'
Expand All @@ -275,13 +275,13 @@ def test_all_channels(self):
message.register_channel(self.uaid, chid2)

_, chans = message.all_channels(self.uaid)
assert(chid in chans)
assert(chid2 in chans)
ok_(chid in chans)
ok_(chid2 in chans)

message.unregister_channel(self.uaid, chid2)
_, chans = message.all_channels(self.uaid)
assert(chid2 not in chans)
assert(chid in chans)
ok_(chid2 not in chans)
ok_(chid in chans)

def test_save_channels(self):
chid = str(uuid.uuid4())
Expand All @@ -301,7 +301,7 @@ def test_all_channels_no_uaid(self):
m = get_rotating_message_table()
message = Message(m, SinkMetrics())
exists, chans = message.all_channels(dummy_uaid)
assert(chans == set([]))
eq_(chans, set([]))

def test_message_storage(self):
chid = str(uuid.uuid4())
Expand Down Expand Up @@ -386,24 +386,24 @@ def test_custom_tablename(self):
db = DynamoDBConnection()
db_name = "router_%s" % uuid.uuid4()
dblist = db.list_tables()["TableNames"]
assert db_name not in dblist
ok_(db_name not in dblist)

create_router_table(db_name)
dblist = db.list_tables()["TableNames"]
assert db_name in dblist
ok_(db_name in dblist)

def test_provisioning(self):
db_name = "router_%s" % uuid.uuid4()

r = create_router_table(db_name, 3, 17)
assert r.throughput["read"] == 3
assert r.throughput["write"] == 17
eq_(r.throughput["read"], 3)
eq_(r.throughput["write"], 17)

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
5 changes: 3 additions & 2 deletions autopush/tests/test_diagnostic_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mock import Mock, patch
from moto import mock_dynamodb2
from nose.tools import eq_
from nose.tools import eq_, ok_


mock_dynamodb2 = mock_dynamodb2()
Expand Down Expand Up @@ -37,7 +37,8 @@ def test_bad_endpoint(self):
"--router_tablename=fred",
"http://someendpoint",
])
assert cli.run()
returncode = cli.run()
ok_(returncode not in (None, 0))

@patch("autopush.diagnostic_cli.AutopushSettings")
def test_successfull_lookup(self, mock_settings_class):
Expand Down
Loading

0 comments on commit 5cbfd81

Please sign in to comment.