def notes(db_session, test_user): other_user = User(email='*****@*****.**', full_name='Testy McTestface') db_session.add(other_user) db_session.commit() content = 'This is not your note' return ( [Note.create(content='*foo*', author=test_user) for i in range(3)] + [Note.create(content=content, author=other_user) for i in range(3)])
def search(): term = escape(request.args.get('q')) results = Note.search(term, current_user) ctx = { 'notes': results.all(), 'search_term': term, 'result_count': results.count()} return render_template('notes/search.html', **ctx)
def make_note(data): content, tags = data note = Note.create(content=content, author=test_user) for tag in tags: note.add_tag(tag) return note
def it_strips_html_tags_from_the_user_input(self, db_session, test_user): note = Note.create('<script>alert("bad things")</script>', test_user) assert note.content == 'alert("bad things")' note.update('<form action="evil.com/phish"><input name="cc"></form>') assert note.content == '' note.update('<p style="color: pink">woo!</p>') assert note.content == 'woo!'
def it_stores_the_previous_version(self, db_session, test_user): note = Note.create('Test note', test_user) assert len(note.history) == 0 note.update('Test note edited') assert len(note.history) == 1 assert note.history[0].content == 'Test note' assert note.history[0].version == 1
def undo(id): note = Note.get_or_404(id=id, author=current_user) try: note.revert() except note.VersionDoesNotExist: pass return redirect(url_for('.list'))
def add(): content = request.form.get('content', '').strip() tags = request.form.get('tags', '').split(',') if content: note = Note.create(content=content, author=current_user) for tag in tags: note.add_tag(tag.strip()) return redirect(url_for('.list'))
def it_can_be_reverted_to_a_previous_version(self, db_session, test_user): note = Note.create('Test note', test_user) note.update('Test note edited') note.update('Test note edited again') assert len(note.history) == 2 assert note.history[0].version == 0 assert note.history[1].version == 1 note.revert() assert len(note.history) == 3 assert note.content == 'Test note edited' note.revert(version=2) assert len(note.history) == 4 assert note.content == 'Test note edited again'
def edit(id): note = Note.get_or_404(id=id, author=current_user) if request.method == 'GET': return render_template('notes/edit.html', note=note) note.update(request.form['content']) existing_tags = set([tag.name for tag in note.tags]) submitted_tags = set( [tag.strip() for tag in request.form.get('tags', '').split(',')]) for tag in (submitted_tags - existing_tags): note.add_tag(tag) for tag in (existing_tags - submitted_tags): note.remove_tag(tag) return redirect(url_for('.list'))
def it_must_have_an_author(self, db_session): with pytest.raises(TypeError): Note.create('Test note')
def example_note(db_session, test_user): note = Note.create('Original content', test_user) return note
def updated_note(db_session): note = Note.create('Original text') note.update('Updated text') return note
def updated_note(db_session, test_user): note = Note.create('Original content', test_user) note.update('Updated content') return note
def tagged_note(db_session, test_user): note = Note.create(content='A tagged note', author=test_user) note.add_tag('foo') note.add_tag('bar') return note
def some_notes(db_session, test_user): _notes = [ 'foo', 'read', 'reader', 'baz and bar', 'a bar', 'bar baz bar baz' ] return [Note.create(content=note, author=test_user) for note in _notes]
def some_notes(db_session, test_user): _notes = [ 'foo', 'read', 'reader', 'baz and bar', 'a bar', 'bar baz bar baz'] return [Note.create(content=note, author=test_user) for note in _notes]
def search_json(): term = request.args.get('q') notes = Note.search(term, current_user).all() return jsonify({'results': [note.json for note in notes]})