Remove I/O in Plex tests (#53196)

This commit is contained in:
jjlawren 2021-07-19 11:50:04 -05:00 committed by GitHub
parent dd8ec04e58
commit 225732d00e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -624,7 +624,9 @@ async def test_manual_config(hass, mock_plex_calls, current_request_with_host):
assert result["data"][PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN assert result["data"][PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN
async def test_manual_config_with_token(hass, mock_plex_calls): async def test_manual_config_with_token(
hass, mock_plex_calls, requests_mock, empty_library, empty_payload
):
"""Test creating via manual configuration with only token.""" """Test creating via manual configuration with only token."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -653,13 +655,19 @@ async def test_manual_config_with_token(hass, mock_plex_calls):
server_id = result["data"][CONF_SERVER_IDENTIFIER] server_id = result["data"][CONF_SERVER_IDENTIFIER]
mock_plex_server = hass.data[DOMAIN][SERVERS][server_id] mock_plex_server = hass.data[DOMAIN][SERVERS][server_id]
mock_url = mock_plex_server.url_in_use
assert result["title"] == mock_plex_server.url_in_use assert result["title"] == mock_url
assert result["data"][CONF_SERVER] == mock_plex_server.friendly_name assert result["data"][CONF_SERVER] == mock_plex_server.friendly_name
assert result["data"][CONF_SERVER_IDENTIFIER] == mock_plex_server.machine_identifier assert result["data"][CONF_SERVER_IDENTIFIER] == mock_plex_server.machine_identifier
assert result["data"][PLEX_SERVER_CONFIG][CONF_URL] == mock_plex_server.url_in_use assert result["data"][PLEX_SERVER_CONFIG][CONF_URL] == mock_url
assert result["data"][PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN assert result["data"][PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN
# Complete Plex integration setup before teardown
requests_mock.get(f"{mock_url}/library", text=empty_library)
requests_mock.get(f"{mock_url}/library/sections", text=empty_payload)
await hass.async_block_till_done()
async def test_setup_with_limited_credentials(hass, entry, setup_plex_server): async def test_setup_with_limited_credentials(hass, entry, setup_plex_server):
"""Test setup with a user with limited permissions.""" """Test setup with a user with limited permissions."""

View File

@ -177,6 +177,7 @@ async def test_setup_with_unknown_session(hass, entry, setup_plex_server):
async def test_setup_when_certificate_changed( async def test_setup_when_certificate_changed(
hass, hass,
requests_mock, requests_mock,
empty_library,
empty_payload, empty_payload,
plex_server_accounts, plex_server_accounts,
plex_server_default, plex_server_default,
@ -210,13 +211,10 @@ async def test_setup_when_certificate_changed(
requests_mock.get("https://plex.tv/api/users/", text=plextv_shared_users) requests_mock.get("https://plex.tv/api/users/", text=plextv_shared_users)
requests_mock.get("https://plex.tv/api/invites/requested", text=empty_payload) requests_mock.get("https://plex.tv/api/invites/requested", text=empty_payload)
requests_mock.get("https://plex.tv/users/account", text=plextv_account)
requests_mock.get("https://plex.tv/api/resources", text=plextv_resources)
requests_mock.get(old_url, exc=WrongCertHostnameException) requests_mock.get(old_url, exc=WrongCertHostnameException)
# Test with account failure # Test with account failure
requests_mock.get(f"{old_url}/accounts", status_code=401) requests_mock.get("https://plex.tv/users/account", status_code=401)
old_entry.add_to_hass(hass) old_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(old_entry.entry_id) is False assert await hass.config_entries.async_setup(old_entry.entry_id) is False
await hass.async_block_till_done() await hass.async_block_till_done()
@ -225,7 +223,7 @@ async def test_setup_when_certificate_changed(
await hass.config_entries.async_unload(old_entry.entry_id) await hass.config_entries.async_unload(old_entry.entry_id)
# Test with no servers found # Test with no servers found
requests_mock.get(f"{old_url}/accounts", text=plex_server_accounts) requests_mock.get("https://plex.tv/users/account", text=plextv_account)
requests_mock.get("https://plex.tv/api/resources", text=empty_payload) requests_mock.get("https://plex.tv/api/resources", text=empty_payload)
assert await hass.config_entries.async_setup(old_entry.entry_id) is False assert await hass.config_entries.async_setup(old_entry.entry_id) is False
@ -237,8 +235,11 @@ async def test_setup_when_certificate_changed(
# Test with success # Test with success
new_url = PLEX_DIRECT_URL new_url = PLEX_DIRECT_URL
requests_mock.get("https://plex.tv/api/resources", text=plextv_resources) requests_mock.get("https://plex.tv/api/resources", text=plextv_resources)
requests_mock.get(new_url, text=plex_server_default) for resource_url in [new_url, "http://1.2.3.4:32400"]:
requests_mock.get(resource_url, text=plex_server_default)
requests_mock.get(f"{new_url}/accounts", text=plex_server_accounts) requests_mock.get(f"{new_url}/accounts", text=plex_server_accounts)
requests_mock.get(f"{new_url}/library", text=empty_library)
requests_mock.get(f"{new_url}/library/sections", text=empty_payload)
assert await hass.config_entries.async_setup(old_entry.entry_id) assert await hass.config_entries.async_setup(old_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()