Beispiel #1
0
 def test_stream_attachment_handles_file_not_in_s3(self, app, fake_auth,
                                                   caplog):
     with mock_legacy_note_attachment(app):
         fake_auth.login(coe_advisor)
         assert get_legacy_attachment_stream(
             '11667051_00001_1.pdf')['stream'] is None
         assert "the s3 key 'sis-attachment-path/11667051/11667051_00001_1.pdf' does not exist, or is forbidden" in caplog.text
Beispiel #2
0
 def test_stream_attachment(self, app, fake_auth):
     with mock_legacy_note_attachment(app):
         fake_auth.login(coe_advisor)
         stream = get_legacy_attachment_stream(
             '9000000000_00002_1.pdf')['stream']
         body = b''
         for chunk in stream:
             body += chunk
         assert body == b'When in the course of human events, it becomes necessarf arf woof woof woof'
Beispiel #3
0
def download_attachment(attachment_id):
    is_legacy = not is_int(attachment_id)
    id_ = attachment_id if is_legacy else int(attachment_id)
    stream_data = get_legacy_attachment_stream(id_) if is_legacy else get_boa_attachment_stream(id_)
    if not stream_data or not stream_data['stream']:
        return Response('Sorry, attachment not available.', mimetype='text/html', status=404)
    r = Response(stream_data['stream'])
    r.headers['Content-Type'] = 'application/octet-stream'
    encoding_safe_filename = urllib.parse.quote(stream_data['filename'].encode('utf8'))
    r.headers['Content-Disposition'] = f"attachment; filename*=UTF-8''{encoding_safe_filename}"
    return r
Beispiel #4
0
 def test_stream_attachment_handles_file_not_in_database(
         self, app, fake_auth, caplog):
     with mock_legacy_note_attachment(app):
         fake_auth.login(coe_advisor)
         assert get_legacy_attachment_stream('11667051_00002_1.pdf') is None
Beispiel #5
0
 def test_stream_attachment_handles_malformed_filename(self, app):
     with mock_legacy_note_attachment(app):
         assert get_legacy_attachment_stream('h0ax.lol') is None