Fixing test client depreciation warning.

This commit is contained in:
Roland 2021-12-21 20:39:55 -07:00
parent 51bcc323af
commit 1c85a2b74b
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
4 changed files with 25 additions and 25 deletions

View file

@ -58,7 +58,7 @@ class TestVideoAPI(TestAPI):
assert response.status_code == HTTPStatus.NOT_FOUND, f'Channel exists: {response.json}'
# Create it
request, response = api_app.test_client.post('/api/videos/channels', data=json.dumps(new_channel))
request, response = api_app.test_client.post('/api/videos/channels', content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.CREATED
location = response.headers['Location']
request, response = api_app.test_client.get(location)
@ -75,13 +75,13 @@ class TestVideoAPI(TestAPI):
assert new_channel['link']
# Can't create it again
request, response = api_app.test_client.post('/api/videos/channels', data=json.dumps(new_channel))
request, response = api_app.test_client.post('/api/videos/channels', content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.BAD_REQUEST
# Update it
new_channel['name'] = 'Example Channel 2'
new_channel['directory'] = str(new_channel['directory'])
request, response = api_app.test_client.put(location, data=json.dumps(new_channel))
request, response = api_app.test_client.put(location, content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.NO_CONTENT, response.status_code
request, response = api_app.test_client.get(location)
assert response.status_code == HTTPStatus.OK
@ -95,7 +95,7 @@ class TestVideoAPI(TestAPI):
# Patch it
patch = {'name': 'new name'}
request, response = api_app.test_client.patch(location, data=json.dumps(patch))
request, response = api_app.test_client.patch(location, content=json.dumps(patch))
assert response.status_code == HTTPStatus.NO_CONTENT, response.status_code
request, response = api_app.test_client.get(location)
assert response.status_code == HTTPStatus.OK
@ -109,7 +109,7 @@ class TestVideoAPI(TestAPI):
# Can't update channel that doesn't exist
request, response = api_app.test_client.put('/api/videos/channels/doesnt_exist',
data=json.dumps(new_channel))
content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.NOT_FOUND
# Delete the new channel
@ -134,7 +134,7 @@ class TestVideoAPI(TestAPI):
)
def _post_channel(channel):
return api_app.test_client.post('/api/videos/channels', data=json.dumps(channel))
return api_app.test_client.post('/api/videos/channels', content=json.dumps(channel))
# Create it
request, response = _post_channel(new_channel)
@ -199,7 +199,7 @@ class TestVideoAPI(TestAPI):
'name': 'Fooz',
'directory': channel_directory,
}
request, response = api_app.test_client.post('/api/videos/channels', data=json.dumps(new_channel))
request, response = api_app.test_client.post('/api/videos/channels', content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.CREATED, response.json
location = response.headers['Location']
@ -209,7 +209,7 @@ class TestVideoAPI(TestAPI):
'name': 'Barz',
'directory': channel_directory2,
}
request, response = api_app.test_client.post('/api/videos/channels', data=json.dumps(new_channel))
request, response = api_app.test_client.post('/api/videos/channels', content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.CREATED, response.json
assert location != response.headers['Location']
@ -362,7 +362,7 @@ class TestVideoAPI(TestAPI):
# Channels don't have videos yet
d = dict(channel_link=channel1.link)
request, response = api_app.test_client.post(f'/api/videos/search', data=json.dumps(d))
request, response = api_app.test_client.post(f'/api/videos/search', content=json.dumps(d))
assert response.status_code == HTTPStatus.OK
assert len(response.json['videos']) == 0
@ -373,14 +373,14 @@ class TestVideoAPI(TestAPI):
session.add(vid2)
# Videos are gotten by their respective channels
request, response = api_app.test_client.post(f'/api/videos/search', data=json.dumps(d))
request, response = api_app.test_client.post(f'/api/videos/search', content=json.dumps(d))
assert response.status_code == HTTPStatus.OK
assert len(response.json['videos']) == 1
assert response.json['totals']['videos'] == 1
self.assertDictContains(response.json['videos'][0], dict(id=2, title='vid2', channel_id=channel1.id))
d = dict(channel_link=channel2.link)
request, response = api_app.test_client.post(f'/api/videos/search', data=json.dumps(d))
request, response = api_app.test_client.post(f'/api/videos/search', content=json.dumps(d))
assert response.status_code == HTTPStatus.OK
assert len(response.json['videos']) == 1
self.assertDictContains(response.json['videos'][0], dict(id=1, title='vid1', channel_id=channel2.id))
@ -446,7 +446,7 @@ class TestVideoAPI(TestAPI):
last_ids = []
for offset, video_count in tests:
d = dict(channel_link=channel1.link, order_by='id', offset=offset)
_, response = api_app.test_client.post(f'/api/videos/search', data=json.dumps(d))
_, response = api_app.test_client.post(f'/api/videos/search', content=json.dumps(d))
assert response.status_code == HTTPStatus.OK
assert len(response.json['videos']) == video_count
current_ids = [i['id'] for i in response.json['videos']]
@ -472,7 +472,7 @@ class TestVideoAPI(TestAPI):
def do_search(search_str, limit=20):
d = json.dumps({'search_str': search_str, 'limit': limit})
_, resp = api_app.test_client.post('/api/videos/search', data=d)
_, resp = api_app.test_client.post('/api/videos/search', content=d)
return resp
def search_is_as_expected(resp, expected):
@ -528,7 +528,7 @@ class TestVideoAPI(TestAPI):
)
# Create the Channel
request, response = api_app.test_client.post('/api/videos/channels', data=json.dumps(new_channel))
request, response = api_app.test_client.post('/api/videos/channels', content=json.dumps(new_channel))
assert response.status_code == HTTPStatus.CREATED
location = response.headers['Location']
@ -551,7 +551,7 @@ class TestVideoAPI(TestAPI):
download_frequency=10,
)
request, response = api_app.test_client.put(f'/api/videos/channels/{channel["link"]}',
data=json.dumps(new_channel))
content=json.dumps(new_channel))
self.assertEqual(response.status_code, 204, response.json)
# Remove the frequency.
@ -562,7 +562,7 @@ class TestVideoAPI(TestAPI):
download_frequency=None,
)
request, response = api_app.test_client.put(f'/api/videos/channels/{channel["link"]}',
data=json.dumps(new_channel))
content=json.dumps(new_channel))
self.assertEqual(response.status_code, 204, response.json)

View file

@ -305,7 +305,7 @@ def get_matching_directories(path: Union[str, Path]) -> List[str]:
}
if os.path.isdir(path):
# The provided path is a directory, return it's subdirectories, or itself if no subdirectories exist
# The provided path is a directory, return its subdirectories, or itself if no subdirectories exist
paths = [os.path.join(path, i) for i in os.listdir(path)]
paths = sorted(i for i in paths if os.path.isdir(i) and i not in ignored_directories)
if len(paths) == 0:

View file

@ -87,11 +87,11 @@ class TestVideoFunctions(TestAPI):
with mock.patch('wrolpi.common.wrol_mode_enabled', lambda: True):
# Can't create, update, or delete a channel.
_, resp = api_app.test_client.post('/api/videos/channels', data=channel)
_, resp = api_app.test_client.post('/api/videos/channels', content=channel)
self.assertError(resp, HTTPStatus.FORBIDDEN, API_ERRORS[WROLModeEnabled]['code'])
_, resp = api_app.test_client.put('/api/videos/channels/channel1', data=channel)
_, resp = api_app.test_client.put('/api/videos/channels/channel1', content=channel)
self.assertError(resp, HTTPStatus.FORBIDDEN, API_ERRORS[WROLModeEnabled]['code'])
_, resp = api_app.test_client.patch('/api/videos/channels/channel1', data=channel)
_, resp = api_app.test_client.patch('/api/videos/channels/channel1', content=channel)
self.assertError(resp, HTTPStatus.FORBIDDEN, API_ERRORS[WROLModeEnabled]['code'])
_, resp = api_app.test_client.delete('/api/videos/channels/channel1')
self.assertError(resp, HTTPStatus.FORBIDDEN, API_ERRORS[WROLModeEnabled]['code'])
@ -107,7 +107,7 @@ class TestVideoFunctions(TestAPI):
self.assertError(resp, HTTPStatus.FORBIDDEN, API_ERRORS[WROLModeEnabled]['code'])
# THE REST OF THESE METHODS ARE ALLOWED
_, resp = api_app.test_client.post('/api/videos/favorite', data=favorite)
_, resp = api_app.test_client.post('/api/videos/favorite', content=favorite)
self.assertEqual(resp.status_code, HTTPStatus.OK)
@wrap_test_db

View file

@ -31,7 +31,7 @@ class TestRootAPI(TestAPI):
assert response.json['args'] == {'hello': ['world']}
data = {'foo': 'bar'}
request, response = api_app.test_client.post('/api/echo', data=json.dumps(data))
request, response = api_app.test_client.post('/api/echo', content=json.dumps(data))
assert response.status_code == HTTPStatus.OK
self.assertDictContains(response.json['form'], {})
assert response.json['method'] == 'POST', 'Method was not POST'
@ -43,17 +43,17 @@ class TestRootAPI(TestAPI):
The endpoint should only return valid if the regex is valid.
"""
data = {'regex': 'foo'}
request, response = api_app.test_client.post('/api/valid_regex', data=json.dumps(data))
request, response = api_app.test_client.post('/api/valid_regex', content=json.dumps(data))
assert response.status_code == HTTPStatus.OK
assert json.loads(response.body) == {'valid': True, 'regex': 'foo'}
data = {'regex': '.*(title match).*'}
request, response = api_app.test_client.post('/api/valid_regex', data=json.dumps(data))
request, response = api_app.test_client.post('/api/valid_regex', content=json.dumps(data))
assert response.status_code == HTTPStatus.OK
assert json.loads(response.body) == {'valid': True, 'regex': '.*(title match).*'}
data = {'regex': '.*(missing parenthesis.*'}
request, response = api_app.test_client.post('/api/valid_regex', data=json.dumps(data))
request, response = api_app.test_client.post('/api/valid_regex', content=json.dumps(data))
assert response.status_code == HTTPStatus.BAD_REQUEST
assert json.loads(response.body) == {'valid': False, 'regex': '.*(missing parenthesis.*'}