Ejemplo n.º 1
0
 def test_update_note_template_attachments(self, app, client, fake_auth,
                                           mock_note_template):
     """Update note attachments."""
     user = AuthorizedUser.find_by_id(mock_note_template.creator_id)
     fake_auth.login(user.uid)
     base_dir = app.config['BASE_DIR']
     attachment_id = mock_note_template.attachments[0].id
     filename = 'mock_advising_note_attachment_2.txt'
     path_to_new_attachment = f'{base_dir}/fixtures/{filename}'
     updated_note = self._api_note_template_update(
         app,
         client,
         note_template_id=mock_note_template.id,
         title=mock_note_template.title,
         subject=mock_note_template.subject,
         body=mock_note_template.body,
         attachments=[path_to_new_attachment],
         delete_attachment_ids=[attachment_id],
     )
     assert mock_note_template.id == updated_note['attachments'][0][
         'noteTemplateId']
     assert len(updated_note['attachments']) == 1
     assert filename == updated_note['attachments'][0]['displayName']
     assert filename == updated_note['attachments'][0]['filename']
     assert updated_note['attachments'][0]['id'] != attachment_id
     # Verify db
     attachments = NoteTemplateAttachment.query.filter(
         and_(
             NoteTemplateAttachment.note_template_id ==
             mock_note_template.id,
             NoteTemplateAttachment.deleted_at == None,  # noqa: E711
         ), ).all()
     assert len(attachments) == 1
     assert filename in attachments[0].path_to_attachment
     assert not NoteTemplateAttachment.find_by_id(attachment_id)
Ejemplo n.º 2
0
    def test_delete_note_template_with_attachments(self, app, client,
                                                   fake_auth):
        """Delete note template that has an attachment."""
        fake_auth.login(l_s_major_advisor_uid)
        base_dir = app.config['BASE_DIR']
        note_template = _api_create_note_template(
            app,
            client,
            title='Delete me!',
            subject='I want to be free',
            attachments=[
                f'{base_dir}/fixtures/mock_advising_note_attachment_1.txt'
            ],
        )
        assert len(note_template.get('attachments')) == 1
        attachment_id = note_template.get('attachments')[0]['id']
        assert NoteTemplateAttachment.find_by_id(attachment_id)

        note_template_id = note_template['id']
        response = client.delete(
            f'/api/note_template/delete/{note_template_id}')
        assert response.status_code == 200
        assert not NoteTemplateAttachment.find_by_id(attachment_id)