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

Commit

Permalink
fix: kill websocket.Notification (#707)
Browse files Browse the repository at this point in the history
this was now dead code only misused by tests

closes #706
  • Loading branch information
pjenvey authored and bbangert committed Oct 14, 2016
1 parent 85ed155 commit e564a97
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
66 changes: 31 additions & 35 deletions autopush/tests/test_websocket.py
Expand Up @@ -20,11 +20,11 @@
from autopush.db import create_rotating_message_table
from autopush.settings import AutopushSettings
from autopush.tests import MockAssist
from autopush.utils import WebPushNotification
from autopush.websocket import (
PushState,
PushServerProtocol,
RouterHandler,
Notification,
NotificationHandler,
WebSocketServerProtocol,
)
Expand All @@ -51,6 +51,21 @@
"content-encoding": "aesgcm",
"TTL": "60",
}
dummy_chid = uuid.uuid4()
dummy_chid_str = str(dummy_chid)
dummy_uaid = uuid.uuid4()


def dummy_notif(**kwargs):
_kwargs = dict(
uaid=dummy_uaid,
channel_id=dummy_chid,
data=dummy_data.encode("utf-8"),
headers=dummy_headers,
ttl=20
)
_kwargs.update(kwargs)
return WebPushNotification(**_kwargs)


def setUp():
Expand Down Expand Up @@ -391,18 +406,12 @@ def wait_for_agent_call(): # pragma: nocover

def test_close_with_delivery_cleanup_using_webpush(self):
self._connect()
self.proto.ps.uaid = uuid.uuid4().hex
self.proto.ap_settings.clients["asdf"] = self.proto
self.proto.ps.uaid = dummy_uaid.hex
self.proto.ap_settings.clients[dummy_uaid.hex] = self.proto
self.proto.ps.use_webpush = True
chid = str(uuid.uuid4())

# Stick an un-acked direct notification in
self.proto.ps.direct_updates[chid] = [
Notification(channel_id=chid, version=dummy_version,
headers=dummy_headers,
data=dummy_data.encode("utf-8"), ttl=200,
timestamp=0)
]
self.proto.ps.direct_updates[dummy_chid_str] = [dummy_notif()]

# Apply some mocks
self.proto.ap_settings.message.store_message = Mock()
Expand Down Expand Up @@ -1646,31 +1655,22 @@ def test_nack_no_version(self):

def test_ack_remove(self):
self._connect()
chid = str(uuid.uuid4())
notif = Notification(version=dummy_version, headers=dummy_headers,
data=dummy_data.encode("utf-8"),
channel_id=chid, ttl=200, timestamp=0)
self.proto.ps.updates_sent[chid] = [notif]
self.proto._handle_webpush_update_remove(None, chid, notif)
eq_(self.proto.ps.updates_sent[chid], [])
notif = dummy_notif()
self.proto.ps.updates_sent[dummy_chid_str] = [notif]
self.proto._handle_webpush_update_remove(None, dummy_chid_str, notif)
eq_(self.proto.ps.updates_sent[dummy_chid_str], [])

def test_ack_remove_not_set(self):
self._connect()
chid = str(uuid.uuid4())
notif = Notification(version=dummy_version, headers=dummy_headers,
data=dummy_data.encode("utf-8"),
channel_id=chid, ttl=200, timestamp=0)
self.proto.ps.updates_sent[chid] = None
self.proto._handle_webpush_update_remove(None, chid, notif)
notif = dummy_notif()
self.proto.ps.updates_sent[dummy_chid_str] = None
self.proto._handle_webpush_update_remove(None, dummy_chid_str, notif)

def test_ack_remove_missing(self):
self._connect()
chid = str(uuid.uuid4())
notif = Notification(version=dummy_version, headers=dummy_headers,
data=dummy_data.encode("utf-8"),
channel_id=chid, ttl=200, timestamp=0)
self.proto.ps.updates_sent[chid] = []
self.proto._handle_webpush_update_remove(None, chid, notif)
notif = dummy_notif()
self.proto.ps.updates_sent[dummy_chid_str] = []
self.proto._handle_webpush_update_remove(None, dummy_chid_str, notif)

def test_ack_fails_first_time(self):
self._connect()
Expand Down Expand Up @@ -1838,13 +1838,9 @@ def check_error(result):

def test_process_notif_doesnt_run_with_webpush_outstanding(self):
self._connect()
self.proto.ps.uaid = uuid.uuid4().hex
self.proto.ps.uaid = dummy_uaid.hex
self.proto.ps.use_webpush = True
self.proto.ps.updates_sent["chid"] = [
Notification(channel_id="chid", data=dummy_data.encode("utf-8"),
headers=dummy_headers, version="now", ttl=200,
timestamp=0)
]
self.proto.ps.updates_sent[dummy_chid_str] = [dummy_notif()]
self.proto.deferToLater = Mock()
self.proto.process_notifications()
ok_(self.proto.deferToLater.called)
Expand Down
6 changes: 0 additions & 6 deletions autopush/websocket.py
Expand Up @@ -121,12 +121,6 @@ def wrapper(self, *args, **kwargs):
return wrapper


class Notification(namedtuple(
"Notification",
"channel_id data headers version ttl timestamp")):
"""Parsed notification from the request"""


class PushState(object):
implements(IProducer)

Expand Down

0 comments on commit e564a97

Please sign in to comment.