コード例 #1
0
def mock_note_template(app, db):
    """Create advising note template with attachment (mock s3)."""
    with mock_advising_note_s3_bucket(app):
        base_dir = app.config['BASE_DIR']
        path_to_file = f'{base_dir}/fixtures/mock_note_template_attachment_1.txt'
        timestamp = datetime.now().timestamp()
        with open(path_to_file, 'r') as file:
            note_template = NoteTemplate.create(
                creator_id=AuthorizedUser.get_id_per_uid('242881'),
                title=f'Potholes in my lawn ({timestamp})',
                subject=
                f'It\'s unwise to leave my garden untended ({timestamp})',
                body=f"""
                    See, I've found that everyone's sayin'
                    What to do when suckers are preyin'
                """,
                topics=['Three Feet High', 'Rising'],
                attachments=[
                    {
                        'name': path_to_file.rsplit('/', 1)[-1],
                        'byte_stream': file.read(),
                    },
                ],
            )
            std_commit(allow_test_environment=True)
            return note_template
コード例 #2
0
def _api_batch_note_create(
        app,
        client,
        author_id,
        subject,
        body,
        sids=None,
        cohort_ids=None,
        curated_group_ids=None,
        topics=(),
        attachments=(),
        template_attachment_ids=(),
        expected_status_code=200,
):
    with mock_advising_note_s3_bucket(app):
        data = {
            'authorId': author_id,
            'isBatchMode': sids and len(sids) > 1,
            'sids': sids or [],
            'cohortIds': cohort_ids or [],
            'curatedGroupIds': curated_group_ids or [],
            'subject': subject,
            'body': body,
            'templateAttachmentIds': template_attachment_ids or [],
            'topics': ','.join(topics),
        }
        for index, path in enumerate(attachments):
            data[f'attachment[{index}]'] = open(path, 'rb')
        response = client.post(
            '/api/notes/create',
            buffered=True,
            content_type='multipart/form-data',
            data=data,
        )
        assert response.status_code == expected_status_code
コード例 #3
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)
コード例 #4
0
 def _api_note_update(
         cls,
         app,
         client,
         note_id,
         subject,
         body,
         topics=(),
         expected_status_code=200,
 ):
     with mock_advising_note_s3_bucket(app):
         data = {
             'id': note_id,
             'subject': subject,
             'body': body,
             'topics': ','.join(topics),
         }
         response = client.post(
             '/api/notes/update',
             buffered=True,
             content_type='multipart/form-data',
             data=data,
         )
         assert response.status_code == expected_status_code
         return response.json
コード例 #5
0
def _api_note_create(
        app,
        client,
        author_id,
        sids,
        subject,
        body,
        topics=(),
        attachments=(),
        template_attachment_ids=(),
        expected_status_code=200,
):
    with mock_advising_note_s3_bucket(app):
        data = {
            'authorId': author_id,
            'sids': sids,
            'subject': subject,
            'body': body,
            'topics': ','.join(topics),
            'templateAttachmentIds': ','.join(str(_id) for _id in template_attachment_ids),
        }
        for index, path in enumerate(attachments):
            data[f'attachment[{index}]'] = open(path, 'rb')
        response = client.post(
            '/api/notes/create',
            buffered=True,
            content_type='multipart/form-data',
            data=data,
        )
        assert response.status_code == expected_status_code
        return response.json
コード例 #6
0
 def test_add_attachments(self, app, client, fake_auth):
     """Add multiple attachments to an existing note."""
     fake_auth.login(coe_advisor_uid)
     base_dir = app.config['BASE_DIR']
     note = _api_note_create(
         app,
         client,
         author_id=AuthorizedUser.get_id_per_uid(coe_advisor_uid),
         sids=[coe_student['sid']],
         subject='No attachments yet',
         body='I travel light',
     )
     assert note['updatedAt'] is None
     # Pause one second to ensure a distinct updatedAt.
     sleep(1)
     note_id = note['id']
     with mock_advising_note_s3_bucket(app):
         data = {
             'attachment[0]': open(f'{base_dir}/fixtures/mock_advising_note_attachment_1.txt', 'rb'),
             'attachment[1]': open(f'{base_dir}/fixtures/mock_advising_note_attachment_2.txt', 'rb'),
         }
         response = client.post(
             f'/api/notes/{note_id}/attachments',
             buffered=True,
             content_type='multipart/form-data',
             data=data,
         )
     assert response.status_code == 200
     updated_note = response.json
     assert len(updated_note['attachments']) == 2
     assert updated_note['attachments'][0]['filename'] == 'mock_advising_note_attachment_1.txt'
     assert updated_note['attachments'][1]['filename'] == 'mock_advising_note_attachment_2.txt'
     assert updated_note['updatedAt'] is not None
コード例 #7
0
def _api_create_note_template(
        app,
        client,
        title,
        subject,
        body=None,
        topics=(),
        attachments=(),
        expected_status_code=200,
):
    with mock_advising_note_s3_bucket(app):
        data = {
            'title': title,
            'subject': subject,
            'body': body,
            'topics': ','.join(topics),
        }
        for index, path in enumerate(attachments):
            data[f'attachment[{index}]'] = open(path, 'rb')
        response = client.post(
            '/api/note_template/create',
            buffered=True,
            content_type='multipart/form-data',
            data=data,
        )
        assert response.status_code == expected_status_code
        return response.json
コード例 #8
0
 def _api_note_update(
         cls,
         app,
         client,
         note_id,
         subject,
         body,
         topics=(),
         attachments=(),
         delete_attachment_ids=(),
         expected_status_code=200,
 ):
     with mock_advising_note_s3_bucket(app):
         data = {
             'id': note_id,
             'subject': subject,
             'body': body,
             'topics': ','.join(topics),
             'deleteAttachmentIds': delete_attachment_ids or [],
         }
         for index, path in enumerate(attachments):
             data[f'attachment[{index}]'] = open(path, 'rb')
         response = client.post(
             '/api/notes/update',
             buffered=True,
             content_type='multipart/form-data',
             data=data,
         )
         assert response.status_code == expected_status_code
         return response.json
コード例 #9
0
    def test_user_without_advising_data_access(self, app, client, fake_auth):
        """Denies access to a user who cannot access notes and appointments."""
        fake_auth.login(coe_advisor_no_advising_data_uid)
        delete_response = client.delete('/api/notes/1/attachment/1')
        assert delete_response.status_code == 401

        with mock_advising_note_s3_bucket(app):
            base_dir = app.config['BASE_DIR']
            data = {'attachment[0]': open(f'{base_dir}/fixtures/mock_advising_note_attachment_1.txt', 'rb')}
            response = client.post(
                '/api/notes/1/attachments',
                buffered=True,
                content_type='multipart/form-data',
                data=data,
            )
        assert response.status_code == 401
コード例 #10
0
def mock_private_advising_note(app):
    with mock_advising_note_s3_bucket(app):
        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:
            return Note.create(
                attachments=[{
                    'name': path_to_file.rsplit('/', 1)[-1],
                    'byte_stream': file.read()
                }],
                author_uid=ce3_advisor_uid,
                author_name='Kate Pierson',
                author_role='Advisor',
                author_dept_codes=['ZCEEE'],
                body='Underground like a wild potato.',
                is_private=True,
                sid=coe_student['sid'],
                subject='You\'re living in your own Private Idaho.',
            )