def create_new_note(): """ Render create note page and create notes """ if request.method == "POST": form = request.form title = form["title"] text = form["text"] user = current_user create_note(g.session, title, text, user) return redirect(url_for("list_notes")) return render_template("create_note.html")
def note_exists(session, note_title, user_name): user = get_user(session, user_name) print(f"Creating {note_title}") note = create_note(session, note_title, "Default test note", user) session.commit() return note
def create_note_with_content(session, note_title, user_name, content): user = get_user(session, user_name) print(f"Creating {note_title}") note = create_note(session, note_title, content, user) session.commit() return note
def test_note(session, user): note = create_note( session, f"Test Note", f"Note is for tests only.\nThis should not be in the real database", user, ) session.commit() return note
def test_create_simple_note(session, user): title = "Test Note" text = "This note is for a simple test" note = create_note(session, title, text, user) session.commit() assert note.id == 1, "New note should be the first one" assert note.title == title, "New note should have the specified title" assert note.text == text, "New note should have the specified text" assert note.owner_id == user.id, "Notes should be owned by their creators"
def test_create_multiline_note(session, user): title = "Test Note" text = "This note has\nmultiple lines." note = create_note(session, title, text, user) session.commit() assert note.id == 1, "New note should be the first one" assert note.title == title, "New note should have the specified title" assert note.text == text, "New note should have the specified text" assert note.owner_id == user.id, "Notes should be owned by their creators" assert len(note.sections) == 2, "Each line of a note should be it's own section"
def test_notes(session, user): notes = [] for i in range(5): notes.append( create_note( session, f"Test Note {i}", f"Note {i} is for tests only.\nThis should not be in the real database", user, )) session.commit() return notes