2007-07-16 20:22:38 +00:00
|
|
|
import cherrypy
|
|
|
|
import cgi
|
|
|
|
from Test_controller import Test_controller
|
|
|
|
from controller.Scheduler import Scheduler
|
|
|
|
from model.Notebook import Notebook
|
2007-07-17 01:21:31 +00:00
|
|
|
from model.Note import Note
|
2007-07-16 20:22:38 +00:00
|
|
|
from model.User import User
|
|
|
|
|
|
|
|
|
|
|
|
class Test_notebooks( Test_controller ):
|
|
|
|
def setUp( self ):
|
|
|
|
Test_controller.setUp( self )
|
|
|
|
|
|
|
|
self.notebook = None
|
|
|
|
self.anon_notebook = None
|
|
|
|
self.unknown_notebook_id = "17"
|
2007-07-17 01:21:31 +00:00
|
|
|
self.unknown_note_id = "42"
|
2007-07-16 20:22:38 +00:00
|
|
|
self.username = u"mulder"
|
|
|
|
self.password = u"trustno1"
|
|
|
|
self.email_address = u"outthere@example.com"
|
|
|
|
self.user = None
|
|
|
|
self.anonymous = None
|
|
|
|
self.session_id = None
|
|
|
|
|
|
|
|
thread = self.make_notebooks()
|
|
|
|
self.scheduler.add( thread )
|
|
|
|
self.scheduler.wait_for( thread )
|
|
|
|
|
|
|
|
thread = self.make_users()
|
|
|
|
self.scheduler.add( thread )
|
|
|
|
self.scheduler.wait_for( thread )
|
|
|
|
|
|
|
|
def make_notebooks( self ):
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
self.notebook = Notebook( ( yield Scheduler.SLEEP ), u"notebook" )
|
|
|
|
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
2007-07-17 01:21:31 +00:00
|
|
|
self.note = Note( ( yield Scheduler.SLEEP ), u"<h3>my title</h3>blah" )
|
|
|
|
self.notebook.add_note( self.note )
|
|
|
|
self.notebook.add_startup_note( self.note )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
2007-07-17 01:21:31 +00:00
|
|
|
self.note2 = Note( ( yield Scheduler.SLEEP ), u"<h3>other title</h3>whee" )
|
|
|
|
self.notebook.add_note( self.note2 )
|
2007-07-16 20:22:38 +00:00
|
|
|
self.database.save( self.notebook )
|
|
|
|
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
self.anon_notebook = Notebook( ( yield Scheduler.SLEEP ), u"anon_notebook" )
|
|
|
|
self.database.save( self.anon_notebook )
|
|
|
|
|
|
|
|
def make_users( self ):
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
self.user = User( ( yield Scheduler.SLEEP ), self.username, self.password, self.email_address, [ self.notebook ] )
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
self.anonymous = User( ( yield Scheduler.SLEEP ), u"anonymous", None, None, [ self.anon_notebook ] )
|
|
|
|
|
|
|
|
self.database.save( self.user )
|
|
|
|
self.database.save( self.anonymous )
|
|
|
|
|
|
|
|
def test_default( self ):
|
|
|
|
result = self.http_get( "/notebooks/%s" % self.notebook.object_id )
|
|
|
|
|
|
|
|
assert result.get( u"notebook_id" ) == self.notebook.object_id
|
|
|
|
|
|
|
|
def test_contents( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
|
|
|
assert notebook.object_id == self.notebook.object_id
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 1
|
|
|
|
assert notebook.startup_notes[ 0 ] == self.note
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_contents_without_login( self ):
|
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.object_id == self.note.object_id
|
|
|
|
assert note.title == self.note.title
|
|
|
|
assert note.contents == self.note.contents
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_note_without_login( self ):
|
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_note_with_unknown_notebook( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.unknown_notebook_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_unknown_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.unknown_note_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
|
|
|
assert note == None
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_note_by_title( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = self.note.title,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.object_id == self.note.object_id
|
|
|
|
assert note.title == self.note.title
|
|
|
|
assert note.contents == self.note.contents
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_note_by_title_without_login( self ):
|
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = self.note.title,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_note_by_title_with_unknown_notebook( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.unknown_notebook_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = self.note.title,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_load_unknown_note_by_title( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = "unknown title",
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
|
|
|
assert note == None
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_note( self, startup = False ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# save over an existing note supplying new contents and a new title
|
|
|
|
new_note_contents = u"<h3>new title</h3>new blah"
|
|
|
|
result = self.http_post( "/notebooks/save_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
|
|
|
contents = new_note_contents,
|
2007-07-16 20:22:38 +00:00
|
|
|
startup = startup,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result[ "saved" ] == True
|
|
|
|
|
|
|
|
# make sure the old title can no longer be loaded
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = "my title",
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
|
|
|
assert note == None
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
# make sure the new title is now loadable
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = "new title",
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.object_id == self.note.object_id
|
|
|
|
assert note.title == self.note.title
|
|
|
|
assert note.contents == self.note.contents
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# check that the note is / is not a startup note
|
2007-07-16 20:22:38 +00:00
|
|
|
if startup:
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note in self.notebook.startup_notes
|
2007-07-16 20:22:38 +00:00
|
|
|
else:
|
2007-07-17 01:21:31 +00:00
|
|
|
assert not note in self.notebook.startup_notes
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_startup_note( self ):
|
|
|
|
self.test_save_note( startup = True )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_note_without_login( self, startup = False ):
|
|
|
|
# save over an existing note supplying new contents and a new title
|
|
|
|
new_note_contents = u"<h3>new title</h3>new blah"
|
|
|
|
result = self.http_post( "/notebooks/save_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
|
|
|
contents = new_note_contents,
|
2007-07-16 20:22:38 +00:00
|
|
|
startup = startup,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_startup_note_without_login( self ):
|
|
|
|
self.test_save_note_without_login( startup = True )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_note_with_unknown_notebook( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# save over an existing note supplying new contents and a new title
|
|
|
|
new_note_contents = u"<h3>new title</h3>new blah"
|
|
|
|
result = self.http_post( "/notebooks/save_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.unknown_notebook_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
|
|
|
contents = new_note_contents,
|
2007-07-16 20:22:38 +00:00
|
|
|
startup = False,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_new_note( self, startup = False ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# save a completely new note
|
|
|
|
new_note = Note( "55", u"<h3>newest title</h3>foo" )
|
|
|
|
result = self.http_post( "/notebooks/save_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = new_note.object_id,
|
|
|
|
contents = new_note.contents,
|
2007-07-16 20:22:38 +00:00
|
|
|
startup = startup,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result[ "saved" ] == True
|
|
|
|
|
|
|
|
# make sure the new title is now loadable
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = new_note.title,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.object_id == new_note.object_id
|
|
|
|
assert note.title == new_note.title
|
|
|
|
assert note.contents == new_note.contents
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# check that the note is / is not a startup note
|
2007-07-16 20:22:38 +00:00
|
|
|
if startup:
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note in self.notebook.startup_notes
|
2007-07-16 20:22:38 +00:00
|
|
|
else:
|
2007-07-17 01:21:31 +00:00
|
|
|
assert not note in self.notebook.startup_notes
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_new_startup_note( self ):
|
|
|
|
self.test_save_new_note( startup = True )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_new_note_with_disallowed_tags( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# save a completely new note
|
2007-07-16 20:22:38 +00:00
|
|
|
title_with_tags = u"<h3>my title</h3>"
|
|
|
|
junk = u"foo<script>haxx0r</script>"
|
|
|
|
more_junk = u"<p style=\"evil\">blah</p>"
|
2007-07-17 01:21:31 +00:00
|
|
|
new_note = Note( "55", title_with_tags + junk + more_junk )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/save_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = new_note.object_id,
|
|
|
|
contents = new_note.contents,
|
2007-07-16 20:22:38 +00:00
|
|
|
startup = False,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result[ "saved" ] == True
|
|
|
|
|
|
|
|
# make sure the new title is now loadable
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = new_note.title,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
expected_contents = title_with_tags + cgi.escape( junk ) + u"<p>blah</p>"
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.object_id == new_note.object_id
|
|
|
|
assert note.title == new_note.title
|
|
|
|
assert note.contents == expected_contents
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_save_new_note_with_bad_characters( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# save a completely new note
|
2007-07-16 20:22:38 +00:00
|
|
|
contents = "<h3>newest title</h3>foo"
|
|
|
|
junk = "\xa0bar"
|
2007-07-17 01:21:31 +00:00
|
|
|
new_note = Note( "55", contents + junk )
|
|
|
|
result = self.http_post( "/notebooks/save_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = new_note.object_id,
|
|
|
|
contents = new_note.contents,
|
2007-07-16 20:22:38 +00:00
|
|
|
startup = False,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result[ "saved" ] == True
|
|
|
|
|
|
|
|
# make sure the new title is now loadable
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_title = new_note.title,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result[ "note" ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.object_id == new_note.object_id
|
|
|
|
assert note.title == new_note.title
|
|
|
|
assert note.contents == contents + " bar"
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_add_startup_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/add_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note2.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that the added note shows up in notebook.startup_notes
|
2007-07-16 20:22:38 +00:00
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 2
|
|
|
|
assert notebook.startup_notes[ 0 ] == self.note
|
|
|
|
assert notebook.startup_notes[ 1 ] == self.note2
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_add_startup_note_without_login( self ):
|
|
|
|
result = self.http_post( "/notebooks/add_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note2.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_add_startup_note_with_unknown_notebook( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/add_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.unknown_notebook_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note2.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that notebook.startup_notes hasn't changed
|
2007-07-16 20:22:38 +00:00
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 1
|
|
|
|
assert notebook.startup_notes[ 0 ] == self.note
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_add_startup_unknown_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/add_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.unknown_note_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that notebook.startup_notes hasn't changed
|
2007-07-16 20:22:38 +00:00
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 1
|
|
|
|
assert notebook.startup_notes[ 0 ] == self.note
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_remove_startup_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/remove_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that the remove note no longer shows up in notebook.startup_notes
|
2007-07-16 20:22:38 +00:00
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 0
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_remove_startup_note_without_login( self ):
|
|
|
|
result = self.http_post( "/notebooks/remove_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_remove_startup_note_with_unknown_notebook( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/remove_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.unknown_notebook_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that notebook.startup_notes hasn't changed
|
2007-07-16 20:22:38 +00:00
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 1
|
|
|
|
assert notebook.startup_notes[ 0 ] == self.note
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_remove_startup_unknown_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/remove_startup_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.unknown_note_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that notebook.startup_notes hasn't changed
|
2007-07-16 20:22:38 +00:00
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/contents?notebook_id=%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
notebook = result[ "notebook" ]
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notebook.startup_notes ) == 1
|
|
|
|
assert notebook.startup_notes[ 0 ] == self.note
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_delete_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/delete_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that the delete note is actually deleted
|
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert result.get( "note" ) == None
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_delete_note_without_login( self ):
|
|
|
|
result = self.http_post( "/notebooks/delete_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_delete_note_with_unknown_notebook( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/delete_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.unknown_notebook_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that the note hasn't been deleted
|
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result.get( "note" )
|
|
|
|
assert note.object_id == self.note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_delete_unknown_note( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/delete_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.unknown_note_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# test that the note hasn't been deleted
|
|
|
|
result = self.http_post( "/notebooks/load_note/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
2007-07-17 01:21:31 +00:00
|
|
|
note_id = self.note.object_id,
|
2007-07-16 20:22:38 +00:00
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note = result.get( "note" )
|
|
|
|
assert note.object_id == self.note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_blank_note( self ):
|
|
|
|
result = self.http_get( "/notebooks/blank_note/5" )
|
2007-07-16 20:22:38 +00:00
|
|
|
assert result[ u"id" ] == u"5"
|
|
|
|
|
|
|
|
def test_search( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
search_text = u"bla"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 1
|
|
|
|
assert notes[ 0 ].object_id == self.note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_search_without_login( self ):
|
|
|
|
search_text = u"bla"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
|
|
|
def test_case_insensitive_search( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
search_text = u"bLA"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 1
|
|
|
|
assert notes[ 0 ].object_id == self.note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_empty_search( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
search_text = ""
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 0
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_search_with_no_results( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
search_text = "doesn't match anything"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 0
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_search_title_and_contents( self ):
|
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# ensure that notes with titles matching the search text show up before notes with only
|
2007-07-16 20:22:38 +00:00
|
|
|
# contents matching the search text
|
2007-07-17 01:21:31 +00:00
|
|
|
note3 = Note( "55", u"<h3>blah</h3>foo" )
|
|
|
|
self.notebook.add_note( note3 )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
self.database.save( self.notebook )
|
|
|
|
|
|
|
|
search_text = "bla"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 2
|
|
|
|
assert notes[ 0 ].object_id == note3.object_id
|
|
|
|
assert notes[ 1 ].object_id == self.note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_search_html_tags( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
search_text = "h3"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 0
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-19 19:03:40 +00:00
|
|
|
def test_search_character_refs( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
note3 = Note( "55", u"<h3>foo: bar</h3>baz" )
|
|
|
|
self.notebook.add_note( note3 )
|
|
|
|
|
|
|
|
search_text = "oo: b"
|
|
|
|
|
|
|
|
result = self.http_post( "/notebooks/search/", dict(
|
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
search_text = search_text,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
notes = result.get( "notes" )
|
|
|
|
|
|
|
|
assert len( notes ) == 1
|
|
|
|
assert notes[ 0 ].object_id == note3.object_id
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_recent_notes( self ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
result = self.http_post( "/notebooks/recent_notes/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
assert len( notes ) == 2
|
|
|
|
assert notes[ 0 ].object_id == self.note2.object_id
|
|
|
|
assert notes[ 1 ].object_id == self.note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
def test_recent_notes_without_login( self ):
|
|
|
|
result = self.http_post( "/notebooks/recent_notes/", dict(
|
2007-07-16 20:22:38 +00:00
|
|
|
notebook_id = self.notebook.object_id,
|
|
|
|
), session_id = self.session_id )
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
|
|
|
def test_download_html( self ):
|
|
|
|
self.login()
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
note3 = Note( "55", u"<h3>blah</h3>foo" )
|
|
|
|
self.notebook.add_note( note3 )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/download_html/%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
assert result.get( "notebook_name" ) == self.notebook.name
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
notes = result.get( "notes" )
|
|
|
|
assert len( notes ) == len( self.notebook.notes )
|
|
|
|
startup_note_allowed = True
|
2007-07-16 20:22:38 +00:00
|
|
|
previous_revision = None
|
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
# assert that startup notes come first, then normal notes in descending revision order
|
|
|
|
for note in notes:
|
|
|
|
if note in self.notebook.startup_notes:
|
|
|
|
assert startup_note_allowed
|
2007-07-16 20:22:38 +00:00
|
|
|
else:
|
2007-07-17 01:21:31 +00:00
|
|
|
startup_note_allowed = False
|
|
|
|
assert note in self.notebook.notes
|
2007-07-16 20:22:38 +00:00
|
|
|
if previous_revision:
|
2007-07-17 01:21:31 +00:00
|
|
|
assert note.revision < previous_revision
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
previous_revision = note.revision
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
def test_download_html( self ):
|
2007-07-17 01:21:31 +00:00
|
|
|
note3 = Note( "55", u"<h3>blah</h3>foo" )
|
|
|
|
self.notebook.add_note( note3 )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/download_html/%s" % self.notebook.object_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
|
|
|
def test_download_html_with_unknown_notebook( self ):
|
|
|
|
self.login()
|
|
|
|
|
|
|
|
result = self.http_get(
|
|
|
|
"/notebooks/download_html/%s" % self.unknown_notebook_id,
|
|
|
|
session_id = self.session_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
assert result.get( "error" )
|
|
|
|
|
|
|
|
def login( self ):
|
|
|
|
result = self.http_post( "/users/login", dict(
|
|
|
|
username = self.username,
|
|
|
|
password = self.password,
|
|
|
|
login_button = u"login",
|
|
|
|
) )
|
|
|
|
self.session_id = result[ u"session_id" ]
|