Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
acec2fd7
Unverified
Commit
acec2fd7
authored
1 year ago
by
epenet
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix lingering timers in mailbox tests (#90830)
parent
84f58543
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/components/mailbox/test_init.py
+20
-11
20 additions, 11 deletions
tests/components/mailbox/test_init.py
with
20 additions
and
11 deletions
tests/components/mailbox/test_init.py
+
20
−
11
View file @
acec2fd7
...
...
@@ -2,21 +2,30 @@
from
hashlib
import
sha1
from
http
import
HTTPStatus
from
aiohttp.test_utils
import
TestClient
import
pytest
from
homeassistant.bootstrap
import
async_setup_component
import
homeassistant.components.mailbox
as
mailbox
from
homeassistant.core
import
HomeAssistant
from
tests.common
import
assert_setup_component
from
tests.typing
import
ClientSessionGenerator
@pytest.fixture
def
mock_http_client
(
hass
,
hass_client
):
async
def
mock_http_client
(
hass
:
HomeAssistant
,
hass_client
:
ClientSessionGenerator
)
->
TestClient
:
"""
Start the Home Assistant HTTP component.
"""
config
=
{
mailbox
.
DOMAIN
:
{
"
platform
"
:
"
demo
"
}}
hass
.
loop
.
run_until_complete
(
async_setup_component
(
hass
,
mailbox
.
DOMAIN
,
config
))
return
hass
.
loop
.
run_until_complete
(
hass_client
())
with
assert_setup_component
(
1
,
mailbox
.
DOMAIN
):
await
async_setup_component
(
hass
,
mailbox
.
DOMAIN
,
config
)
await
hass
.
async_block_till_done
()
return
await
hass_client
()
async
def
test_get_platforms_from_mailbox
(
mock_http_client
)
->
None
:
async
def
test_get_platforms_from_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get platforms from mailbox.
"""
url
=
"
/api/mailbox/platforms
"
...
...
@@ -27,7 +36,7 @@ async def test_get_platforms_from_mailbox(mock_http_client) -> None:
assert
result
[
0
].
get
(
"
name
"
)
==
"
DemoMailbox
"
async
def
test_get_messages_from_mailbox
(
mock_http_client
)
->
None
:
async
def
test_get_messages_from_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get messages from mailbox.
"""
url
=
"
/api/mailbox/messages/DemoMailbox
"
...
...
@@ -37,7 +46,7 @@ async def test_get_messages_from_mailbox(mock_http_client) -> None:
assert
len
(
result
)
==
10
async
def
test_get_media_from_mailbox
(
mock_http_client
)
->
None
:
async
def
test_get_media_from_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get audio from mailbox.
"""
mp3sha
=
"
3f67c4ea33b37d1710f772a26dd3fb43bb159d50
"
msgtxt
=
"
Message 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
"
...
...
@@ -50,7 +59,7 @@ async def test_get_media_from_mailbox(mock_http_client) -> None:
assert
sha1
(
data
).
hexdigest
()
==
mp3sha
async
def
test_delete_from_mailbox
(
mock_http_client
)
->
None
:
async
def
test_delete_from_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get audio from mailbox.
"""
msgtxt1
=
"
Message 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
"
msgtxt2
=
"
Message 3. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
"
...
...
@@ -69,7 +78,7 @@ async def test_delete_from_mailbox(mock_http_client) -> None:
assert
len
(
result
)
==
8
async
def
test_get_messages_from_invalid_mailbox
(
mock_http_client
)
->
None
:
async
def
test_get_messages_from_invalid_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get messages from mailbox.
"""
url
=
"
/api/mailbox/messages/mailbox.invalid_mailbox
"
...
...
@@ -77,7 +86,7 @@ async def test_get_messages_from_invalid_mailbox(mock_http_client) -> None:
assert
req
.
status
==
HTTPStatus
.
NOT_FOUND
async
def
test_get_media_from_invalid_mailbox
(
mock_http_client
)
->
None
:
async
def
test_get_media_from_invalid_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get messages from mailbox.
"""
msgsha
=
"
0000000000000000000000000000000000000000
"
url
=
f
"
/api/mailbox/media/mailbox.invalid_mailbox/
{
msgsha
}
"
...
...
@@ -86,7 +95,7 @@ async def test_get_media_from_invalid_mailbox(mock_http_client) -> None:
assert
req
.
status
==
HTTPStatus
.
NOT_FOUND
async
def
test_get_media_from_invalid_msgid
(
mock_http_client
)
->
None
:
async
def
test_get_media_from_invalid_msgid
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get messages from mailbox.
"""
msgsha
=
"
0000000000000000000000000000000000000000
"
url
=
f
"
/api/mailbox/media/DemoMailbox/
{
msgsha
}
"
...
...
@@ -95,7 +104,7 @@ async def test_get_media_from_invalid_msgid(mock_http_client) -> None:
assert
req
.
status
==
HTTPStatus
.
INTERNAL_SERVER_ERROR
async
def
test_delete_from_invalid_mailbox
(
mock_http_client
)
->
None
:
async
def
test_delete_from_invalid_mailbox
(
mock_http_client
:
TestClient
)
->
None
:
"""
Get audio from mailbox.
"""
msgsha
=
"
0000000000000000000000000000000000000000
"
url
=
f
"
/api/mailbox/delete/mailbox.invalid_mailbox/
{
msgsha
}
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment