From 9289834660e89d45205e2c9a9cfb5beb069288d7 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Mon, 13 Jan 2020 19:30:00 -0500 Subject: [PATCH] Reworked mocking of NamedTemporaryFile() (#8) --- apprise_api/api/tests/test_add.py | 4 ++-- apprise_api/api/tests/test_json_urls.py | 4 ++-- apprise_api/api/tests/test_notify.py | 4 ++-- apprise_api/api/views.py | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apprise_api/api/tests/test_add.py b/apprise_api/api/tests/test_add.py index 7490df1..33c2533 100644 --- a/apprise_api/api/tests/test_add.py +++ b/apprise_api/api/tests/test_add.py @@ -162,8 +162,8 @@ class AddTests(SimpleTestCase): ) assert response.status_code == 400 - with patch('tempfile._TemporaryFileWrapper') as mock_ntf: - mock_ntf.side_effect = OSError() + with patch('tempfile.NamedTemporaryFile') as mock_ntf: + mock_ntf.side_effect = OSError # we won't be able to write our retrieved configuration # to disk for processing; we'll get a 500 error response = self.client.post( diff --git a/apprise_api/api/tests/test_json_urls.py b/apprise_api/api/tests/test_json_urls.py index 9ce545f..21c7a12 100644 --- a/apprise_api/api/tests/test_json_urls.py +++ b/apprise_api/api/tests/test_json_urls.py @@ -126,8 +126,8 @@ class JsonUrlsTests(SimpleTestCase): # Handle case when we try to retrieve our content but we have no idea # what the format is in. Essentialy there had to have been disk # corruption here or someone meddling with the backend. - with patch('tempfile._TemporaryFileWrapper') as mock_ntf: - mock_ntf.side_effect = OSError() + with patch('tempfile.NamedTemporaryFile') as mock_ntf: + mock_ntf.side_effect = OSError # Now retrieve our JSON resonse response = self.client.get('/json/urls/{}'.format(key)) assert response.status_code == 500 diff --git a/apprise_api/api/tests/test_notify.py b/apprise_api/api/tests/test_notify.py index f7cc3e6..ced8113 100644 --- a/apprise_api/api/tests/test_notify.py +++ b/apprise_api/api/tests/test_notify.py @@ -168,8 +168,8 @@ class NotifyTests(SimpleTestCase): 'body': 'test message' } - with patch('tempfile._TemporaryFileWrapper') as mock_ntf: - mock_ntf.side_effect = OSError() + with patch('tempfile.NamedTemporaryFile') as mock_ntf: + mock_ntf.side_effect = OSError # we won't be able to write our retrieved configuration # to disk for processing; we'll get a 500 error response = self.client.post( diff --git a/apprise_api/api/views.py b/apprise_api/api/views.py index 7415b6a..b3b1a04 100644 --- a/apprise_api/api/views.py +++ b/apprise_api/api/views.py @@ -39,7 +39,7 @@ from .forms import AddByConfigForm from .forms import NotifyForm from .forms import NotifyByUrlForm -from tempfile import NamedTemporaryFile +import tempfile import apprise import json import re @@ -186,7 +186,7 @@ class AddView(View): try: # Write our file to a temporary file - with NamedTemporaryFile() as f: + with tempfile.NamedTemporaryFile() as f: # Write our content to disk f.write(content['config'].encode()) f.flush() @@ -395,7 +395,7 @@ class NotifyView(View): # so that we can read it back. In the future a change will be to # Apprise so that we can just directly write the configuration as # is to the AppriseConfig() object... but for now... - with NamedTemporaryFile() as f: + with tempfile.NamedTemporaryFile() as f: # Write our content to disk f.write(config.encode()) f.flush() @@ -569,7 +569,7 @@ class JsonUrlView(View): # so that we can read it back. In the future a change will be to # Apprise so that we can just directly write the configuration as # is to the AppriseConfig() object... but for now... - with NamedTemporaryFile() as f: + with tempfile.NamedTemporaryFile() as f: # Write our content to disk f.write(config.encode()) f.flush()