mirror of
https://github.com/caronc/apprise-api.git
synced 2025-03-04 09:31:20 +01:00
Reworked mocking of NamedTemporaryFile() (#8)
This commit is contained in:
parent
2185737911
commit
9289834660
@ -162,8 +162,8 @@ class AddTests(SimpleTestCase):
|
|||||||
)
|
)
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
||||||
with patch('tempfile._TemporaryFileWrapper') as mock_ntf:
|
with patch('tempfile.NamedTemporaryFile') as mock_ntf:
|
||||||
mock_ntf.side_effect = OSError()
|
mock_ntf.side_effect = OSError
|
||||||
# we won't be able to write our retrieved configuration
|
# we won't be able to write our retrieved configuration
|
||||||
# to disk for processing; we'll get a 500 error
|
# to disk for processing; we'll get a 500 error
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
|
@ -126,8 +126,8 @@ class JsonUrlsTests(SimpleTestCase):
|
|||||||
# Handle case when we try to retrieve our content but we have no idea
|
# 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
|
# what the format is in. Essentialy there had to have been disk
|
||||||
# corruption here or someone meddling with the backend.
|
# corruption here or someone meddling with the backend.
|
||||||
with patch('tempfile._TemporaryFileWrapper') as mock_ntf:
|
with patch('tempfile.NamedTemporaryFile') as mock_ntf:
|
||||||
mock_ntf.side_effect = OSError()
|
mock_ntf.side_effect = OSError
|
||||||
# Now retrieve our JSON resonse
|
# Now retrieve our JSON resonse
|
||||||
response = self.client.get('/json/urls/{}'.format(key))
|
response = self.client.get('/json/urls/{}'.format(key))
|
||||||
assert response.status_code == 500
|
assert response.status_code == 500
|
||||||
|
@ -168,8 +168,8 @@ class NotifyTests(SimpleTestCase):
|
|||||||
'body': 'test message'
|
'body': 'test message'
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch('tempfile._TemporaryFileWrapper') as mock_ntf:
|
with patch('tempfile.NamedTemporaryFile') as mock_ntf:
|
||||||
mock_ntf.side_effect = OSError()
|
mock_ntf.side_effect = OSError
|
||||||
# we won't be able to write our retrieved configuration
|
# we won't be able to write our retrieved configuration
|
||||||
# to disk for processing; we'll get a 500 error
|
# to disk for processing; we'll get a 500 error
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
|
@ -39,7 +39,7 @@ from .forms import AddByConfigForm
|
|||||||
from .forms import NotifyForm
|
from .forms import NotifyForm
|
||||||
from .forms import NotifyByUrlForm
|
from .forms import NotifyByUrlForm
|
||||||
|
|
||||||
from tempfile import NamedTemporaryFile
|
import tempfile
|
||||||
import apprise
|
import apprise
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
@ -186,7 +186,7 @@ class AddView(View):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Write our file to a temporary file
|
# Write our file to a temporary file
|
||||||
with NamedTemporaryFile() as f:
|
with tempfile.NamedTemporaryFile() as f:
|
||||||
# Write our content to disk
|
# Write our content to disk
|
||||||
f.write(content['config'].encode())
|
f.write(content['config'].encode())
|
||||||
f.flush()
|
f.flush()
|
||||||
@ -395,7 +395,7 @@ class NotifyView(View):
|
|||||||
# so that we can read it back. In the future a change will be to
|
# 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
|
# Apprise so that we can just directly write the configuration as
|
||||||
# is to the AppriseConfig() object... but for now...
|
# is to the AppriseConfig() object... but for now...
|
||||||
with NamedTemporaryFile() as f:
|
with tempfile.NamedTemporaryFile() as f:
|
||||||
# Write our content to disk
|
# Write our content to disk
|
||||||
f.write(config.encode())
|
f.write(config.encode())
|
||||||
f.flush()
|
f.flush()
|
||||||
@ -569,7 +569,7 @@ class JsonUrlView(View):
|
|||||||
# so that we can read it back. In the future a change will be to
|
# 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
|
# Apprise so that we can just directly write the configuration as
|
||||||
# is to the AppriseConfig() object... but for now...
|
# is to the AppriseConfig() object... but for now...
|
||||||
with NamedTemporaryFile() as f:
|
with tempfile.NamedTemporaryFile() as f:
|
||||||
# Write our content to disk
|
# Write our content to disk
|
||||||
f.write(config.encode())
|
f.write(config.encode())
|
||||||
f.flush()
|
f.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user