mirror of https://github.com/caronc/apprise
test case coverage fixed
parent
f9ae7a9592
commit
c804def0ab
|
@ -1640,6 +1640,14 @@ class NotifyMatrix(NotifyBase):
|
|||
# This is an acceptable response; we're done
|
||||
self.logger.debug(
|
||||
'Matrix Well-Known Base URI not found at %s', verify_url)
|
||||
|
||||
# Clear our keys out for fast recall later on
|
||||
self.store.set(
|
||||
self.discovery_base_key, '',
|
||||
expires=self.discovery_cache_length_sec)
|
||||
self.store.set(
|
||||
self.discovery_identity_key, '',
|
||||
expires=self.discovery_cache_length_sec)
|
||||
return ''
|
||||
|
||||
elif code != requests.codes.ok:
|
||||
|
|
|
@ -1070,6 +1070,7 @@ def test_plugin_matrix_discovery_service(mock_post, mock_get):
|
|||
response.status_code = requests.codes.ok
|
||||
obj.store.clear(
|
||||
NotifyMatrix.discovery_base_key, NotifyMatrix.discovery_identity_key)
|
||||
|
||||
# bad data
|
||||
_resp['m.homeserver'] = '!garbage!:303'
|
||||
response.content = dumps(_resp).encode('utf-8')
|
||||
|
@ -1083,6 +1084,9 @@ def test_plugin_matrix_discovery_service(mock_post, mock_get):
|
|||
assert NotifyMatrix.discovery_base_key not in obj.store
|
||||
assert NotifyMatrix.discovery_identity_key not in obj.store
|
||||
|
||||
# We fail our discovery and therefore can't send our notification
|
||||
assert obj.notify('hello world') is False
|
||||
|
||||
# bad key
|
||||
_resp['m.homeserver'] = {}
|
||||
response.content = dumps(_resp).encode('utf-8')
|
||||
|
@ -1102,6 +1106,13 @@ def test_plugin_matrix_discovery_service(mock_post, mock_get):
|
|||
assert obj.base_url == 'https://nuxref.com/base'
|
||||
assert obj.identity_url == "https://vector.im"
|
||||
|
||||
# Verify cache saved
|
||||
assert NotifyMatrix.discovery_base_key in obj.store
|
||||
assert NotifyMatrix.discovery_identity_key in obj.store
|
||||
|
||||
# Discovery passes so notifications work too
|
||||
assert obj.notify('hello world') is True
|
||||
|
||||
# bad data
|
||||
_resp['m.identity_server'] = '!garbage!:303'
|
||||
response.content = dumps(_resp).encode('utf-8')
|
||||
|
@ -1148,6 +1159,14 @@ def test_plugin_matrix_discovery_service(mock_post, mock_get):
|
|||
assert obj.base_url == 'https://example.com'
|
||||
assert obj.identity_url == 'https://example.com'
|
||||
|
||||
# Verify cache saved
|
||||
assert NotifyMatrix.discovery_base_key in obj.store
|
||||
assert NotifyMatrix.discovery_identity_key in obj.store
|
||||
|
||||
# Discovery passes so notifications work too
|
||||
response.status_code = requests.codes.ok
|
||||
assert obj.notify('hello world') is True
|
||||
|
||||
response.status_code = requests.codes.ok
|
||||
mock_get.return_value = None
|
||||
mock_get.side_effect = (response, bad_response)
|
||||
|
@ -1161,7 +1180,24 @@ def test_plugin_matrix_discovery_service(mock_post, mock_get):
|
|||
assert NotifyMatrix.discovery_base_key not in obj.store
|
||||
assert NotifyMatrix.discovery_identity_key not in obj.store
|
||||
|
||||
# Test case where ourIdentity URI fails to do it's check
|
||||
mock_get.side_effect = (response, response, bad_response)
|
||||
obj.store.clear(
|
||||
NotifyMatrix.discovery_base_key, NotifyMatrix.discovery_identity_key)
|
||||
|
||||
with pytest.raises(MatrixDiscoveryException):
|
||||
obj.base_url
|
||||
|
||||
# Verify cache is not saved
|
||||
assert NotifyMatrix.discovery_base_key not in obj.store
|
||||
assert NotifyMatrix.discovery_identity_key not in obj.store
|
||||
|
||||
# Enforce cleanup
|
||||
response.status_code = requests.codes.ok
|
||||
mock_get.return_value = response
|
||||
mock_get.side_effect = None
|
||||
mock_post.return_value = response
|
||||
mock_post.side_effect = None
|
||||
del obj
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue