def test_get_note_template_by_id(self, app, client, fake_auth): """Returns note templates created by current user.""" fake_auth.login(l_s_major_advisor_uid) creator_id = AuthorizedUser.get_id_per_uid(l_s_major_advisor_uid) names = ['Johnny', 'Tommy', 'Joey', 'Dee Dee'] for i in range(0, 4): NoteTemplate.create(creator_id=creator_id, title=f'{names[i]}', subject=f'Subject {i}') api_json = self._api_my_note_templates(client=client) expected_order = [template['title'] for template in api_json] expected_order.sort() assert expected_order == [template['title'] for template in api_json]
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
def create_note_template(): params = request.form title = params.get('title', None) subject = params.get('subject', None) body = params.get('body', None) topics = get_note_topics_from_http_post() if not title or not subject: raise BadRequestError( 'Note creation requires \'subject\' and \'title\'') user_dept_codes = dept_codes_where_advising(current_user) if current_user.is_admin or not len(user_dept_codes): raise ForbiddenRequestError( 'Sorry, only advisors can create advising note templates') attachments = get_note_attachments_from_http_post(tolerate_none=True) note_template = NoteTemplate.create( attachments=attachments, body=process_input_from_rich_text_editor(body), creator_id=current_user.get_id(), is_private=to_bool_or_none(params.get('isPrivate', False)), subject=subject, title=title, topics=topics, ) return tolerant_jsonify(note_template.to_api_json())