hass-core/tests/components/zodiac/test_sensor.py
Julien Tant 8b9c757fdc
Add zodiac integration (#38935)
* add zodiac sign integration

* add tests & refacto

* Apply suggestions from code review

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* fix indentation from suggested correction, fix quality scale and remove useless functions

* fix code formatting

* Create const.py

* Update sensor.py

* Update const.py

* Update test_sensor.py

* Update test_sensor.py

* Update test_sensor.py

* Update test_sensor.py

* Update test_sensor.py

* Update sensor.py

* Update test_sensor.py

* Update __init__.py

* Update sensor.py

* Update test_sensor.py

* Update sensor.py

* Update __init__.py

* Update test_sensor.py

* Update __init__.py

* Fix zodiac time patch

* Delete sensor.fr.json

* Update sensor.py

* Delete sensor.en.json

* Update test_sensor.py

* Apply suggestions from code review

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-09-21 10:41:30 -05:00

50 lines
1.4 KiB
Python

"""The test for the zodiac sensor platform."""
from datetime import datetime
import pytest
from homeassistant.components.zodiac.const import (
ATTR_ELEMENT,
ATTR_MODALITY,
DOMAIN,
ELEMENT_EARTH,
ELEMENT_FIRE,
ELEMENT_WATER,
MODALITY_CARDINAL,
MODALITY_FIXED,
SIGN_ARIES,
SIGN_SCORPIO,
SIGN_TAURUS,
)
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.async_mock import patch
DAY1 = datetime(2020, 11, 15, tzinfo=dt_util.UTC)
DAY2 = datetime(2020, 4, 20, tzinfo=dt_util.UTC)
DAY3 = datetime(2020, 4, 21, tzinfo=dt_util.UTC)
@pytest.mark.parametrize(
"now,sign,element,modality",
[
(DAY1, SIGN_SCORPIO, ELEMENT_WATER, MODALITY_FIXED),
(DAY2, SIGN_ARIES, ELEMENT_FIRE, MODALITY_CARDINAL),
(DAY3, SIGN_TAURUS, ELEMENT_EARTH, MODALITY_FIXED),
],
)
async def test_zodiac_day(hass, now, sign, element, modality):
"""Test the zodiac sensor."""
config = {DOMAIN: {}}
with patch("homeassistant.components.zodiac.sensor.utcnow", return_value=now):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("sensor.zodiac")
assert state
assert state.state == sign
assert state.attributes
assert state.attributes[ATTR_ELEMENT] == element
assert state.attributes[ATTR_MODALITY] == modality