APNs: Fix a case I broke while working out tests.

I got distracted, came back later to a successful test run in my
terminal, and thought I remembered finishing the change and just
kicking off a final test run to check.

In fact, there was an `assert False` right in the normal case for
production, and I just hadn't finished a test for that path. (m.-)
Definitely the most grateful I've been for our coverage checks,
which highlighted this for me.

Remove the `assert False`, and also finish writing the test it was
there to help me write.  Those lines are covered now.
This commit is contained in:
Greg Price 2018-02-09 18:22:26 -08:00
parent 59f61c2525
commit 8be2dfa81c
2 changed files with 6 additions and 1 deletions

View File

@ -66,7 +66,6 @@ def get_apns_client() -> APNsClient:
if settings.APNS_CERT_FILE is not None: if settings.APNS_CERT_FILE is not None:
_apns_client = APNsClient(credentials=settings.APNS_CERT_FILE, _apns_client = APNsClient(credentials=settings.APNS_CERT_FILE,
use_sandbox=settings.APNS_SANDBOX) use_sandbox=settings.APNS_SANDBOX)
assert False
_apns_client_initialized = True _apns_client_initialized = True
return _apns_client return _apns_client

View File

@ -565,6 +565,12 @@ class TestAPNs(PushNotificationTest):
apn.send_apple_push_notification( apn.send_apple_push_notification(
self.user_profile.id, devices, payload_data) self.user_profile.id, devices, payload_data)
def test_get_apns_client(self) -> None:
with self.settings(APNS_CERT_FILE='/foo.pem'), \
mock.patch('zerver.lib.push_notifications.APNsClient') as mock_client:
client = get_apns_client()
self.assertEqual(mock_client.return_value, client)
def test_not_configured(self) -> None: def test_not_configured(self) -> None:
with mock.patch('zerver.lib.push_notifications.get_apns_client') as mock_get, \ with mock.patch('zerver.lib.push_notifications.get_apns_client') as mock_get, \
mock.patch('zerver.lib.push_notifications.logging') as mock_logging: mock.patch('zerver.lib.push_notifications.logging') as mock_logging: