mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 07:26:18 -05:00
Converting APIError to use SanicException as base.
This commit is contained in:
parent
58de8c7c5b
commit
9ee73af61d
19 changed files with 181 additions and 161 deletions
|
|
@ -5,5 +5,5 @@ from wrolpi.errors import APIError
|
|||
|
||||
class InvalidArchive(APIError):
|
||||
code = 'INVALID_ARCHIVE'
|
||||
summary = 'The archive is invalid. See server logs.'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'The archive is invalid. See server logs.'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ from wrolpi.errors import APIError
|
|||
|
||||
class NoInventories(APIError):
|
||||
code = 'NO_INVENTORIES'
|
||||
summary = 'No Inventories'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'No Inventories'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class InventoriesVersionMismatch(APIError):
|
||||
code = 'INVENTORIES_VERSION_MISMATCH'
|
||||
summary = 'Inventories version in the DB does not match the inventories config'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'Inventories version in the DB does not match the inventories config'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
|
|
|||
|
|
@ -135,4 +135,4 @@ def test_empty_import(test_client, test_session, test_directory):
|
|||
body = {'files': []}
|
||||
request, response = test_client.post('/api/map/import', content=json.dumps(body))
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
assert 'validate' in response.json['summary']
|
||||
assert 'validate' in response.json['message']
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@ from wrolpi.errors import APIError
|
|||
|
||||
class InvalidOTP(APIError):
|
||||
code = 'INVALID_OTP'
|
||||
summary = 'OTP has invalid characters'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'OTP has invalid characters'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class InvalidPlaintext(APIError):
|
||||
code = 'INVALID_PLAINTEXT'
|
||||
summary = 'Plaintext has invalid characters'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'Plaintext has invalid characters'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class InvalidCiphertext(APIError):
|
||||
code = 'INVALID_CIPHERTEXT'
|
||||
summary = 'Ciphertext has invalid characters'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'Ciphertext has invalid characters'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def test_get_video(test_client, test_session, simple_channel, video_factory):
|
|||
assert response.status_code == HTTPStatus.NOT_FOUND, response.json
|
||||
assert response.json == {'code': 'UNKNOWN_VIDEO',
|
||||
'error': 'Cannot find Video with id 10',
|
||||
'summary': 'The video could not be found.'}
|
||||
'message': 'The video could not be found.'}
|
||||
|
||||
# Get the video info we inserted
|
||||
_, response = test_client.get('/api/videos/video/1')
|
||||
|
|
@ -207,11 +207,11 @@ def test_channel_conflicts(test_client, test_session, test_directory):
|
|||
request, response = _post_channel(new_channel)
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
assert response.json == {'cause': {'code': 'CHANNEL_NAME_CONFLICT',
|
||||
'error': '',
|
||||
'summary': 'The channel name is already taken.'},
|
||||
'error': 'The channel name is already taken.',
|
||||
'message': 'The channel name is already taken.'},
|
||||
'code': 'VALIDATION_ERROR',
|
||||
'error': '',
|
||||
'summary': 'Could not validate the contents of the request'}
|
||||
'error': 'Could not validate the contents of the request',
|
||||
'message': 'Could not validate the contents of the request'}
|
||||
|
||||
# Directory was already used
|
||||
new_channel = dict(
|
||||
|
|
@ -221,11 +221,11 @@ def test_channel_conflicts(test_client, test_session, test_directory):
|
|||
request, response = _post_channel(new_channel)
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
assert response.json == {'cause': {'code': 'CHANNEL_DIRECTORY_CONFLICT',
|
||||
'error': '',
|
||||
'summary': 'The directory is already used by another channel.'},
|
||||
'error': 'The directory is already used by another channel.',
|
||||
'message': 'The directory is already used by another channel.'},
|
||||
'code': 'VALIDATION_ERROR',
|
||||
'error': '',
|
||||
'summary': 'Could not validate the contents of the request'}
|
||||
'error': 'Could not validate the contents of the request',
|
||||
'message': 'Could not validate the contents of the request'}
|
||||
|
||||
# URL is already used
|
||||
channel_directory3 = tempfile.TemporaryDirectory(dir=test_directory).name
|
||||
|
|
@ -238,11 +238,11 @@ def test_channel_conflicts(test_client, test_session, test_directory):
|
|||
request, response = _post_channel(new_channel)
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
assert response.json == {'cause': {'code': 'CHANNEL_URL_CONFLICT',
|
||||
'error': '',
|
||||
'summary': 'The URL is already used by another channel.'},
|
||||
'error': 'The URL is already used by another channel.',
|
||||
'message': 'The URL is already used by another channel.'},
|
||||
'code': 'VALIDATION_ERROR',
|
||||
'error': '',
|
||||
'summary': 'Could not validate the contents of the request'}
|
||||
'error': 'Could not validate the contents of the request',
|
||||
'message': 'Could not validate the contents of the request'}
|
||||
|
||||
|
||||
def test_channel_empty_url_doesnt_conflict(test_client, test_session, test_directory):
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ async def test_delete_channel_with_videos(test_session, test_async_client, chann
|
|||
|
||||
# Delete the Channel.
|
||||
request, response = await test_async_client.delete(f'/api/videos/channels/{channel.id}')
|
||||
assert response.status == HTTPStatus.NO_CONTENT
|
||||
assert response.status_code == HTTPStatus.NO_CONTENT
|
||||
|
||||
# Video still exists, but has no channel.
|
||||
video: Video = test_session.query(Video).one()
|
||||
|
|
@ -53,9 +53,9 @@ async def test_nested_channel_directories(test_session, test_async_client, test_
|
|||
directory=str(channel2_directory),
|
||||
)
|
||||
request, response = await test_async_client.post('/api/videos/channels', content=json.dumps(content))
|
||||
assert response.status == HTTPStatus.BAD_REQUEST
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
assert response.json['cause'] and \
|
||||
response.json['cause']['summary'] == 'The directory is already used by another channel.'
|
||||
response.json['cause']['message'] == 'The directory is already used by another channel.'
|
||||
|
||||
# Channel 3 cannot be above Channel 1's directory.
|
||||
content = dict(
|
||||
|
|
@ -63,6 +63,6 @@ async def test_nested_channel_directories(test_session, test_async_client, test_
|
|||
directory=str(test_directory),
|
||||
)
|
||||
request, response = await test_async_client.post('/api/videos/channels', content=json.dumps(content))
|
||||
assert response.status == HTTPStatus.BAD_REQUEST
|
||||
assert response.status_code == HTTPStatus.BAD_REQUEST
|
||||
assert response.json['cause'] and \
|
||||
response.json['cause']['summary'] == 'The directory is already used by another channel.'
|
||||
response.json['cause']['message'] == 'The directory is already used by another channel.'
|
||||
|
|
|
|||
|
|
@ -5,41 +5,41 @@ from wrolpi.errors import APIError
|
|||
|
||||
class UnknownVideo(APIError):
|
||||
code = 'UNKNOWN_VIDEO'
|
||||
summary = 'The video could not be found.'
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
message = 'The video could not be found.'
|
||||
status_code = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
class UnknownChannel(APIError):
|
||||
code = 'UNKNOWN_CHANNEL'
|
||||
summary = 'The channel could not be found.'
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
message = 'The channel could not be found.'
|
||||
status_code = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
class ChannelNameConflict(APIError):
|
||||
code = 'CHANNEL_NAME_CONFLICT'
|
||||
summary = 'The channel name is already taken.'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'The channel name is already taken.'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class ChannelURLConflict(APIError):
|
||||
code = 'CHANNEL_URL_CONFLICT'
|
||||
summary = 'The URL is already used by another channel.'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'The URL is already used by another channel.'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class ChannelDirectoryConflict(APIError):
|
||||
code = 'CHANNEL_DIRECTORY_CONFLICT'
|
||||
summary = 'The directory is already used by another channel.'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'The directory is already used by another channel.'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class ChannelSourceIdConflict(APIError):
|
||||
code = 'CHANNEL_SOURCE_ID_CONFLICT'
|
||||
summary = 'Search is empty, search_str must have content.'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'Search is empty, search_str must have content.'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class ChannelURLEmpty(APIError):
|
||||
code = 'CHANNEL_URL_EMPTY'
|
||||
summary = 'This channel has no URL'
|
||||
status = HTTPStatus.BAD_REQUEST
|
||||
message = 'This channel has no URL'
|
||||
status_code = HTTPStatus.BAD_REQUEST
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ async def test_download_channel(test_session, simple_channel, video_download_man
|
|||
downloads = filter(lambda i: 'watch' in i.url, downloads)
|
||||
assert {i.url for i in downloads} == \
|
||||
{'https://youtube.com/watch?v=video_2_url', 'https://youtube.com/watch?v=video_1_url'}
|
||||
assert all(i.status == 'complete' for i in downloads)
|
||||
assert all(i.status_code == 'complete' for i in downloads)
|
||||
|
||||
# A channel with `match_regex` only returns matching video URLs.
|
||||
simple_channel.match_regex = '.*(2).*'
|
||||
|
|
|
|||
|
|
@ -5,23 +5,23 @@ from wrolpi.errors import APIError
|
|||
|
||||
class UnknownZim(APIError):
|
||||
code = 'UNKNOWN_ZIM'
|
||||
summary = 'Failed to find the Zim'
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
message = 'Failed to find the Zim'
|
||||
status_code = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
class UnknownZimEntry(APIError):
|
||||
code = 'UNKNOWN_ZIM_ENTRY'
|
||||
summary = 'Failed to find the Zim entry at that path'
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
message = 'Failed to find the Zim entry at that path'
|
||||
status_code = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
class UnknownZimTagEntry(APIError):
|
||||
code = 'UNKNOWN_ZIM_TAG_ENTRY'
|
||||
summary = 'Failed to find the TagZimEntry'
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
message = 'Failed to find the TagZimEntry'
|
||||
status_code = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
class UnknownZimSubscription(APIError):
|
||||
code = 'UNKNOWN_ZIM_SUBSCRIPTION'
|
||||
summary = 'Failed to find the ZimSubscription'
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
message = 'Failed to find the ZimSubscription'
|
||||
status_code = HTTPStatus.NOT_FOUND
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue