Esempio n. 1
0
 def test_stream_attachment_reports_missing_files_not_found(
         self, app, client, fake_auth):
     with mock_legacy_note_attachment(app):
         fake_auth.login(asc_advisor_uid)
         response = client.get('/api/notes/attachment/h0ax.lol')
         assert response.status_code == 404
         assert response.data == b'Sorry, attachment not available.'
Esempio n. 2
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
Esempio n. 3
0
    def test_stream_zipped_bundle(self, app):
        with mock_legacy_note_attachment(app):
            sid = '9000000000'
            filename = 'advising_notes'
            stream = get_zip_stream(
                filename=filename,
                notes=get_advising_notes(sid),
                student={
                    'first_name': 'Wolfgang',
                    'last_name': 'Pauli-O\'Rourke',
                    'sid': sid,
                },
            )
            body = b''
            for chunk in stream:
                body += chunk
            zipfile = ZipFile(io.BytesIO(body), 'r')
            contents = {}
            for name in zipfile.namelist():
                contents[name] = zipfile.read(name)

            assert len(contents) == 2
            assert contents['dog_eaten_homework.pdf'] == b'When in the course of human events, it becomes necessarf arf woof woof woof'
            csv_rows = contents[f'{filename}.csv'].decode('utf-8').strip().split('\r\n')
            assert len(csv_rows) == 4
            assert csv_rows[0] == 'date_created,student_sid,student_name,author_uid,author_csid,author_name,subject,' \
                                  'topics,attachments,body,is_private,late_change_request_action,' \
                                  'late_change_request_status,late_change_request_term,late_change_request_course'
            assert csv_rows[1] == '2017-11-02,9000000000,Wolfgang Pauli-O\'Rourke,,700600500,,,,' \
                                  'dog_eaten_homework.pdf,I am confounded by this confounding student,False,,,,'
            assert csv_rows[2] == "2017-11-02,9000000000,Wolfgang Pauli-O'Rourke,,600500400,,,Ne Scéaw,," \
                                  'Is this student even on campus?,False,,,,'
            assert csv_rows[3] == "2020-12-05,9000000000,Wolfgang Pauli-O'Rourke,,,,,,,," \
                                  'False,Late Grading Basis Change,In Error,Fall 2020,' \
                                  '24460 PSYCH 110 - INTROD BIOL PSYCH 001'
Esempio n. 4
0
    def test_stream_zipped_bundle(self, app, fake_auth):
        with mock_legacy_note_attachment(app):
            stream = get_zip_stream_for_sid('9000000000')['stream']
            body = b''
            for chunk in stream:
                body += chunk
            zipfile = ZipFile(io.BytesIO(body), 'r')
            contents = {}
            for name in zipfile.namelist():
                contents[name] = zipfile.read(name)

            assert len(contents) == 2
            assert contents[
                'dog_eaten_homework.pdf'] == b'When in the course of human events, it becomes necessarf arf woof woof woof'
            today = localize_datetime(utc_now()).strftime('%Y%m%d')
            csv_rows = contents[
                f"advising_notes_wolfgang_pauli-o'rourke_{today}.csv"].decode(
                    'utf-8').strip().split('\r\n')
            assert len(csv_rows) == 4
            assert csv_rows[
                0] == 'date_created,student_sid,student_name,author_uid,author_csid,author_name,subject,topics,attachments,\
body,late_change_request_action,late_change_request_status,late_change_request_term,late_change_request_course'
            assert csv_rows[1] ==\
                "2017-11-02,9000000000,Wolfgang Pauli-O'Rourke,,700600500,,,,dog_eaten_homework.pdf,I am confounded by this confounding student,,,,"
            assert csv_rows[
                2] == "2017-11-02,9000000000,Wolfgang Pauli-O'Rourke,,600500400,,,Ne Scéaw,,Is this student even on campus?,,,,"
            assert csv_rows[
                3] == "2020-12-05,9000000000,Wolfgang Pauli-O'Rourke,,,,,,,,Late Grading Basis Change,In Error,Fall 2020,24460 PSYCH 110 - \
Esempio n. 5
0
 def test_stream_note_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'
Esempio n. 6
0
 def _assert_zip_download(self, app, client):
     today = localize_datetime(utc_now()).strftime('%Y%m%d')
     with mock_legacy_note_attachment(app):
         response = client.get('/api/notes/download_for_sid/9000000000')
         assert response.status_code == 200
         assert response.headers['Content-Type'] == 'application/zip'
         assert response.headers['Content-Disposition'] == f"attachment; filename=advising_notes_wolfgang_pauli-o'rourke_{today}.zip"
         assert response.data
Esempio n. 7
0
 def test_stream_attachment(self, app, client, fake_auth):
     with mock_legacy_note_attachment(app):
         fake_auth.login(coe_advisor_uid)
         response = client.get('/api/notes/attachment/9000000000_00002_1.pdf')
         assert response.status_code == 200
         assert response.headers['Content-Type'] == 'application/octet-stream'
         assert response.headers['Content-Disposition'] == "attachment; filename*=UTF-8''dog_eaten_homework.pdf"
         assert response.data == b'When in the course of human events, it becomes necessarf arf woof woof woof'
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
0
 def test_user_without_advising_data_access(self, app, client, fake_auth):
     """Denies access to a user who cannot access notes and appointments."""
     with mock_legacy_note_attachment(app):
         fake_auth.login(coe_advisor_no_advising_data_uid)
         assert client.get('/api/notes/attachment/9000000000_00002_1.pdf').status_code == 401