Ejemplo n.º 1
0
def create_recording():
    """Initializes a recording and returns its id."""

    validate.validate_form(request.form,
                           recording.form_schema['create_recording'])

    new_filename = request.form['filename']
    new_media = Multimedia(recording.config, recording.plugin_manager)
    success, filename = new_media.load_backend(None, new_filename)

    if not success:
        raise HTTPError(500, 'Could not load multimedia backend')

    filepath = new_media.plugman.get_plugin_by_name(
        new_media.config.record_to_file_plugin,
        "Output").plugin_object.location
    new_recording_id = recording.next_id
    key = str(new_recording_id)

    recording.media_dict[new_recording_id] = new_media
    recording.media_info[key] = {
        'filename': filename,
        'filepath': filepath,
        'null_multimeda': True,
    }
    recording.next_id = recording.next_id + 1
    recording.media_info.sync()

    return {'id': new_recording_id}
Ejemplo n.º 2
0
 def test_invalid_create_recording_data_structure(self, invalid_form):
     '''
     Tests validating the request form for controlling a recording with an invalid data structure
     '''
     with pytest.raises(HTTPError):
         validate.validate_form(invalid_form,
                                recording.form_schema['create_recording'])
Ejemplo n.º 3
0
def control_recording(recording_id):
    """Change the state of a recording."""

    validate.validate_form(request.form,
                           recording.form_schema['control_recording'])

    try:
        retrieved_media = recording.media_dict[recording_id]
    except KeyError:
        raise HTTPError(
            404, 'No recording with id "{}" was found'.format(recording_id))

    command = request.form['command']
    media_state = retrieved_media.current_state

    if command == 'start' and media_state in [
            Multimedia.NULL, Multimedia.PAUSE
    ]:
        retrieved_media.record()
    elif command == 'pause' and media_state == Multimedia.RECORD:
        retrieved_media.pause()
    elif command == 'stop' and media_state in [
            Multimedia.RECORD, Multimedia.PAUSE
    ]:
        retrieved_media.stop()
    else:
        raise HTTPError(400,
                        'Command "{}" could not be performed'.format(command))

    if media_state is not Multimedia.NULL:
        key = str(recording_id)
        recording.media_info[key]['null_multimeda'] = False

    return ''
Ejemplo n.º 4
0
 def test_valid_create_recording_data(self):
     '''
     Tests validating the request form for creating a recording with valid data
     '''
     form_data = {'filename': 'valid_filename'}
     validate.validate_form(form_data,
                            recording.form_schema['create_recording'])
Ejemplo n.º 5
0
 def test_valid_control_recording_data(self):
     '''
     Tests validating the request form for controlling a recording with valid data
     '''
     form_data = {'command': 'start'}
     validate.validate_form(form_data,
                            recording.form_schema['control_recording'])
Ejemplo n.º 6
0
def control_recording(recording_id):
    """Change the state of a recording."""

    validate.validate_form(request.form, recording.form_schema['control_recording'])

    try:
        retrieved_media = recording.media_dict[recording_id]
    except KeyError:
        raise HTTPError(404, 'No recording with id "{}" was found'.format(recording_id))

    command = request.form['command']
    media_state = retrieved_media.current_state

    if command == 'start' and media_state in [Multimedia.NULL, Multimedia.PAUSE]:
        retrieved_media.record()
    elif command == 'pause' and media_state == Multimedia.RECORD:
        retrieved_media.pause()
    elif command == 'stop' and media_state in [Multimedia.RECORD, Multimedia.PAUSE]:
        retrieved_media.stop()
    else:
        raise HTTPError(400, 'Command "{}" could not be performed'.format(command))

    if media_state is not Multimedia.NULL:
        key = str(recording_id)
        recording.media_info[key]['null_multimeda'] = False

    return ''
Ejemplo n.º 7
0
def create_recording():
    """Initializes a recording and returns its id."""

    validate.validate_form(request.form, recording.form_schema['create_recording'])

    new_filename = request.form['filename']
    new_media = Multimedia(recording.config, recording.plugin_manager)
    success, filename = new_media.load_backend(None, new_filename)

    if not success:
        raise HTTPError(500, 'Could not load multimedia backend')

    filepath = new_media.plugman.get_plugin_by_name(new_media.config.record_to_file_plugin, "Output").plugin_object.location
    new_recording_id = recording.next_id
    key = str(new_recording_id)

    recording.media_dict[new_recording_id] = new_media
    recording.media_info[key] = {
        'filename': filename,
        'filepath': filepath,
        'null_multimeda': True,
    }
    recording.next_id = recording.next_id + 1
    recording.media_info.sync()

    return {'id': new_recording_id}
Ejemplo n.º 8
0
 def test_invalid_create_recording_data(self, filename):
     '''
     Tests validating the request form for creating a recording with invalid data
     '''
     form_data = {'filename': filename}
     with pytest.raises(HTTPError):
         validate.validate_form(form_data, recording.form_schema['create_recording'])
Ejemplo n.º 9
0
 def test_invalid_control_recording_data(self, control):
     '''
     Tests validating the request form for controlling a recording with invalid data
     '''
     form_data = {'command': control}
     with pytest.raises(HTTPError):
         validate.validate_form(form_data, recording.form_schema['control_recording'])
Ejemplo n.º 10
0
 def test_invalid_create_recording_data(self, filename):
     '''
     Tests validating the request form for creating a recording with invalid data
     '''
     form_data = {'filename': filename}
     with pytest.raises(HTTPError):
         validate.validate_form(form_data,
                                recording.form_schema['create_recording'])
Ejemplo n.º 11
0
 def test_invalid_control_recording_data(self, control):
     '''
     Tests validating the request form for controlling a recording with invalid data
     '''
     form_data = {'command': control}
     with pytest.raises(HTTPError):
         validate.validate_form(form_data,
                                recording.form_schema['control_recording'])
Ejemplo n.º 12
0
 def test_invalid_create_recording_data_structure(self, invalid_form):
     '''
     Tests validating the request form for controlling a recording with an invalid data structure
     '''
     with pytest.raises(HTTPError):
         validate.validate_form(invalid_form, recording.form_schema['create_recording'])
Ejemplo n.º 13
0
 def test_valid_create_recording_data(self):
     '''
     Tests validating the request form for creating a recording with valid data
     '''
     form_data = {'filename': 'valid_filename'}
     validate.validate_form(form_data, recording.form_schema['create_recording'])
Ejemplo n.º 14
0
 def test_valid_control_recording_data(self):
     '''
     Tests validating the request form for controlling a recording with valid data
     '''
     form_data = {'command': 'start'}
     validate.validate_form(form_data, recording.form_schema['control_recording'])