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

Commit

Permalink
bug: Fix diagnostic cli to handle tuple args
Browse files Browse the repository at this point in the history
Also we were inconsistent about passing `current_month` when registering
`webpush` protocol entities. While not strictly an error now, it could
cause issues later if we do stricter lookups.

Closes #1096
  • Loading branch information
jrconlin committed Dec 7, 2017
1 parent 44007e4 commit 7acbcec
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion autopush/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def preflight_check(message, router, uaid="deadbeef00000000deadbeef00000000"):
# Store a router entry, fetch it, delete it
router.register_user(dict(uaid=uaid.hex, node_id=node_id,
connected_at=connected_at,
current_month=datetime.date.today().month,
router_type="webpush"))
item = router.get_uaid(uaid.hex)
assert item.get("node_id") == node_id
Expand Down Expand Up @@ -694,7 +695,7 @@ def update_last_message_read(self, uaid, timestamp):
class Router(object):
"""Create a Router table abstraction on top of a DynamoDB Table object"""
def __init__(self, table, metrics, max_ttl=MAX_EXPIRY):
# type: (Table, IMetrics) -> None
# type: (Table, IMetrics, int) -> None
"""Create a new Router object
:param table: :class:`Table` object.
Expand Down
13 changes: 7 additions & 6 deletions autopush/diagnostic_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def __init__(self, sysargs, use_files=True):
def _load_args(self, sysargs, use_files):
shared_config_files = AutopushMultiService.shared_config_files
if use_files:
config_files = shared_config_files + [ # pragma: nocover
config_files = shared_config_files + ( # pragma: nocover
'/etc/autopush_endpoint.ini',
'~/.autopush_endpoint.ini',
'.autopush_endpoint.ini'
]
)
else:
config_files = [] # pragma: nocover

Expand Down Expand Up @@ -68,10 +68,11 @@ def run(self):
self._pp.pprint(rec._data)
print("\n")

mess_table = rec["current_month"]
chans = self.db.message_tables[mess_table].all_channels(uaid)
print("Channels in message table:")
self._pp.pprint(chans)
if "current_month" in rec:
mess_table = rec["current_month"]
chans = self.db.message_tables[mess_table].all_channels(uaid)
print("Channels in message table:")
self._pp.pprint(chans)


def run_endpoint_diagnostic_cli(sysargs=None, use_files=True):
Expand Down
1 change: 1 addition & 0 deletions autopush/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def _create_minimal_record(self):
"router_type": "webupsh",
"last_connect": generate_last_connect(),
"connected_at": ms_time(),
"current_month": datetime.today().month,
}
return data

Expand Down
7 changes: 7 additions & 0 deletions autopush/tests/test_diagnostic_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ def test_successfull_lookup(self, mock_db_cstr, mock_conf_class):
"http://something/wpush/v1/legit_endpoint",
], use_files=False)
mock_message_table.all_channels.assert_called()

def test_parser_tuple(self):
from autopush.diagnostic_cli import EndpointDiagnosticCLI

edc = EndpointDiagnosticCLI(("http://someendpoint",))
assert edc is not None
assert edc._endpoint == "http://someendpoint"

0 comments on commit 7acbcec

Please sign in to comment.