def from_dict(cls, a_dictionary):
        invalid_request = InvalidRequestObject()

        if invalid_request.has_errors():
            return invalid_request

        return cls()
def test_invalid_request_object_accepts_errors():
    invalid_request_object = InvalidRequestObject()

    invalid_request_object.add_error('param1', 'value1')
    invalid_request_object.add_error('param2', 'value2')
    assert bool(invalid_request_object) is False
    assert invalid_request_object.has_errors() is True
    assert len(invalid_request_object.errors) == 2
示例#3
0
def test_use_case_can_process_invalid_requests_and_returns_response_failure():
    invalid_request_object = InvalidRequestObject()
    invalid_request_object.add_error('param', 'value')

    use_case = UseCase()
    response = use_case.execute(invalid_request_object)

    assert not response
    assert response.type == ResponseFailure.PARAMETERS_ERROR
    def from_dict(cls, a_dictionary):
        invalid_request = InvalidRequestObject()

        if not ('playlist_name' in a_dictionary):
            invalid_request.add_error('playlist_name', 'is missing')

        if invalid_request.has_errors():
            return invalid_request

        return cls(playlist_name=a_dictionary.get('playlist_name', None))
    def from_dict(cls, a_dictionary):
        invalid_request = InvalidRequestObject()

        if invalid_request.has_errors():
            return invalid_request

        return cls(
            track_name=a_dictionary.get('track_name', None),
            artist_name=a_dictionary.get('artist_name', None),
            album_name=a_dictionary.get('album_name', None),
            playlist_name=a_dictionary.get('playlist_name', None),
        )
    def from_dict(cls, a_dictionary):
        invalid_request = InvalidRequestObject()

        if 'volume_increase' in a_dictionary and not isinstance(
                a_dictionary['volume_increase'], int):
            invalid_request.add_error('volume_increase', 'must be an integer')

        if 'volume_increase' in a_dictionary and isinstance(
                a_dictionary['volume_increase'],
                int) and a_dictionary['volume_increase'] < 0:
            invalid_request.add_error('volume_increase', 'must be positive')

        if 'volume_increase' in a_dictionary and isinstance(
                a_dictionary['volume_increase'],
                int) and a_dictionary['volume_increase'] > 100:
            invalid_request.add_error('volume_increase',
                                      'must be lower than 100')

        if invalid_request.has_errors():
            return invalid_request

        return cls(volume_increase=a_dictionary.get('volume_increase', None))
def test_invalid_request_object_is_false():
    invalid_request_object = InvalidRequestObject()
    assert bool(invalid_request_object) is False