diff --git a/apprise/attachment/base.py b/apprise/attachment/base.py index 4fa70806bf..9cec8ba386 100644 --- a/apprise/attachment/base.py +++ b/apprise/attachment/base.py @@ -269,25 +269,26 @@ def exists(self, retrieve_if_missing=True): cache = self.template_args['cache']['default'] \ if self.cache is None else self.cache - if self.download_path and os.path.isfile(self.download_path) \ - and cache: - - # We have enough reason to look further into our cached content - # and verify it has not expired. - if cache is True: - # return our fixed content as is; we will always cache it - return True + try: + if self.download_path and os.path.isfile(self.download_path) \ + and cache: - # Verify our cache time to determine whether we will get our - # content again. - try: - age_in_sec = time.time() - os.stat(self.download_path).st_mtime - if age_in_sec <= cache: + # We have enough reason to look further into our cached content + # and verify it has not expired. + if cache is True: + # return our fixed content as is; we will always cache it return True - except (OSError, IOError): - # The file is not present - pass + # Verify our cache time to determine whether we will get our + # content again. + age_in_sec = \ + time.time() - os.stat(self.download_path).st_mtime + if age_in_sec <= cache: + return True + + except (OSError, IOError): + # The file is not present + pass return False if not retrieve_if_missing else self.download() diff --git a/test/test_attach_file.py b/test/test_attach_file.py index 8c3697846d..f5ece72900 100644 --- a/test/test_attach_file.py +++ b/test/test_attach_file.py @@ -213,6 +213,13 @@ def test_attach_file(): aa = AppriseAttachment(location=ContentLocation.HOSTED) assert aa.add(path) is False + response = AppriseAttachment.instantiate(path) + assert len(response) > 0 + + # Test the inability to get our file size + with mock.patch('os.path.getsize', side_effect=(True, OSError)): + assert len(response) == 0 + def test_attach_file_base64(): """