def test_use_case_with_parameter_out_of_range(connected_device):
    volume_increase_in_percentage = 123456789

    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    device_transport_control_service = mock.Mock()
    volume_down_uc = VolumeDownUseCase(device_discovery_service, device_transport_control_service)

    volume_down_request = VolumeDownRequestFactory.from_dict({'volume_decrease': volume_increase_in_percentage})
    response_object = volume_down_uc.execute(volume_down_request)

    assert bool(response_object) is True
    assert connected_device.volume == 0
def test_use_case_with_maximum_volume(connected_device):
    volume_decrease_integer = 11

    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    device_transport_control_service = mock.Mock()
    volume_down_uc = VolumeDownUseCase(device_discovery_service, device_transport_control_service)

    volume_down_request = VolumeDownRequestFactory.from_dict({'volume_decrease': volume_decrease_integer})
    response_object = volume_down_uc.execute(volume_down_request)

    assert bool(response_object) is True
    assert connected_device.volume == 0
def test_use_case_with_parameter_out_of_range(connected_device):
    volume_increase_in_percentage = 123456789

    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    device_transport_control_service = mock.Mock()
    volume_down_uc = VolumeDownUseCase(device_discovery_service,
                                       device_transport_control_service)

    volume_down_request = VolumeDownRequestFactory.from_dict(
        {'volume_decrease': volume_increase_in_percentage})
    response_object = volume_down_uc.execute(volume_down_request)

    assert bool(response_object) is True
    assert connected_device.volume == 0
def test_use_case_with_maximum_volume(connected_device):
    volume_decrease_integer = 11

    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    device_transport_control_service = mock.Mock()
    volume_down_uc = VolumeDownUseCase(device_discovery_service,
                                       device_transport_control_service)

    volume_down_request = VolumeDownRequestFactory.from_dict(
        {'volume_decrease': volume_decrease_integer})
    response_object = volume_down_uc.execute(volume_down_request)

    assert bool(response_object) is True
    assert connected_device.volume == 0
def test_use_case_with_positive_percentage(connected_device):
    volume_decrease_in_percentage = 10
    initial_volume = connected_device.volume

    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    device_transport_control_service = mock.Mock()
    volume_down_uc = VolumeDownUseCase(device_discovery_service, device_transport_control_service)

    volume_down_request = VolumeDownRequestFactory.from_dict({'volume_decrease': volume_decrease_in_percentage})
    response_object = volume_down_uc.execute(volume_down_request)

    assert bool(response_object) is True
    device_transport_control_service.volume_down.assert_called_with(connected_device)
    assert connected_device.volume == initial_volume - volume_decrease_in_percentage
def test_use_case_with_positive_percentage(connected_device):
    volume_decrease_in_percentage = 10
    initial_volume = connected_device.volume

    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    device_transport_control_service = mock.Mock()
    volume_down_uc = VolumeDownUseCase(device_discovery_service,
                                       device_transport_control_service)

    volume_down_request = VolumeDownRequestFactory.from_dict(
        {'volume_decrease': volume_decrease_in_percentage})
    response_object = volume_down_uc.execute(volume_down_request)

    assert bool(response_object) is True
    device_transport_control_service.volume_down.assert_called_with(
        connected_device)
    assert connected_device.volume == initial_volume - volume_decrease_in_percentage
def test_use_case_empty_parameters(connected_device):
    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    initial_volume = connected_device.volume

    device_transport_control_service = mock.Mock()

    volume_down_uc = VolumeDownUseCase(device_discovery_service, device_transport_control_service)
    volume_down_request = VolumeDownRequestFactory.from_dict({})
    result_object = volume_down_uc.execute(volume_down_request)

    device_discovery_service.get.assert_called()
    device_transport_control_service.volume_down.assert_called()

    device_transport_control_service.volume_down.assert_called_with(connected_device)

    assert bool(result_object) is True
    assert connected_device.volume == initial_volume - VolumeDownUseCase.DEFAULT_VOLUME_DECREMENT
def test_use_case_empty_parameters(connected_device):
    device_discovery_service = mock.Mock()
    device_discovery_service.get.return_value = connected_device  # We mock the device discovery service

    initial_volume = connected_device.volume

    device_transport_control_service = mock.Mock()

    volume_down_uc = VolumeDownUseCase(device_discovery_service,
                                       device_transport_control_service)
    volume_down_request = VolumeDownRequestFactory.from_dict({})
    result_object = volume_down_uc.execute(volume_down_request)

    device_discovery_service.get.assert_called()
    device_transport_control_service.volume_down.assert_called()

    device_transport_control_service.volume_down.assert_called_with(
        connected_device)

    assert bool(result_object) is True
    assert connected_device.volume == initial_volume - VolumeDownUseCase.DEFAULT_VOLUME_DECREMENT
 def from_intent_message(cls, intentMessage):
     slots_dict = cls.extract_slots_dictionary(intentMessage)
     return VolumeDownRequestFactory.from_dict(slots_dict)
Exemple #10
0
 def from_intent_message(cls, intentMessage):
     slots_dict = cls.extract_slots_dictionary(intentMessage)
     return VolumeDownRequestFactory.from_dict(slots_dict)