Ejemplo n.º 1
0
def mock_advising_note(app, db):
    """Create advising note with attachment (mock s3)."""
    with mock_advising_note_s3_bucket(app):
        note_author_uid = '90412'
        base_dir = app.config['BASE_DIR']
        path_to_file = f'{base_dir}/fixtures/mock_advising_note_attachment_1.txt'
        with open(path_to_file, 'r') as file:
            note = Note.create(
                author_uid=note_author_uid,
                author_name='Joni Mitchell',
                author_role='Director',
                author_dept_codes=['UWASC'],
                sid='11667051',
                subject='In France they kiss on main street',
                body="""
                    My darling dime store thief, in the War of Independence
                    Rock 'n Roll rang sweet as victory, under neon signs
                """,
                attachments=[
                    {
                        'name': path_to_file.rsplit('/', 1)[-1],
                        'byte_stream': file.read(),
                    },
                ],
            )
            db.session.add(note)
            std_commit(allow_test_environment=True)
    yield note
    Note.delete(note_id=note.id)
    std_commit(allow_test_environment=True)
Ejemplo n.º 2
0
def delete_note(note_id):
    if not current_user.is_admin:
        raise ForbiddenRequestError('Sorry, you are not authorized to delete notes.')
    note = Note.find_by_id(note_id=note_id)
    if not note:
        raise ResourceNotFoundError('Note not found')
    Note.delete(note_id=note_id)
    return tolerant_jsonify({'message': f'Note {note_id} deleted'}), 200