mirror of
https://github.com/home-assistant/core.git
synced 2025-08-22 11:50:05 +00:00
.devcontainer
.github
.vscode
docs
homeassistant
script
tests
auth
components
abode
adguard
air_quality
airly
alarm_control_panel
alert
alexa
almond
ambiclimate
ambient_station
androidtv
api
api_streams
apns
apprise
aprs
arcam_fmj
arlo
asuswrt
aurora
auth
automatic
automation
awair
aws
__init__.py
test_init.py
axis
bayesian
binary_sensor
blackbird
bom
broadlink
buienradar
caldav
calendar
camera
canary
cast
cert_expiry
climate
cloud
coinmarketcap
command_line
config
configurator
conversation
coolmaster
counter
cover
daikin
darksky
datadog
deconz
default_config
demo
device_automation
device_sun_light_trigger
device_tracker
dialogflow
directv
discovery
dsmr
dte_energy_bridge
duckdns
dyson
ecobee
ee_brightbox
efergy
emulated_hue
emulated_roku
esphome
everlights
facebook
facebox
fail2ban
fan
feedreader
ffmpeg
fido
file
filesize
filter
flux
folder
folder_watcher
foobot
freedns
fritzbox
frontend
generic
generic_thermostat
geo_json_events
geo_location
geo_rss_events
geofency
geonetnz_quakes
glances
google
google_assistant
google_domains
google_pubsub
google_translate
google_wifi
gpslogger
graphite
group
hangouts
hassio
hddtemp
heos
here_travel_time
history
history_graph
history_stats
homeassistant
homekit
homekit_controller
homematic
homematicip_cloud
honeywell
html5
http
huawei_lte
hue
iaqualink
ifttt
ign_sismologia
image_processing
imap_email_content
influxdb
input_boolean
input_datetime
input_number
input_select
input_text
integration
intent_script
ios
ipma
iqvia
islamic_prayer_times
izone
jewish_calendar
kira
light
linky
litejet
local_file
locative
lock
logbook
logentries
logger
logi_circle
london_air
lovelace
luftdaten
mailbox
mailgun
manual
manual_mqtt
marytts
media_player
melissa
meraki
met
mfi
mhz19
microsoft_face
microsoft_face_detect
microsoft_face_identify
min_max
minio
mobile_app
mochad
modbus
mold_indicator
monoprice
moon
mqtt
mqtt_eventstream
mqtt_json
mqtt_room
mqtt_statestream
mythicbeastsdns
namecheapdns
neato
ness_alarm
nest
nextbus
no_ip
notify
notion
nsw_fuel_station
nsw_rural_fire_service_feed
nuheat
nws
nx584
onboarding
openalpr_cloud
openalpr_local
openhardwaremonitor
opentherm_gw
openuv
owntracks
panel_custom
panel_iframe
persistent_notification
person
pi_hole
pilight
plant
plex
point
prometheus
proximity
ps4
ptvsd
push
pushbullet
python_script
qld_bushfire
qwikswitch
radarr
rainmachine
random
recorder
reddit
remember_the_milk
remote
rest
rest_command
rflink
rfxtrx
ring
rmvtransport
rss_feed_template
samsungtv
scene
script
season
sensor
seventeentrack
shell_command
shopping_list
sigfox
simplisafe
simulated
sleepiq
sma
smartthings
smhi
smtp
snips
solaredge
solarlog
soma
somfy
sonarr
sonos
soundtouch
spaceapi
spc
splunk
sql
ssdp
startca
statistics
statsd
stream
sun
switch
switcher_kis
system_health
system_log
tcp
teksavvy
tellduslive
template
threshold
time_date
timer
tod
tomato
toon
tplink
traccar
tradfri
transmission
transport_nsw
trend
tts
twentemilieu
twilio
uk_transport
unifi
unifi_direct
universal
updater
upnp
uptime
usgs_earthquakes_feed
utility_meter
uvc
vacuum
velbus
verisure
version
vesync
voicerss
vultr
wake_on_lan
water_heater
weather
webhook
weblink
webostv
websocket_api
withings
workday
worldclock
wsdot
wunderground
wwlln
xiaomi
xiaomi_miio
yamaha
yandex_transport
yandextts
yessssms
yr
yweather
zeroconf
zha
zone
zwave
__init__.py
conftest.py
fixtures
helpers
mock
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_config_entries.py
test_core.py
test_data_entry_flow.py
test_loader.py
test_main.py
test_requirements.py
test_setup.py
.codecov.yml
.coveragerc
.dockerignore
.gitattributes
.gitignore
.hound.yml
.ignore
.pre-commit-config-all.yaml
.pre-commit-config.yaml
.readthedocs.yml
.travis.yml
CLA.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.dev
LICENSE.md
MANIFEST.in
README.rst
azure-pipelines-ci.yml
azure-pipelines-release.yml
azure-pipelines-translation.yml
azure-pipelines-wheels.yml
pylintrc
pyproject.toml
requirements_all.txt
requirements_docs.txt
requirements_test.txt
requirements_test_all.txt
setup.cfg
setup.py
tox.ini
257 lines
8.3 KiB
Python
257 lines
8.3 KiB
Python
"""Tests for the aws component config and setup."""
|
|
from asynctest import patch as async_patch, MagicMock, CoroutineMock
|
|
|
|
from homeassistant.components import aws
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
class MockAioSession:
|
|
"""Mock AioSession."""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
"""Init a mock session."""
|
|
self.get_user = CoroutineMock()
|
|
self.invoke = CoroutineMock()
|
|
self.publish = CoroutineMock()
|
|
self.send_message = CoroutineMock()
|
|
|
|
def create_client(self, *args, **kwargs): # pylint: disable=no-self-use
|
|
"""Create a mocked client."""
|
|
return MagicMock(
|
|
__aenter__=CoroutineMock(
|
|
return_value=CoroutineMock(
|
|
get_user=self.get_user, # iam
|
|
invoke=self.invoke, # lambda
|
|
publish=self.publish, # sns
|
|
send_message=self.send_message, # sqs
|
|
)
|
|
),
|
|
__aexit__=CoroutineMock(),
|
|
)
|
|
|
|
|
|
async def test_empty_config(hass):
|
|
"""Test a default config will be create for empty config."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(hass, "aws", {"aws": {}})
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 1
|
|
session = sessions.get("default")
|
|
assert isinstance(session, MockAioSession)
|
|
# we don't validate auto-created default profile
|
|
session.get_user.assert_not_awaited()
|
|
|
|
|
|
async def test_empty_credential(hass):
|
|
"""Test a default config will be create for empty credential section."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(
|
|
hass,
|
|
"aws",
|
|
{
|
|
"aws": {
|
|
"notify": [
|
|
{
|
|
"service": "lambda",
|
|
"name": "New Lambda Test",
|
|
"region_name": "us-east-1",
|
|
}
|
|
]
|
|
}
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 1
|
|
session = sessions.get("default")
|
|
assert isinstance(session, MockAioSession)
|
|
|
|
assert hass.services.has_service("notify", "new_lambda_test") is True
|
|
await hass.services.async_call(
|
|
"notify", "new_lambda_test", {"message": "test", "target": "ARN"}, blocking=True
|
|
)
|
|
session.invoke.assert_awaited_once()
|
|
|
|
|
|
async def test_profile_credential(hass):
|
|
"""Test credentials with profile name."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(
|
|
hass,
|
|
"aws",
|
|
{
|
|
"aws": {
|
|
"credentials": {"name": "test", "profile_name": "test-profile"},
|
|
"notify": [
|
|
{
|
|
"service": "sns",
|
|
"credential_name": "test",
|
|
"name": "SNS Test",
|
|
"region_name": "us-east-1",
|
|
}
|
|
],
|
|
}
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 1
|
|
session = sessions.get("test")
|
|
assert isinstance(session, MockAioSession)
|
|
|
|
assert hass.services.has_service("notify", "sns_test") is True
|
|
await hass.services.async_call(
|
|
"notify",
|
|
"sns_test",
|
|
{"title": "test", "message": "test", "target": "ARN"},
|
|
blocking=True,
|
|
)
|
|
session.publish.assert_awaited_once()
|
|
|
|
|
|
async def test_access_key_credential(hass):
|
|
"""Test credentials with access key."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(
|
|
hass,
|
|
"aws",
|
|
{
|
|
"aws": {
|
|
"credentials": [
|
|
{"name": "test", "profile_name": "test-profile"},
|
|
{
|
|
"name": "key",
|
|
"aws_access_key_id": "test-key",
|
|
"aws_secret_access_key": "test-secret",
|
|
},
|
|
],
|
|
"notify": [
|
|
{
|
|
"service": "sns",
|
|
"credential_name": "key",
|
|
"name": "SNS Test",
|
|
"region_name": "us-east-1",
|
|
}
|
|
],
|
|
}
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 2
|
|
session = sessions.get("key")
|
|
assert isinstance(session, MockAioSession)
|
|
|
|
assert hass.services.has_service("notify", "sns_test") is True
|
|
await hass.services.async_call(
|
|
"notify",
|
|
"sns_test",
|
|
{"title": "test", "message": "test", "target": "ARN"},
|
|
blocking=True,
|
|
)
|
|
session.publish.assert_awaited_once()
|
|
|
|
|
|
async def test_notify_credential(hass):
|
|
"""Test notify service can use access key directly."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(
|
|
hass,
|
|
"aws",
|
|
{
|
|
"aws": {
|
|
"notify": [
|
|
{
|
|
"service": "sqs",
|
|
"credential_name": "test",
|
|
"name": "SQS Test",
|
|
"region_name": "us-east-1",
|
|
"aws_access_key_id": "some-key",
|
|
"aws_secret_access_key": "some-secret",
|
|
}
|
|
]
|
|
}
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 1
|
|
assert isinstance(sessions.get("default"), MockAioSession)
|
|
|
|
assert hass.services.has_service("notify", "sqs_test") is True
|
|
await hass.services.async_call(
|
|
"notify", "sqs_test", {"message": "test", "target": "ARN"}, blocking=True
|
|
)
|
|
|
|
|
|
async def test_notify_credential_profile(hass):
|
|
"""Test notify service can use profile directly."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(
|
|
hass,
|
|
"aws",
|
|
{
|
|
"aws": {
|
|
"notify": [
|
|
{
|
|
"service": "sqs",
|
|
"name": "SQS Test",
|
|
"region_name": "us-east-1",
|
|
"profile_name": "test",
|
|
}
|
|
]
|
|
}
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 1
|
|
assert isinstance(sessions.get("default"), MockAioSession)
|
|
|
|
assert hass.services.has_service("notify", "sqs_test") is True
|
|
await hass.services.async_call(
|
|
"notify", "sqs_test", {"message": "test", "target": "ARN"}, blocking=True
|
|
)
|
|
|
|
|
|
async def test_credential_skip_validate(hass):
|
|
"""Test credential can skip validate."""
|
|
with async_patch("aiobotocore.AioSession", new=MockAioSession):
|
|
await async_setup_component(
|
|
hass,
|
|
"aws",
|
|
{
|
|
"aws": {
|
|
"credentials": [
|
|
{
|
|
"name": "key",
|
|
"aws_access_key_id": "not-valid",
|
|
"aws_secret_access_key": "dont-care",
|
|
"validate": False,
|
|
}
|
|
]
|
|
}
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
sessions = hass.data[aws.DATA_SESSIONS]
|
|
assert sessions is not None
|
|
assert len(sessions) == 1
|
|
session = sessions.get("key")
|
|
assert isinstance(session, MockAioSession)
|
|
session.get_user.assert_not_awaited()
|