100% test coverage

This commit is contained in:
Chris Caron 2023-06-03 17:14:57 -04:00
parent ca52674969
commit 4f6219941f
4 changed files with 74 additions and 14 deletions

View File

@ -278,7 +278,7 @@ class NotifyRingCentral(NotifyBase):
self.token = validate_regex( self.token = validate_regex(
token, *self.template_tokens['token']['regex']) token, *self.template_tokens['token']['regex'])
if not self.token: if not self.token:
msg = 'An invalid RingCentral JWT Toen ' \ msg = 'An invalid RingCentral JWT Token ' \
'({}) was specified.'.format(token) '({}) was specified.'.format(token)
self.logger.warning(msg) self.logger.warning(msg)
raise TypeError(msg) raise TypeError(msg)

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# BSD 3-Clause License # BSD 3-Clause License
# #

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# BSD 3-Clause License # BSD 3-Clause License
# #

View File

@ -121,7 +121,23 @@ apprise_url_tests = (
# Invalid client secret # Invalid client secret
'instance': TypeError, 'instance': TypeError,
}), }),
('ringc://18005554321:jwt{}@client_id/secret/1555123456'.format( ('ringc://18005554321:password@client_id/secret?mode=invalid', {
# Invalid auth mode
'instance': TypeError,
}),
('ringc://18005554321:password@client_id/secret?ext=invalid', {
# Invalid extension
'instance': TypeError,
}),
('ringc://18005554321:password@client_id/secret?env=invalid', {
# Invalid Environment
'instance': TypeError,
}),
('ringc://18005554321:jwt=@client_id/secret/1555123456?mode=jwt', {
# Invalid jwt token
'instance': TypeError,
}),
('ringc://18005554321:jwt{}@client_id/secret/1555123456?mode=jwt'.format(
'c' * 60), { 'c' * 60), {
# Valid everything # Valid everything
'instance': NotifyRingCentral, 'instance': NotifyRingCentral,
@ -132,9 +148,17 @@ apprise_url_tests = (
# Our expected url(privacy=True) startswith() response: # Our expected url(privacy=True) startswith() response:
'privacy_url': 'ringc://18005554321:j...c@c...d/****/', 'privacy_url': 'ringc://18005554321:j...c@c...d/****/',
}), }),
('ringc://18005554321:jwt{}@client_id/secret'.format('c' * 60), { ('ringc://18005554321:jwt{}@client_id/secret/245/?ext=sms&env=dev'.format(
# using phone no with no target - we text ourselves in 'c' * 60), {
# this case # using phone no with no target - we text ourselves in
# this case
# Invalid pone number 245 is parsed out
'instance': NotifyRingCentral,
# Return a good response
'requests_response_text': GOOD_RESPONSE,
}),
('ringc://18005554321:password@client_id/secret', {
# Basic auth mode
'instance': NotifyRingCentral, 'instance': NotifyRingCentral,
# Return a good response # Return a good response
'requests_response_text': GOOD_RESPONSE, 'requests_response_text': GOOD_RESPONSE,
@ -146,6 +170,14 @@ apprise_url_tests = (
# use get args to acomplish the same thing # use get args to acomplish the same thing
'instance': NotifyRingCentral, 'instance': NotifyRingCentral,
}), }),
# Test 'id' argument
('ringc://_?id={}&secret={}&from={}'.format(
'a' * 8, 'b' * 16, '5' * 11), {
# Return a good response
'requests_response_text': GOOD_RESPONSE,
# use get args to acomplish the same thing
'instance': NotifyRingCentral,
}),
('ringc://_?token={}&secret={}&source={}'.format( ('ringc://_?token={}&secret={}&source={}'.format(
'a' * 8, 'b' * 16, '5' * 11), { 'a' * 8, 'b' * 16, '5' * 11), {
# Return a good response # Return a good response
@ -226,17 +258,45 @@ def test_plugin_ringc_edge_cases(mock_post):
NotifyRingCentral( NotifyRingCentral(
client_id=client_id, client_secret=" ", source=source) client_id=client_id, client_secret=" ", source=source)
# a error response with mock.patch(
response.status_code = 400 'apprise.plugins.NotifyRingCentral.NotifyRingCentral.logout',
response.content = dumps({ side_effect=OSError()):
'code': 21211, # Handle edge case where a logout fails during our objects destruction
'message': "The 'To' number +1234567 is not a valid phone number.", # We silently fail without any error
})
mock_post.return_value = response obj = NotifyRingCentral(
client_id=client_id, client_secret="valid", source=source)
# force __del__ to get called
del obj
# Prepare a good response
response = mock.Mock()
response.status_code = requests.codes.ok
response.content = dumps(GOOD_RESPONSE)
# Prepare a bad response
bad_response = mock.Mock()
bad_response.status_code = requests.codes.internal_server_error
bad_response.content = dumps(GOOD_RESPONSE)
# Initialize our object # Initialize our object
obj = NotifyRingCentral( obj = NotifyRingCentral(
client_id=client_id, client_secret=client_secret, source=source) client_id=client_id, client_secret=client_secret, source=source)
# a error response
mock_post.return_value = bad_response
# We will fail with the above error code # We will fail with the above error code
assert obj.notify('title', 'body', 'info') is False assert obj.notify('title', 'body', 'info') is False
# A good response
mock_post.return_value = response
assert obj.notify('title', 'body', 'info') is True
# this extra check skips the login step (it already happened above when we
# fixed the response code). The below goes straight to the notification
# which fails. Hence this test checks our failure in a different part of
# the code
mock_post.return_value = bad_response
assert obj.notify('title', 'body', 'info') is False