'Test retrieving sun setting and rising.'

def test_setting_rising(self):

    utc_now = datetime(2016, 11, 1, 8, 0, 0, tzinfo=dt_util.UTC)
    with patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=utc_now):
        setup_component(self.hass, sun.DOMAIN, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
    self.hass.block_till_done()
    state = self.hass.states.get(sun.ENTITY_ID)
    from astral import Astral
    astral = Astral()
    utc_today = utc_now.date()
    latitude = self.hass.config.latitude
    longitude = self.hass.config.longitude
    mod = (-1)
    while True:
        next_dawn = astral.dawn_utc((utc_today + timedelta(days=mod)), latitude, longitude)
        if (next_dawn > utc_now):
            break
        mod += 1
    mod = (-1)
    while True:
        next_dusk = astral.dusk_utc((utc_today + timedelta(days=mod)), latitude, longitude)
        if (next_dusk > utc_now):
            break
        mod += 1
    mod = (-1)
    while True:
        next_midnight = astral.solar_midnight_utc((utc_today + timedelta(days=mod)), longitude)
        if (next_midnight > utc_now):
            break
        mod += 1
    mod = (-1)
    while True:
        next_noon = astral.solar_noon_utc((utc_today + timedelta(days=mod)), longitude)
        if (next_noon > utc_now):
            break
        mod += 1
    mod = (-1)
    while True:
        next_rising = astral.sunrise_utc((utc_today + timedelta(days=mod)), latitude, longitude)
        if (next_rising > utc_now):
            break
        mod += 1
    mod = (-1)
    while True:
        next_setting = astral.sunset_utc((utc_today + timedelta(days=mod)), latitude, longitude)
        if (next_setting > utc_now):
            break
        mod += 1
    self.assertEqual(next_dawn, dt_util.parse_datetime(state.attributes[sun.STATE_ATTR_NEXT_DAWN]))
    self.assertEqual(next_dusk, dt_util.parse_datetime(state.attributes[sun.STATE_ATTR_NEXT_DUSK]))
    self.assertEqual(next_midnight, dt_util.parse_datetime(state.attributes[sun.STATE_ATTR_NEXT_MIDNIGHT]))
    self.assertEqual(next_noon, dt_util.parse_datetime(state.attributes[sun.STATE_ATTR_NEXT_NOON]))
    self.assertEqual(next_rising, dt_util.parse_datetime(state.attributes[sun.STATE_ATTR_NEXT_RISING]))
    self.assertEqual(next_setting, dt_util.parse_datetime(state.attributes[sun.STATE_ATTR_NEXT_SETTING]))
