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 #533 from mozilla-services/fix/issue-531
Browse files Browse the repository at this point in the history
fix: remove use of buggy moto from websocket/db tests
  • Loading branch information
bbangert authored Jul 19, 2016
2 parents a227cde + 07fd0ca commit a79f3a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
44 changes: 16 additions & 28 deletions autopush/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from boto.dynamodb2.layer1 import DynamoDBConnection
from boto.dynamodb2.items import Item
from mock import Mock
from moto import mock_dynamodb2
from nose.tools import eq_, assert_raises

from autopush.db import (
Expand All @@ -27,17 +26,18 @@
from autopush.metrics import SinkMetrics


mock_db2 = mock_dynamodb2()
dummy_uaid = str(uuid.UUID("abad1dea00000000aabbccdd00000000"))
dummy_chid = str(uuid.UUID("deadbeef00000000decafbad00000000"))


def setUp():
mock_db2.start()
from .test_integration import setUp
setUp()


def tearDown():
mock_db2.stop()
from .test_integration import tearDown
tearDown()


class DbCheckTestCase(unittest.TestCase):
Expand Down Expand Up @@ -232,7 +232,7 @@ def test_unregister(self):
rows = m.query_2(uaid__eq=self.uaid, chidmessageid__eq=" ")
results = list(rows)
assert(len(results) == 1)
eq_(results[0]["chids"], set([]))
eq_(results[0]["chids"], None)

# Test for the very unlikely case that there's no 'chid'
m.connection.update_item = Mock()
Expand Down Expand Up @@ -377,12 +377,11 @@ def test_update_message(self):
data1 = str(uuid.uuid4())
data2 = str(uuid.uuid4())
time1 = self._nstime()
time2 = self._nstime()+100
ttl = self._nstime()+1000
message.store_message(self.uaid, chid, time1, ttl, data1, {})
message.update_message(self.uaid, chid, time2, ttl, data2, {})
message.update_message(self.uaid, chid, time1, ttl, data2, {})
messages = list(message.fetch_messages(self.uaid))
eq_(data2, messages[0]['#dd'])
eq_(data2, messages[0]['data'])

def test_update_message_fail(self):
message = Message(get_rotating_message_table(), SinkMetrics)
Expand Down Expand Up @@ -476,25 +475,14 @@ def raise_error(*args, **kwargs):
connected_at="1234",
node_id="asdf")))

def test_save_uaid(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
result = router.register_user(dict(uaid=uaid, node_id="me",
connected_at=1234))
eq_(result[0], True)
eq_(result[1], {"uaid": uaid,
"connected_at": 1234,
"node_id": "me"})
result = router.get_uaid(uaid)
eq_(bool(result), True)
eq_(result["node_id"], "me")

def test_incomplete_uaid(self):
uaid = str(uuid.uuid4())
r = get_router_table()
router = Router(r, SinkMetrics())
router.register_user(dict(uaid=uaid))
try:
router.register_user(dict(uaid=uaid))
except:
pass
self.assertRaises(ItemNotFound, router.get_uaid, uaid)
self.assertRaises(ItemNotFound, router.table.get_item,
consistent=True, uaid=uaid)
Expand Down Expand Up @@ -530,13 +518,13 @@ def test_node_clear(self):
# Register a node user
router.register_user(dict(uaid=dummy_uaid, node_id="asdf",
connected_at=1234,
router_key="webpush"))
router_type="webpush"))

# Verify
user = router.get_uaid(dummy_uaid)
eq_(user["node_id"], "asdf")
eq_(user["connected_at"], 1234)
eq_(user["router_key"], "webpush")
eq_(user["router_type"], "webpush")

# Clear
router.clear_node(user)
Expand All @@ -545,7 +533,7 @@ def test_node_clear(self):
user = router.get_uaid(dummy_uaid)
eq_(user.get("node_id"), None)
eq_(user["connected_at"], 1234)
eq_(user["router_key"], "webpush")
eq_(user["router_type"], "webpush")

def test_node_clear_fail(self):
r = get_router_table()
Expand All @@ -565,8 +553,8 @@ def test_drop_user(self):
r = get_router_table()
router = Router(r, SinkMetrics())
# Register a node user
router.register_user(dict(uaid=uaid, node_id="asdf",
connected_at=1234))
router.table.put_item(data=dict(uaid=uaid, node_id="asdf",
connected_at=1234))
result = router.drop_user(uaid)
eq_(result, True)
# Deleting already deleted record should return false.
Expand Down
17 changes: 8 additions & 9 deletions autopush/tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
)
from cyclone.web import Application
from mock import Mock, patch
from moto import mock_dynamodb2
from nose.tools import eq_, ok_
from txstatsd.metrics.metrics import Metrics
from twisted.internet import reactor
Expand All @@ -37,16 +36,15 @@
from .test_router import MockAssist


mock_dynamodb2 = mock_dynamodb2()


def setUp():
mock_dynamodb2.start()
from .test_integration import setUp
setUp()
create_rotating_message_table()


def tearDown():
mock_dynamodb2.stop()
from .test_integration import tearDown
tearDown()


class WebsocketTestCase(unittest.TestCase):
Expand Down Expand Up @@ -433,7 +431,7 @@ def test_hello_old(self):
"current_month": msg_date,
}
router = self.proto.ap_settings.router
router.register_user(dict(
router.table.put_item(data=dict(
uaid=orig_uaid,
connected_at=ms_time(),
current_month=msg_date,
Expand Down Expand Up @@ -570,10 +568,11 @@ def test_hello_with_missing_router_type(self):
self._connect()
uaid = uuid.uuid4().hex
router = self.proto.ap_settings.router
router.register_user(dict(
router.table.put_item(data=dict(
uaid=uaid,
connected_at=ms_time(),
connected_at=ms_time()-1000,
))

self._send_message(dict(messageType="hello", channelIDs=[],
uaid=uaid))

Expand Down

0 comments on commit a79f3a6

Please sign in to comment.