def test_create_light_alarm__should_not_fail_when_api_call_returns_empty_list(self, mock_tasks, mock_light):
        mock_tasks.return_value = []
        mock_light.get_instance.return_value.LIGHT_ALARMS = []
        create_light_alarm()

        mock_light.get_instance.return_value.add_light_alarm.assert_not_called()
        mock_light.get_instance.return_value.remove_light_alarm.assert_not_called()
    def test_create_light_alarm__should_call_remove_light_on_items_missing_from_api_response(self, mock_tasks, mock_light):
        other_task = str(uuid.uuid4())
        missing_task = str(uuid.uuid4())
        pref_one = {'alarm_time': self.TIME, 'alarm_days': self.DAYS, 'alarm_light_group': self.GROUP_ID, 'task_id': self.TASK_ID, 'enabled': True, 'task_type': self.TASK_TYPE}
        pref_two = {'alarm_time': self.TIME, 'alarm_days': self.DAYS, 'alarm_light_group': self.GROUP_ID, 'task_id': other_task, 'enabled': True, 'task_type': self.TASK_TYPE}
        alarm_one = LightAlarmState(self.TASK_ID, self.TIME, self.DAYS)
        alarm_two = LightAlarmState(other_task, self.TIME, self.DAYS)
        alarm_three = LightAlarmState(missing_task, self.TIME, self.DAYS)
        mock_light.get_instance.return_value.LIGHT_ALARMS = [alarm_one, alarm_two, alarm_three]
        mock_tasks.return_value = [pref_one, pref_two]
        create_light_alarm()

        mock_light.get_instance.return_value.remove_light_alarm.assert_called_with(missing_task)
    def test_create_light_alarm__should_log_when_exception(self, mock_log, mock_tasks, mock_light):
        error = TimeoutError()
        mock_tasks.side_effect = error
        create_light_alarm()

        mock_log.error.assert_called_with(error)
    def test_create_light_alarm__should_call_add_alarm(self, mock_tasks, mock_light):
        light_pref = {'alarm_time': self.TIME, 'alarm_days': self.DAYS, 'alarm_light_group': self.GROUP_ID, 'task_id': self.TASK_ID, 'enabled': True, 'task_type': self.TASK_TYPE}
        mock_tasks.return_value = [light_pref]
        create_light_alarm()

        mock_light.get_instance.return_value.add_light_alarm.assert_called_with(self.TASK_ID, self.GROUP_ID, self.TIME, self.DAYS, self.TASK_TYPE)
    def test_create_light_alarm__should_not_call_add_replace_alarm_when_alarm_group_id_none(self, mock_tasks, mock_light):
        mock_tasks.return_value = [{'alarm_time': self.TIME, 'alarm_days': self.DAYS, 'alarm_light_group': None, 'task_id': self.TASK_ID}]
        create_light_alarm()

        mock_light.get_instance.return_value.add_light_alarm.assert_not_called()
    def test_create_light_alarm__should_not_call_add_light_alarm_when_light_tasks_are_none(self, mock_tasks, mock_light):
        mock_tasks.return_value = None
        create_light_alarm()

        mock_light.get_instance.return_value.add_light_alarm.assert_not_called()
    def test_create_light_alarm__should_make_call_to_get_light_preferences(self, mock_tasks, mock_light):
        create_light_alarm()

        mock_tasks.assert_called_with(self.USER_ID)