hm"
new_note = Note.create( "55", title_with_tags + junk + more_junk )
previous_revision = new_note.revision
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = new_note.object_id,
contents = new_note.contents,
startup = False,
previous_revision = None,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ] != previous_revision
assert result[ "new_revision" ].user_id == self.user.object_id
assert result[ "new_revision" ].username == self.username
assert result[ "previous_revision" ] == None
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
assert result[ "rank" ] == 0.0
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
note_title = new_note.title,
), session_id = self.session_id )
note = result[ "note" ]
expected_contents = title_with_tags + u"fooms word!blahhm"
assert note.object_id == new_note.object_id
assert note.title == new_note.title
assert note.contents == expected_contents
assert note.user_id == self.user.object_id
def test_save_new_note_with_unknown_tags( self ):
self.login()
# save a completely new note
title_with_tags = u"my funny title
"
junk = u"fooblahbar"
new_note = Note.create( "55", title_with_tags + junk )
previous_revision = new_note.revision
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = new_note.object_id,
contents = new_note.contents,
startup = False,
previous_revision = None,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ] != previous_revision
assert result[ "new_revision" ].user_id == self.user.object_id
assert result[ "new_revision" ].username == self.username
assert result[ "previous_revision" ] == None
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
assert result[ "rank" ] == 0.0
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
note_title = new_note.title,
), session_id = self.session_id )
note = result[ "note" ]
expected_contents = title_with_tags + u"fooblahbar"
assert note.object_id == new_note.object_id
assert note.title == new_note.title
assert note.contents == expected_contents
assert note.user_id == self.user.object_id
def test_save_new_note_with_bad_characters( self ):
self.login()
# save a completely new note
contents = "newest title
foo"
junk = "\xa0bar"
new_note = Note.create( "55", contents + junk )
previous_revision = new_note.revision
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = new_note.object_id,
contents = new_note.contents,
startup = False,
previous_revision = None,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ] != previous_revision
assert result[ "new_revision" ].user_id == self.user.object_id
assert result[ "new_revision" ].username == self.username
assert result[ "previous_revision" ] == None
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
assert result[ "rank" ] == 0.0
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
note_title = new_note.title,
), session_id = self.session_id )
note = result[ "note" ]
assert note.object_id == new_note.object_id
assert note.title == new_note.title
assert note.contents == contents + " bar"
assert note.user_id == self.user.object_id
def test_save_two_new_notes( self, startup = False ):
self.login()
# save a completely new note
new_note = Note.create( "55", u"newest title
foo" )
previous_revision = new_note.revision
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = new_note.object_id,
contents = new_note.contents,
startup = startup,
previous_revision = None,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
previous_storage_bytes = user.storage_bytes
# save a completely new note
new_note = Note.create( "56", u"my new title
foo" )
previous_revision = new_note.revision
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = new_note.object_id,
contents = new_note.contents,
startup = startup,
previous_revision = None,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ] != previous_revision
assert result[ "new_revision" ].user_id == self.user.object_id
assert result[ "new_revision" ].username == self.username
assert result[ "previous_revision" ] == None
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
assert result[ "rank" ] == 1.0
# make sure the new title is now loadable
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
note_title = new_note.title,
), session_id = self.session_id )
note = result[ "note" ]
assert note.object_id == new_note.object_id
assert note.title == new_note.title
assert note.contents == new_note.contents
assert note.startup == startup
assert note.user_id == self.user.object_id
assert note.rank == 1.0 # one greater than the previous new note's rank
def test_save_two_new_startup_notes( self ):
self.test_save_two_new_notes( startup = True )
def test_revert_note( self ):
self.login()
# save over an existing note, supplying new contents and a new title
first_revision = self.note.revision
original_contents = self.note.contents
new_note_contents = u"new title
new blah"
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
contents = new_note_contents,
startup = False,
previous_revision = first_revision,
), session_id = self.session_id )
second_revision = result[ "new_revision" ].revision
# revert the note to the earlier revision
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = first_revision,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ].revision != first_revision
assert result[ "new_revision" ].revision != second_revision
assert result[ "new_revision" ].user_id == self.user.object_id
assert result[ "new_revision" ].username == self.username
current_revision = result[ "new_revision" ].revision
assert result[ "previous_revision" ].revision == second_revision
assert result[ "previous_revision" ].user_id == self.user.object_id
assert result[ "previous_revision" ].username == self.username
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
assert result[ "contents" ] == original_contents
# make sure that the correct revisions are returned and are in chronological order
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 4
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
assert revisions[ 3 ].revision == current_revision
assert revisions[ 3 ].user_id == self.user.object_id
assert revisions[ 3 ].username == self.username
def test_revert_note_own_notes( self ):
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = True,
) )
self.test_revert_note()
def test_revert_note_by_different_user( self ):
self.login()
# save over an existing note, supplying new contents and a new title
first_revision = self.note.revision
original_contents = self.note.contents
new_note_contents = u"new title
new blah"
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
contents = new_note_contents,
startup = False,
previous_revision = first_revision,
), session_id = self.session_id )
second_revision = result[ "new_revision" ].revision
self.login2()
# as a different user, revert the note to the earlier revision
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = first_revision,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ].revision != first_revision
assert result[ "new_revision" ].revision != second_revision
assert result[ "new_revision" ].user_id == self.user2.object_id
assert result[ "new_revision" ].username == self.username2
current_revision = result[ "new_revision" ].revision
assert result[ "previous_revision" ].revision == second_revision
assert result[ "previous_revision" ].user_id == self.user.object_id
assert result[ "previous_revision" ].username == self.username
assert result[ "contents" ] == original_contents
# make sure that the correct revisions are returned and are in chronological order
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 4
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
assert revisions[ 3 ].revision == current_revision
assert revisions[ 3 ].user_id == self.user2.object_id
assert revisions[ 3 ].username == self.username2
def test_revert_note_own_notes_by_different_user( self ):
self.login()
self.database.execute( self.user2.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = True,
) )
# save over an existing note, supplying new contents and a new title
first_revision = self.note.revision
original_contents = self.note.contents
new_note_contents = u"new title
new blah"
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
contents = new_note_contents,
startup = False,
previous_revision = first_revision,
), session_id = self.session_id )
second_revision = result[ "new_revision" ].revision
self.login2()
# as a different user, revert the note to the earlier revision
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = first_revision,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
# make sure that a new revision wasn't saved
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 3
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
def test_revert_note_without_login( self ):
self.login()
# save over an existing note, supplying new contents and a new title
first_revision = self.note.revision
original_contents = self.note.contents
new_note_contents = u"new title
new blah"
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
contents = new_note_contents,
startup = False,
previous_revision = first_revision,
), session_id = self.session_id )
second_revision = result[ "new_revision" ].revision
# revert the note to the earlier revision, but without logging in
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = first_revision,
) )
assert result.get( "error" )
# make sure that a new revision wasn't saved
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 3
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
def test_revert_deleted_note( self ):
self.login()
# delete an existing note
first_revision = self.note.revision
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = self.database.load( Note, self.note.object_id )
second_revision = note.revision
# revert the note to the earlier, non-deleted revision
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = first_revision,
), session_id = self.session_id )
assert result[ "new_revision" ]
assert result[ "new_revision" ].revision != first_revision
assert result[ "new_revision" ].revision != second_revision
assert result[ "new_revision" ].user_id == self.user.object_id
assert result[ "new_revision" ].username == self.username
current_revision = result[ "new_revision" ].revision
assert result[ "previous_revision" ].revision == second_revision
assert result[ "previous_revision" ].user_id == self.user.object_id
assert result[ "previous_revision" ].username == self.username
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
assert result[ "contents" ] == self.note.contents
# make sure that the reverted note is not in the trash anymore
note = self.database.load( Note, self.note.object_id )
assert note.notebook_id == self.note.notebook_id
# make sure that the correct revisions are returned and are in chronological order
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 4
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
assert revisions[ 3 ].revision == current_revision
assert revisions[ 3 ].user_id == self.user.object_id
assert revisions[ 3 ].username == self.username
def test_revert_note_with_unknown_notebook( self ):
self.login()
# save over an existing note, supplying new contents and a new title
first_revision = self.note.revision
original_contents = self.note.contents
new_note_contents = u"new title
new blah"
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
contents = new_note_contents,
startup = False,
previous_revision = first_revision,
), session_id = self.session_id )
second_revision = result[ "new_revision" ].revision
# revert the note to the earlier revision, but with an unknown notebook
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.unknown_notebook_id,
note_id = self.note.object_id,
revision = first_revision,
), session_id = self.session_id )
assert result.get( "error" )
# make sure that a new revision wasn't saved
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 3
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
def test_revert_unknown_note( self ):
self.login()
# revert a new (unsaved) note
new_note = Note.create( "55", u"newest title
foo" )
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = new_note.object_id,
revision = new_note.revision,
), session_id = self.session_id )
assert "access" in result.get( "error" )
note = self.database.load( Note, new_note.object_id )
assert note == None
def test_revert_note_to_newest_revision( self ):
self.login()
# save over an existing note, supplying new contents and a new title
first_revision = self.note.revision
original_contents = self.note.contents
new_note_contents = u"new title
new blah"
result = self.http_post( "/notebooks/save_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
contents = new_note_contents,
startup = False,
previous_revision = first_revision,
), session_id = self.session_id )
second_revision = result[ "new_revision" ].revision
# "revert" the note to the most recent revision
result = self.http_post( "/notebooks/revert_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = second_revision,
), session_id = self.session_id )
assert result[ "new_revision" ] is None
assert result[ "previous_revision" ].revision == second_revision
assert result[ "previous_revision" ].user_id == self.user.object_id
assert result[ "previous_revision" ].username == self.username
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "contents" ] == new_note_contents
# make sure that the correct revisions are returned and are in chronological order
result = self.http_post( "/notebooks/load_note_revisions/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
revisions = result[ "revisions" ]
assert revisions != None
assert len( revisions ) == 3
assert revisions[ 1 ].revision == first_revision
assert revisions[ 1 ].user_id == self.user.object_id
assert revisions[ 1 ].username == self.username
assert revisions[ 2 ].revision == second_revision
assert revisions[ 2 ].user_id == self.user.object_id
assert revisions[ 2 ].username == self.username
def test_delete_note( self ):
self.login()
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
# test that the deleted note is actually deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "note" ] is None
assert result[ "note_id_in_trash" ] == self.note.object_id
# test that the deleted note can be loaded from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result[ "note" ]
assert note
assert note.object_id == self.note.object_id
assert note.title == self.note.title
assert note.contents == self.note.contents
assert note.startup == self.note.startup
assert note.deleted_from_id == self.notebook.object_id
assert note.user_id == self.user.object_id
def test_delete_note_own_notes( self ):
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
self.test_delete_note()
def test_delete_note_from_trash( self ):
self.login()
# first, delete the note from the main notebook, thereby moving it to the trash
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
# then, delete the note from the trash
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
# test that the deleted note is actually deleted from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "note" ) is None
def test_delete_note_without_login( self ):
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "error" )
def test_delete_note_with_unknown_notebook( self ):
self.login()
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.unknown_notebook_id,
note_id = self.note.object_id,
), session_id = self.session_id )
# test that the note hasn't been deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note.object_id == self.note.object_id
def test_delete_unknown_note( self ):
self.login()
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.unknown_note_id,
), session_id = self.session_id )
# test that the note hasn't been deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note.object_id == self.note.object_id
def test_delete_note_by_a_different_user( self ):
self.login2()
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
user2 = self.database.load( User, self.user2.object_id )
assert user2.storage_bytes == 0
assert result[ "storage_bytes" ] == user2.storage_bytes
# test that the deleted note is actually deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "note" ] is None
assert result[ "note_id_in_trash" ] == self.note.object_id
# test that the deleted note can be loaded from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result[ "note" ]
assert note
assert note.object_id == self.note.object_id
assert note.title == self.note.title
assert note.contents == self.note.contents
assert note.startup == self.note.startup
assert note.deleted_from_id == self.notebook.object_id
assert note.user_id == self.user2.object_id
def test_delete_note_own_notes_by_a_different_user( self ):
self.login2()
self.database.execute( self.user2.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_undelete_note( self ):
self.login()
# first delete the note
self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
# get the revision of the deleted note
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.trash.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
deleted_revision = result[ "note" ].revision
# then undelete the note
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
# test that the undeleted note is actually undeleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == None
assert note.notebook_id == self.notebook.object_id
assert note.user_id == self.user.object_id
# test that the revision of the note from when it was deleted is loadable
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
revision = deleted_revision,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == self.notebook.object_id
assert note.notebook_id == self.trash.object_id
assert note.user_id == self.user.object_id
def test_undelete_note_that_is_not_deleted( self ):
self.login()
# "undelete" the note
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "error" ) == None
# test that the "undeleted" note is where it should be
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == None
assert note.notebook_id == self.notebook.object_id
def test_undelete_note_without_login( self ):
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "error" )
def test_undelete_note_with_unknown_notebook( self ):
self.login()
self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.unknown_notebook_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "error" )
# test that the note hasn't been undeleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == self.notebook.object_id
assert note.notebook_id == self.notebook.trash_id
assert note.user_id == self.user.object_id
def test_undelete_unknown_note( self ):
self.login()
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.unknown_note_id,
), session_id = self.session_id )
# test that the note hasn't been deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == None
assert note.notebook_id == self.notebook.object_id
assert note.user_id == self.user.object_id
def test_undelete_note_from_incorrect_notebook( self ):
self.login()
result = self.http_post( "/notebooks/delete_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.anon_notebook,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "error" )
# test that the note hasn't been undeleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == self.notebook.object_id
assert note.notebook_id == self.notebook.trash_id
assert note.user_id == self.user.object_id
def test_undelete_note_that_is_not_deleted_from_id_incorrect_notebook( self ):
self.login()
result = self.http_post( "/notebooks/undelete_note/", dict(
notebook_id = self.anon_notebook,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "error" )
# test that the note is still in its notebook
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == None
assert note.notebook_id == self.notebook.object_id
assert note.user_id == self.user.object_id
def test_delete_all_notes( self ):
self.login()
result = self.http_post( "/notebooks/delete_all_notes/", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
# test that all notes are actually deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result[ "note" ] is None
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note2.object_id,
), session_id = self.session_id )
assert result[ "note" ] is None
# test that all notes can be loaded from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note
assert note.object_id == self.note.object_id
assert note.deleted_from_id == self.notebook.object_id
assert note.notebook_id == self.notebook.trash_id
assert note.user_id == self.user.object_id
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note2.object_id,
), session_id = self.session_id )
note2 = result.get( "note" )
assert note2
assert note2.object_id == self.note2.object_id
assert note2.deleted_from_id == self.notebook.object_id
assert note2.notebook_id == self.notebook.trash_id
assert note2.user_id == self.user.object_id
def test_delete_all_notes_from_trash( self ):
self.login()
# first, delete all notes from the main notebook, thereby moving them to the trash
result = self.http_post( "/notebooks/delete_all_notes/", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
# then, delete all notes from the trash
result = self.http_post( "/notebooks/delete_all_notes/", dict(
notebook_id = self.notebook.trash_id,
), session_id = self.session_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
assert result[ "storage_bytes" ] == user.storage_bytes
# test that all notes are actually deleted from the trash
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.trash_id,
note_id = self.note.object_id,
), session_id = self.session_id )
assert result.get( "note" ) is None
def test_delete_all_notes_without_login( self ):
result = self.http_post( "/notebooks/delete_all_notes/", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"access" in result.get( "error" )
def test_delete_all_notes_own_notes( self ):
self.login()
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
result = self.http_post( "/notebooks/delete_all_notes/", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"access" in result.get( "error" )
def test_delete_all_notes_with_unknown_notebook( self ):
self.login()
result = self.http_post( "/notebooks/delete_all_notes/", dict(
notebook_id = self.unknown_notebook_id,
), session_id = self.session_id )
# test that the notes haven't been deleted
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
), session_id = self.session_id )
note = result.get( "note" )
assert note.object_id == self.note.object_id
result = self.http_post( "/notebooks/load_note/", dict(
notebook_id = self.notebook.object_id,
note_id = self.note2.object_id,
), session_id = self.session_id )
note2 = result.get( "note" )
assert note2.object_id == self.note2.object_id
def test_search_note_titles( self ):
self.login()
search_text = u"other"
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 == self.note2.object_id
def test_search_contents( 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 )
notes = result.get( "notes" )
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note.object_id
assert notes[ 0 ].summary
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_search_without_access( self ):
self.login2()
self.make_extra_notebooks()
search_text = u"other"
result = self.http_post( "/notebooks/search/", dict(
notebook_id = self.notebook2.object_id,
search_text = search_text,
), session_id = self.session_id )
assert result.get( "error" )
def test_search_case_insensitive( 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 )
notes = result.get( "notes" )
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note.object_id
assert notes[ 0 ].summary
def test_search_empty( 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 )
assert result[ "error" ]
assert u"missing" in result[ "error" ]
def test_search_long( self ):
self.login()
search_text = "w" * 257
result = self.http_post( "/notebooks/search/", dict(
notebook_id = self.notebook.object_id,
search_text = search_text,
), session_id = self.session_id )
assert result[ "error" ]
assert u"too long" in result[ "error" ]
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 )
notes = result.get( "notes" )
assert len( notes ) == 0
def test_search_note_title_and_contents( self ):
self.login()
# ensure that notes with titles matching the search text show up before notes with only
# contents matching the search text
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
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 )
notes = result.get( "notes" )
assert len( notes ) == 2
assert notes[ 0 ].object_id == note3.object_id
assert notes[ 0 ].summary
assert notes[ 1 ].object_id == self.note.object_id
assert notes[ 1 ].summary
def test_search_character_refs( self ):
self.login()
note3 = Note.create( "55", u"foo: bar
baz", notebook_id = self.notebook.object_id )
self.database.save( 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
assert notes[ 0 ].summary
def test_search_titles( self ):
self.login()
search_text = u"other"
result = self.http_post( "/notebooks/search_titles/", 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 == self.note2.object_id
assert notes[ 0 ].title == self.note2.title
assert notes[ 0 ].summary == self.note2.title.replace( search_text, u"%s" % search_text )
def test_search_titles_without_login( self ):
search_text = u"other"
result = self.http_post( "/notebooks/search_titles/", dict(
notebook_id = self.notebook.object_id,
search_text = search_text,
) )
assert result.get( "error" )
def test_search_titles_without_access( self ):
self.login2()
self.make_extra_notebooks()
search_text = u"other"
result = self.http_post( "/notebooks/search_titles/", dict(
notebook_id = self.notebook2.object_id,
search_text = search_text,
), session_id = self.session_id )
assert result.get( "error" )
def test_search_titles_multiple( self ):
self.login()
search_text = u"itl"
result = self.http_post( "/notebooks/search_titles/", dict(
notebook_id = self.notebook.object_id,
search_text = search_text,
), session_id = self.session_id )
notes = result.get( "notes" )
assert len( notes ) == 2
assert notes[ 0 ].object_id == self.note2.object_id
assert notes[ 0 ].title == self.note2.title
assert notes[ 0 ].summary == self.note2.title.replace( search_text, u"%s" % search_text )
assert notes[ 1 ].object_id == self.note.object_id
assert notes[ 1 ].title == self.note.title
assert notes[ 1 ].summary == self.note.title.replace( search_text, u"%s" % search_text )
def test_search_titles_case_insensitive( self ):
self.login()
search_text = u"oTHer"
result = self.http_post( "/notebooks/search_titles/", 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 == self.note2.object_id
assert notes[ 0 ].title == self.note2.title
assert notes[ 0 ].summary == u"other title"
def test_search_titles_empty( self ):
self.login()
search_text = ""
result = self.http_post( "/notebooks/search_titles/", dict(
notebook_id = self.notebook.object_id,
search_text = search_text,
), session_id = self.session_id )
notes = result.get( "notes" )
assert result[ "error" ]
assert u"missing" in result[ "error" ]
def test_search_titles_long( self ):
self.login()
search_text = "w" * 257
result = self.http_post( "/notebooks/search_titles/", dict(
notebook_id = self.notebook.object_id,
search_text = search_text,
), session_id = self.session_id )
notes = result.get( "notes" )
assert result[ "error" ]
assert u"too long" in result[ "error" ]
def test_search_titles_with_no_results( self ):
self.login()
search_text = "doesn't match anything"
result = self.http_post( "/notebooks/search_titles/", dict(
notebook_id = self.notebook.object_id,
search_text = search_text,
), session_id = self.session_id )
notes = result.get( "notes" )
assert len( notes ) == 0
def test_search_titles_character_refs( self ):
self.login()
note3 = Note.create( "55", u"foo: bar
baz", notebook_id = self.notebook.object_id )
self.database.save( note3 )
search_text = "oo: b"
result = self.http_post( "/notebooks/search_titles/", 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
def test_export_with_invalid_format( self ):
self.login()
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=foo^^bar" % self.notebook.object_id,
session_id = self.session_id,
)
assert u"error" in result[ "body" ][ 0 ]
assert u"format is invalid" in result[ "body" ][ 0 ]
def test_export_with_unknown_format( self ):
self.login()
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=foobar" % self.notebook.object_id,
session_id = self.session_id,
)
assert u"error" in result[ "body" ][ 0 ]
assert u"format is unknown" in result[ "body" ][ 0 ]
def test_export_html( self ):
self.login()
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=html" % self.notebook.object_id,
session_id = self.session_id,
)
assert result.get( "notebook" ).object_id == self.notebook.object_id
assert result.get( "view" )
notes = result.get( "notes" )
assert len( notes ) == self.database.select_one( int, self.notebook.sql_count_notes() )
startup_note_allowed = True
previous_revision = None
# assert that startup notes come first, then normal notes in alphabetical order
for note in notes:
if note.startup:
assert startup_note_allowed
else:
startup_note_allowed = False
if previous_revision:
assert note.revision < previous_revision
previous_revision = note.revision
db_note = self.database.load( Note, note.object_id )
assert db_note
assert note.object_id == db_note.object_id
assert note.revision == db_note.revision
assert note.title == db_note.title
assert note.contents == db_note.contents
assert note.notebook_id == db_note.notebook_id
assert note.startup == db_note.startup
assert note.deleted_from_id == db_note.deleted_from_id
assert note.rank == db_note.rank
assert note.user_id == db_note.user_id
assert note.creation == db_note.creation
def test_export_html_without_login( self ):
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
path = "/notebooks/export?notebook_id=%s&format=html" % self.notebook.object_id
result = self.http_get(
path,
session_id = self.session_id,
)
headers = result.get( "headers" )
assert headers
assert headers.get( "Location" ) == u"http:///login?after_login=%s" % urllib.quote( path )
def test_export_html_with_unknown_notebook( self ):
self.login()
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=html" % self.unknown_notebook_id,
session_id = self.session_id,
)
assert u"access" in result[ "body" ][ 0 ]
def test_export_csv( self ):
self.login()
note_contents = u"blah
foo"
note3 = Note.create( "55", note_contents, notebook_id = self.notebook.object_id )
self.database.save( note3 )
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=csv" % self.notebook.object_id,
session_id = self.session_id,
)
headers = result[ u"headers" ]
assert headers
assert headers[ u"Content-Type" ] == u"text/csv;charset=utf-8"
assert headers[ u"Content-Disposition" ] == 'attachment; filename=%s.csv' % self.notebook.friendly_id
assert result[ u"body" ]
csv_data = result[ u"body" ][ 0 ]
reader = csv.reader( StringIO( csv_data ) )
row = reader.next()
expected_header = [ u"contents", u"title", u"note_id", u"startup", u"username", u"revision_date" ]
assert row == expected_header
expected_note_count = self.database.select_one( int, self.notebook.sql_count_notes() )
note_count = 0
startup_note_allowed = True
previous_revision = None
# assert that startup notes come first, then normal notes in alphabetical order
for row in reader:
note_count += 1
assert len( row ) == len( expected_header )
( contents, title, note_id, startup, username, revision_date ) = row
if startup:
assert startup_note_allowed
else:
startup_note_allowed = False
if previous_revision:
assert revision_date < previous_revision
previous_revision = revision_date
db_note = self.database.load( Note, note_id )
assert db_note
assert contents.decode( "utf8" ) == db_note.contents.strip()
if db_note.title:
assert title.decode( "utf8" ) == db_note.title.strip()
else:
assert not title
assert note_id.decode( "utf8" ) == db_note.object_id
assert startup.decode( "utf8" ) == db_note.startup and u"1" or "0"
assert username.decode( "utf8" ) == ( db_note.user_id and self.user.username or u"" )
assert revision_date.decode( "utf8" ) == unicode( db_note.revision )
assert note_count == expected_note_count
def test_export_csv_without_login( self ):
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
path = "/notebooks/export?notebook_id=%s&format=csv" % self.notebook.object_id
result = self.http_get(
path,
session_id = self.session_id,
)
headers = result.get( "headers" )
assert headers
assert headers.get( "Location" ) == u"http:///login?after_login=%s" % urllib.quote( path )
def test_export_csv_with_unknown_notebook( self ):
self.login()
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=csv" % self.unknown_notebook_id,
session_id = self.session_id,
)
assert u"access" in result[ u"body" ][ 0 ]
def test_export_print( self ):
self.login()
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=print" % self.notebook.object_id,
session_id = self.session_id,
)
assert result.get( "notebook" ).object_id == self.notebook.object_id
assert result.get( "view" )
notes = result.get( "notes" )
assert len( notes ) == self.database.select_one( int, self.notebook.sql_count_notes() )
startup_note_allowed = True
previous_revision = None
# assert that startup notes come first, then normal notes in alphabetical order
for note in notes:
if note.startup:
assert startup_note_allowed
else:
startup_note_allowed = False
if previous_revision:
assert note.revision < previous_revision
previous_revision = note.revision
db_note = self.database.load( Note, note.object_id )
assert db_note
assert note.object_id == db_note.object_id
assert note.revision == db_note.revision
assert note.title == db_note.title
assert note.contents == db_note.contents
assert note.notebook_id == db_note.notebook_id
assert note.startup == db_note.startup
assert note.deleted_from_id == db_note.deleted_from_id
assert note.rank == db_note.rank
assert note.user_id == db_note.user_id
assert note.creation == db_note.creation
def test_export_print_without_login( self ):
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
path = "/notebooks/export?notebook_id=%s&format=print" % self.notebook.object_id
result = self.http_get(
path,
session_id = self.session_id,
)
headers = result.get( "headers" )
assert headers
assert headers.get( "Location" ) == u"http:///login?after_login=%s" % urllib.quote( path )
def test_export_print_with_unknown_notebook( self ):
self.login()
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=print" % self.unknown_notebook_id,
session_id = self.session_id,
)
assert u"access" in result[ "body" ][ 0 ]
def test_export_print_with_note_id( self ):
self.login()
note3 = Note.create( "55", u"blah
foo", notebook_id = self.notebook.object_id )
self.database.save( note3 )
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=print¬e_id=%s" % ( self.notebook.object_id, note3.object_id ),
session_id = self.session_id,
)
assert result.get( "notebook" ) == None
assert result.get( "view" )
notes = result.get( "notes" )
assert len( notes ) == 1
note = notes[ 0 ]
assert note.object_id == note3.object_id
assert note.revision == note3.revision
assert note.title == note3.title
assert note.contents == note3.contents
assert note.notebook_id == note3.notebook_id
assert note.startup == note3.startup
assert note.deleted_from_id == note3.deleted_from_id
assert note.rank == note3.rank
assert note.user_id == note3.user_id
assert note.creation == note3.creation
def test_export_print_with_unknown_note_id( self ):
self.login()
result = self.http_get(
"/notebooks/export?notebook_id=%s&format=print¬e_id=%s" % ( self.notebook.object_id, self.unknown_note_id ),
session_id = self.session_id,
)
assert u"access" in result[ "body" ][ 0 ]
def test_create( self ):
self.login()
result = self.http_post( "/notebooks/create", dict(), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
new_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
notebook = self.database.load( Notebook, new_notebook_id )
assert isinstance( notebook, Notebook )
assert notebook.object_id == new_notebook_id
assert notebook.name == u"new notebook"
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.trash_id
self.user.sql_load_notebooks()
notebooks = self.database.select_many( Notebook, self.user.sql_load_notebooks() )
new_notebook = [ notebook for notebook in notebooks if notebook.object_id == new_notebook_id ][ 0 ]
assert new_notebook.rank == 1
def test_contents_after_create( self ):
self.login()
result = self.http_post( "/notebooks/create", dict(), session_id = self.session_id )
new_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
result = cherrypy.root.notebooks.contents(
notebook_id = new_notebook_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert result[ "total_notes_count" ] == 0
assert result[ "startup_notes" ] == []
assert result[ "notes" ] == []
assert result[ "invites" ] == []
assert notebook.object_id == new_notebook_id
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.tags == []
def test_contents_after_create_with_tag( self ):
self.login()
result = self.http_post( "/notebooks/create", dict(), session_id = self.session_id )
new_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
tag_id = self.database.next_id( Tag, commit = False )
new_tag = Tag.create(
tag_id,
notebook_id = None, # this tag is not in the namespace of a single notebook
user_id = self.user.object_id,
name = u"mytag",
description = u"some tag"
)
self.database.save( new_tag, commit = False )
self.database.execute(
self.user.sql_save_notebook_tag( new_notebook_id, new_tag.object_id, value = u"myvalue" ),
commit = False,
)
self.database.commit()
result = cherrypy.root.notebooks.contents(
notebook_id = new_notebook_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert result[ "total_notes_count" ] == 0
assert result[ "startup_notes" ] == []
assert result[ "notes" ] == []
assert result[ "invites" ] == []
assert notebook.object_id == new_notebook_id
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.tags
assert len( notebook.tags ) == 1
tag = notebook.tags[ 0 ]
assert tag.object_id == new_tag.object_id
assert tag.notebook_id == new_tag.notebook_id
assert tag.user_id == new_tag.user_id
assert tag.name == new_tag.name
assert tag.description == new_tag.description
def test_contents_after_create_with_anonymous_tag( self ):
self.login()
result = self.http_post( "/notebooks/create", dict(), session_id = self.session_id )
new_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
tag_id = self.database.next_id( Tag, commit = False )
new_tag = Tag.create(
tag_id,
notebook_id = None, # this tag is not in the namespace of a single notebook
user_id = self.anonymous.object_id,
name = u"mytag",
description = u"some tag"
)
self.database.save( new_tag, commit = False )
self.database.execute(
self.anonymous.sql_save_notebook_tag( new_notebook_id, new_tag.object_id, value = u"myvalue" ),
commit = False,
)
self.database.commit()
result = cherrypy.root.notebooks.contents(
notebook_id = new_notebook_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert result[ "total_notes_count" ] == 0
assert result[ "startup_notes" ] == []
assert result[ "notes" ] == []
assert result[ "invites" ] == []
assert notebook.object_id == new_notebook_id
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.tags
assert len( notebook.tags ) == 1
tag = notebook.tags[ 0 ]
assert tag.object_id == new_tag.object_id
assert tag.notebook_id == new_tag.notebook_id
assert tag.user_id == new_tag.user_id
assert tag.name == new_tag.name
assert tag.description == new_tag.description
def test_create_without_login( self ):
result = self.http_post( "/notebooks/create", dict() )
assert result[ u"error" ]
def test_rename( self ):
self.login()
new_name = u"renamed notebook"
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
assert u"error" not in result
def test_contents_after_rename( self ):
self.login()
new_name = u"renamed notebook"
self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert notebook.name == new_name
assert notebook.user_id == self.user.object_id
def test_contents_after_rename_read_only_for_own_notes( self ):
self.login()
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
new_name = u"renamed notebook"
self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert notebook.name == new_name
assert notebook.user_id == self.user.object_id
def test_contents_after_rename_read_only_for_own_notes( self ):
self.login()
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
new_name = u"renamed notebook"
self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert notebook.name == new_name
assert notebook.user_id == self.user.object_id
def test_contents_after_rename_read_only_for_own_notes_without_access( self ):
self.login2()
self.database.execute( self.user2.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
new_name = u"renamed notebook"
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_rename_without_login( self ):
new_name = u"renamed notebook"
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
) )
assert u"access" in result[ u"error" ]
def test_rename_without_access( self ):
self.login()
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_ONLY, owner = False,
) )
new_name = u"renamed notebook"
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
) )
assert u"access" in result[ u"error" ]
def test_rename_trash( self ):
self.login()
new_name = u"renamed notebook"
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.trash_id,
name = new_name,
), session_id = self.session_id )
assert u"error" in result
def test_rename_with_reserved_luminotes_name( self ):
self.login()
new_name = u"Luminotes blog"
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
assert result[ u"error" ]
def test_rename_with_reserved_trash_name( self ):
self.login()
new_name = u" trash "
result = self.http_post( "/notebooks/rename", dict(
notebook_id = self.notebook.object_id,
name = new_name,
), session_id = self.session_id )
assert result[ u"error" ]
def test_delete( self ):
self.login()
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# assert that we're redirected to a newly created notebook
remaining_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
notebook = self.database.load( Notebook, remaining_notebook_id )
assert isinstance( notebook, Notebook )
assert notebook.object_id == remaining_notebook_id
assert notebook.name == u"my notebook"
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.trash_id
assert notebook.user_id == self.user.object_id
def test_delete_with_remaining_notebook( self ):
# create a second notebook, which we should be redirected to after the first notebook is deleted
trash = Notebook.create( self.database.next_id( Notebook ), u"trash" )
self.database.save( trash, commit = False )
notebook = Notebook.create( self.database.next_id( Notebook ), u"notebook", trash.object_id )
self.database.save( notebook, commit = False )
self.database.execute( self.user.sql_save_notebook( notebook.object_id, read_write = True, owner = True, rank = 1 ) )
self.database.execute( self.user.sql_save_notebook( notebook.trash_id, read_write = True, owner = True, rank = 1 ) )
self.database.commit()
self.login()
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# assert that we're redirected to the second notebook
remaining_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
assert remaining_notebook_id
assert remaining_notebook_id == notebook.object_id
def test_delete_with_remaining_read_only_notebook( self ):
# create a second read-only notebook, which we should NOT be redirected to after the first
# notebook is deleted
trash = Notebook.create( self.database.next_id( Notebook ), u"trash" )
self.database.save( trash, commit = False )
notebook = Notebook.create( self.database.next_id( Notebook ), u"notebook", trash.object_id )
self.database.save( notebook, commit = False )
self.database.execute( self.user.sql_save_notebook( notebook.object_id, read_write = False, owner = False, rank = 1 ) )
self.database.execute( self.user.sql_save_notebook( notebook.trash_id, read_write = False, owner = False, rank = 1 ) )
self.database.commit()
self.login()
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# assert that we're redirected to a newly created notebook
remaining_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
notebook = self.database.load( Notebook, remaining_notebook_id )
assert isinstance( notebook, Notebook )
assert notebook.object_id == remaining_notebook_id
assert notebook.name == u"my notebook"
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.trash_id
assert notebook.user_id == self.user.object_id
def test_contents_after_delete( self ):
self.login()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert notebook.deleted == True
assert notebook.user_id == self.user.object_id
def test_contents_after_delete_twice( self ):
self.login()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert notebook.deleted == True
assert notebook.user_id == self.user.object_id
def test_delete_without_login( self ):
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"error" ]
def test_delete_trash( self ):
self.login()
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.trash_id,
), session_id = self.session_id )
assert u"error" in result
def test_delete_forever( self ):
self.login()
result = self.http_post( "/notebooks/delete_forever", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"error" not in result
@raises( Access_error )
def test_contents_after_delete_forever( self ):
self.login()
self.http_post( "/notebooks/delete_forever", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
def test_delete_then_delete_forever( self ):
self.login()
result = self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/delete_forever", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"error" not in result
@raises( Access_error )
def test_contents_after_delete_then_delete_forever( self ):
self.login()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
self.http_post( "/notebooks/delete_forever", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
def test_delete_forever_without_login( self ):
result = self.http_post( "/notebooks/delete_forever", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"error" ]
def test_delete_forever_trash( self ):
self.login()
result = self.http_post( "/notebooks/delete_forever", dict(
notebook_id = self.notebook.trash_id,
), session_id = self.session_id )
assert u"error" in result
def test_undelete( self ):
self.login()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# assert that we're redirected to the undeleted notebook
notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ]
notebook = self.database.load( Notebook, notebook_id )
assert isinstance( notebook, Notebook )
assert notebook.object_id == notebook_id
assert notebook.name == self.notebook.name
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.trash_id
assert notebook.user_id == self.user.object_id
def test_contents_after_undelete( self ):
self.login()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = cherrypy.root.notebooks.contents(
notebook_id = self.notebook.object_id,
user_id = self.user.object_id,
)
notebook = result[ "notebook" ]
assert notebook.deleted == False
assert notebook.user_id == self.user.object_id
def test_undelete_without_login( self ):
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_undelete_own_notes( self ):
self.login()
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_undelete_twice( self ):
self.login()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
self.http_post( "/notebooks/undelete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/undelete", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# assert that we're redirected to the undeleted notebook
notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ]
notebook = self.database.load( Notebook, notebook_id )
assert isinstance( notebook, Notebook )
assert notebook.object_id == notebook_id
assert notebook.name == self.notebook.name
assert notebook.read_write == Notebook.READ_WRITE
assert notebook.owner == True
assert notebook.trash_id
assert notebook.user_id == self.user.object_id
def test_move_up( self ):
self.login()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_up", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
assert u"error" not in result
notebooks = self.database.select_many( Notebook, self.user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
assert notebooks
assert len( notebooks ) == 3
assert notebooks[ 0 ].object_id == self.notebook2.object_id
assert notebooks[ 0 ].rank == 0
assert notebooks[ 1 ].object_id == self.notebook.object_id
assert notebooks[ 1 ].rank == 1
assert notebooks[ 2 ].object_id == self.notebook3.object_id
assert notebooks[ 2 ].rank == 2
def test_move_up_and_wrap( self ):
self.login()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_up", dict(
notebook_id = self.notebook.object_id,
), session_id = self.session_id )
assert u"error" not in result
notebooks = self.database.select_many( Notebook, self.user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
assert notebooks
assert len( notebooks ) == 3
assert notebooks[ 0 ].object_id == self.notebook2.object_id
assert notebooks[ 0 ].rank == 1
assert notebooks[ 1 ].object_id == self.notebook3.object_id
assert notebooks[ 1 ].rank == 2
assert notebooks[ 2 ].object_id == self.notebook.object_id
assert notebooks[ 2 ].rank == 3
def test_move_up_without_login( self ):
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_up", dict(
notebook_id = self.notebook2.object_id,
) )
assert u"access" in result[ u"error" ]
def test_move_up_without_access( self ):
self.login2()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_up", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_move_up_trash( self ):
self.login()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_up", dict(
notebook_id = self.trash.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_move_up_deleted_notebook( self ):
self.login()
self.make_extra_notebooks()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/move_up", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_move_down( self ):
self.login()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_down", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
assert u"error" not in result
notebooks = self.database.select_many( Notebook, self.user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
assert notebooks
assert len( notebooks ) == 3
assert notebooks[ 0 ].object_id == self.notebook.object_id
assert notebooks[ 0 ].rank == 0
assert notebooks[ 1 ].object_id == self.notebook3.object_id
assert notebooks[ 1 ].rank == 1
assert notebooks[ 2 ].object_id == self.notebook2.object_id
assert notebooks[ 2 ].rank == 2
def test_move_down_and_wrap( self ):
self.login()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_down", dict(
notebook_id = self.notebook3.object_id,
), session_id = self.session_id )
assert u"error" not in result
notebooks = self.database.select_many( Notebook, self.user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
assert notebooks
assert len( notebooks ) == 3
assert notebooks[ 0 ].object_id == self.notebook3.object_id
assert notebooks[ 0 ].rank == -1
assert notebooks[ 1 ].object_id == self.notebook.object_id
assert notebooks[ 1 ].rank == 0
assert notebooks[ 2 ].object_id == self.notebook2.object_id
assert notebooks[ 2 ].rank == 1
def test_move_down_without_login( self ):
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_down", dict(
notebook_id = self.notebook2.object_id,
) )
assert u"access" in result[ u"error" ]
def test_move_down_without_access( self ):
self.login2()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_down", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_move_down_trash( self ):
self.login()
self.make_extra_notebooks()
result = self.http_post( "/notebooks/move_down", dict(
notebook_id = self.trash.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_move_down_deleted_notebook( self ):
self.login()
self.make_extra_notebooks()
self.http_post( "/notebooks/delete", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
result = self.http_post( "/notebooks/move_down", dict(
notebook_id = self.notebook2.object_id,
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_recent_notes( self ):
result = cherrypy.root.notebooks.recent_notes(
self.notebook.object_id,
user_id = self.user.object_id,
)
assert result.get( u"user" ).object_id == self.user.object_id
assert len( result.get( u"notebooks" ) ) == 1
assert result.get( u"login_url" ) is None
assert result.get( u"logout_url" )
assert result.get( u"rate_plan" )
assert result.get( u"notebook" ).object_id == self.notebook.object_id
assert len( result.get( u"startup_notes" ) ) == 1
assert result[ "total_notes_count" ] == 2
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 2
assert notes[ 0 ].object_id == self.note2.object_id
assert notes[ 1 ].object_id == self.note.object_id
assert result.get( u"parent_id" ) == None
assert result.get( u"note_read_write" ) in ( None, True )
assert result.get( u"start" ) == 0
assert result.get( u"count" ) == 10
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_recent_notes_with_start( self ):
result = cherrypy.root.notebooks.recent_notes(
self.notebook.object_id,
start = 1,
user_id = self.user.object_id,
)
assert result.get( u"user" ).object_id == self.user.object_id
assert len( result.get( u"notebooks" ) ) == 1
assert result.get( u"login_url" ) is None
assert result.get( u"logout_url" )
assert result.get( u"rate_plan" )
assert result.get( u"notebook" ).object_id == self.notebook.object_id
assert len( result.get( u"startup_notes" ) ) == 1
assert result[ "total_notes_count" ] == 2
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note.object_id
assert result.get( u"parent_id" ) == None
assert result.get( u"note_read_write" ) in ( None, True )
assert result.get( u"start" ) == 1
assert result.get( u"count" ) == 10
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_recent_notes_with_count( self ):
result = cherrypy.root.notebooks.recent_notes(
self.notebook.object_id,
count = 1,
user_id = self.user.object_id,
)
assert result.get( u"user" ).object_id == self.user.object_id
assert len( result.get( u"notebooks" ) ) == 1
assert result.get( u"login_url" ) is None
assert result.get( u"logout_url" )
assert result.get( u"rate_plan" )
assert result.get( u"notebook" ).object_id == self.notebook.object_id
assert len( result.get( u"startup_notes" ) ) == 1
assert result[ "total_notes_count" ] == 2
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note2.object_id
assert result.get( u"parent_id" ) == None
assert result.get( u"note_read_write" ) in ( None, True )
assert result.get( u"start" ) == 0
assert result.get( u"count" ) == 1
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
@raises( Access_error )
def test_recent_notes_with_unknown_notebok( self ):
result = cherrypy.root.notebooks.recent_notes(
self.unknown_notebook_id,
user_id = self.user.object_id,
)
@raises( Access_error )
def test_recent_notes_with_incorrect_user( self ):
result = cherrypy.root.notebooks.recent_notes(
self.notebook.object_id,
user_id = self.anonymous.object_id,
)
def test_old_notes( self ):
result = cherrypy.root.notebooks.old_notes(
self.notebook.object_id,
user_id = self.user.object_id,
)
assert result.get( u"user" ).object_id == self.user.object_id
assert len( result.get( u"notebooks" ) ) == 1
assert result.get( u"login_url" ) is None
assert result.get( u"logout_url" )
assert result.get( u"rate_plan" )
assert result.get( u"notebook" ).object_id == self.notebook.object_id
assert len( result.get( u"startup_notes" ) ) == 1
assert result[ "total_notes_count" ] == 2
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 2
assert notes[ 0 ].object_id == self.note.object_id
assert notes[ 1 ].object_id == self.note2.object_id
assert result.get( u"parent_id" ) == None
assert result.get( u"note_read_write" ) in ( None, True )
assert result.get( u"start" ) == 0
assert result.get( u"count" ) == 10
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_old_notes_with_start( self ):
result = cherrypy.root.notebooks.old_notes(
self.notebook.object_id,
start = 1,
user_id = self.user.object_id,
)
assert result.get( u"user" ).object_id == self.user.object_id
assert len( result.get( u"notebooks" ) ) == 1
assert result.get( u"login_url" ) is None
assert result.get( u"logout_url" )
assert result.get( u"rate_plan" )
assert result.get( u"notebook" ).object_id == self.notebook.object_id
assert len( result.get( u"startup_notes" ) ) == 1
assert result[ "total_notes_count" ] == 2
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note2.object_id
assert result.get( u"parent_id" ) == None
assert result.get( u"note_read_write" ) in ( None, True )
assert result.get( u"start" ) == 1
assert result.get( u"count" ) == 10
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_old_notes_with_count( self ):
result = cherrypy.root.notebooks.old_notes(
self.notebook.object_id,
count = 1,
user_id = self.user.object_id,
)
assert result.get( u"user" ).object_id == self.user.object_id
assert len( result.get( u"notebooks" ) ) == 1
assert result.get( u"login_url" ) is None
assert result.get( u"logout_url" )
assert result.get( u"rate_plan" )
assert result.get( u"notebook" ).object_id == self.notebook.object_id
assert len( result.get( u"startup_notes" ) ) == 1
assert result[ "total_notes_count" ] == 2
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note.object_id
assert result.get( u"parent_id" ) == None
assert result.get( u"note_read_write" ) in ( None, True )
assert result.get( u"start" ) == 0
assert result.get( u"count" ) == 1
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
@raises( Access_error )
def test_old_notes_with_unknown_notebok( self ):
result = cherrypy.root.notebooks.old_notes(
self.unknown_notebook_id,
user_id = self.user.object_id,
)
@raises( Access_error )
def test_old_notes_with_incorrect_user( self ):
result = cherrypy.root.notebooks.old_notes(
self.notebook.object_id,
user_id = self.anonymous.object_id,
)
def test_load_recent_updates( self ):
self.login()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook.object_id ),
( "start", "0" ),
( "count", "10" ),
] ),
session_id = self.session_id,
)
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 2
assert notes[ 0 ].object_id == self.note2.object_id
assert notes[ 1 ].object_id == self.note.object_id
def test_load_recent_updates_with_non_default_start( self ):
self.login()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook.object_id ),
( "start", "1" ),
( "count", "10" ),
] ),
session_id = self.session_id,
)
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note.object_id
def test_load_recent_updates_with_too_small_start( self ):
self.login()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook.object_id ),
( "start", "-1" ),
( "count", "10" ),
] ),
session_id = self.session_id,
)
assert u"too small" in result[ "error" ]
def test_load_recent_updates_with_non_default_count( self ):
self.login()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook.object_id ),
( "start", "0" ),
( "count", "1" ),
] ),
session_id = self.session_id,
)
notes = result.get( u"notes" )
assert notes
assert len( notes ) == 1
assert notes[ 0 ].object_id == self.note2.object_id
def test_load_recent_updates_with_too_small_count( self ):
self.login()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook.object_id ),
( "start", "0" ),
( "count", "0" ),
] ),
session_id = self.session_id,
)
assert u"too small" in result[ "error" ]
def test_load_recent_updates_without_login( self ):
path = "/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook.object_id ),
( "start", "0" ),
( "count", "10" ),
] )
result = self.http_get( path )
headers = result.get( "headers" )
assert headers
assert headers.get( "Location" ) == u"http:///login?after_login=%s" % urllib.quote( path )
def test_load_recent_updates_without_access( self ):
self.login2()
self.make_extra_notebooks()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.notebook2.object_id ),
( "start", "0" ),
( "count", "10" ),
] ),
session_id = self.session_id,
)
assert u"access" in result[ "error" ]
def test_load_recent_updates_with_unknown_notebook( self ):
self.login()
result = self.http_get(
"/notebooks/load_recent_updates?%s" % urllib.urlencode( [
( "notebook_id", self.unknown_notebook_id ),
( "start", "0" ),
( "count", "10" ),
] ),
session_id = self.session_id,
)
assert u"access" in result[ "error" ]
def test_import_csv( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3" ), # ( title, contents )
( "whee", "hmm\nfoo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
LINK_PATTERN = re.compile( ']*)>([^<]*)', re.IGNORECASE )
NOTE_URL_PATTERN = re.compile( '([^"]*)/notebooks/(\w+)\?note_id=(\w+)', re.IGNORECASE )
def __assert_imported_notebook( self, expected_notes, result, plaintext = True ):
assert result[ u"redirect" ].startswith( u"/notebooks/" )
# make sure that a notebook has been created with the imported notes
new_notebook_id = result[ u"redirect" ].split( u"/notebooks/" )[ -1 ].split( u"?" )[ 0 ]
notebook = self.database.load( Notebook, new_notebook_id )
assert notebook.name == u"imported notebook"
assert notebook.trash_id
assert notebook.read_write is Notebook.READ_WRITE
assert notebook.owner is True
assert notebook.deleted is False
assert notebook.user_id == self.user.object_id
assert notebook.rank is None
result = self.http_get(
"/notebooks/%s" % notebook.object_id,
session_id = self.session_id,
)
recent_notes = result.get( "recent_notes" )
assert recent_notes
assert len( recent_notes ) == len( expected_notes )
# reverse the recent notes because they're in reverse chronological order
recent_notes.reverse()
for ( note, ( title, contents ) ) in zip( recent_notes, expected_notes ):
assert note.title == title
if plaintext is True:
contents = contents.replace( u"\n", u"
" )
if plaintext is True or u"" not in contents:
contents = u"%s
%s" % ( title, contents )
if plaintext is False:
link_match = self.LINK_PATTERN.search( contents )
# if there's a link, make sure it is a rewritten note link or has a link target
if link_match:
( url, attributes, title ) = link_match.groups()
url_match = self.NOTE_URL_PATTERN.search( url )
if url_match:
imported_notebook = self.database.select_one( Notebook, "select * from notebook where name = 'imported notebook' limit 1;" )
( protocol_and_host, notebook_id, note_id ) = url_match.groups()
assert attributes == u""
assert protocol_and_host == u""
# assert that the link has been rewritten to point to a note in the new notebook
assert note_id
rewritten_note = self.database.load( Note, note_id )
if rewritten_note:
assert rewritten_note.notebook_id == imported_notebook.object_id
assert notebook_id == imported_notebook.object_id
else:
assert notebook_id == self.notebook.object_id
else:
assert attributes.startswith( u'target="' )
assert note.contents == contents
# make sure the CSV data file has been deleted from the database and filesystem
db_file = self.database.load( File, self.file_id )
assert db_file is None
assert not Upload_file.exists( self.file_id )
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes > 0
def test_import_csv_own_notes( self ):
self.login()
self.database.execute( self.user.sql_update_access(
self.notebook.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES, owner = False,
) )
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3" ), # ( title, contents )
( "whee", "hmm\nfoo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_import_csv_title_already_in_contents( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","yay
3.3"\n"8","whee","hmm\nmy title
foo"\n3,4,5'
expected_notes = [
( "yay", "yay
3.3" ), # ( title, contents )
( "my title", "hmm\nmy title
foo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_title_already_in_plaintext_contents( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","hi\nyay
3.3"\n"8","whee","hmm\nmy title
foo"\n3,4,5'
expected_notes = [
( "blah and stuff", "hi
<h3>yay</h3>3.3" ), # ( title, contents )
( "whee", "hmm
<h3>my title</h3>foo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = True )
def test_import_csv_unknown_file_id( self ):
self.login()
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = u"unknownfileid",
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_import_csv_content_column_too_high( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 5,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
assert u"import" in result[ u"error" ]
def test_import_csv_title_column_too_high( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 5,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
assert u"import" in result[ u"error" ]
def test_import_csv_same_title_and_content_columns( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "3.3", "3.3" ), # ( title, contents )
( "hmm", "hmm\nfoo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 2,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_html_in_plaintext_title( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff
",3.3\n"8","whee
","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah <i>and</i> stuff<br />", "3.3" ), # ( title, contents )
( "whee<p>", "hmm\nfoo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_no_title_column( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "3.3", "3.3" ), # ( title, contents )
( "hmm", "hmm\nfoo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_no_title_column_and_title_already_in_contents( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","
yay
3.3"\n"8","whee","hmm\nmy title
foo"\n3,4,5'
expected_notes = [
( "yay", "yay
3.3" ), # ( title, contents )
( "my title", "hmm\nmy title
foo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_no_title_column_and_title_already_in_plaintext_contents( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","hi\nyay
3.3"\n"8","whee","hmm\nmy title
foo"\n3,4,5'
expected_notes = [
( "hi", "hi
<h3>yay</h3>3.3" ), # ( title, contents )
( "hmm", "hmm
<h3>my title</h3>foo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = True )
def test_import_csv_no_title_column_and_html_first_line( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","3 < 4"\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "3 < 4<img>", "3 < 4<img>" ), # ( title, contents )
( "<b>hmm</b>", "<b>hmm</b>\nfoo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_no_title_column_and_long_first_line( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","Ten percent of nuthin\' is...let me do the math here...nuthin\' into nuthin\'...carry the nuthin\'..."\n"8","whee","I brought you some supper but if you\'d prefer a lecture, I\'ve a few very catchy ones prepped...sin and hellfire... one has lepers.\n--Book"\n3,4,5'
# expect the long titles to be truncated on a word boundary
expected_notes = [
( "Ten percent of nuthin' is...let me do the math here...nuthin' into", "Ten percent of nuthin' is...let me do the math here...nuthin' into nuthin'...carry the nuthin'..." ),
( "I brought you some supper but if you'd prefer a lecture, I've a few very catchy", "I brought you some supper but if you'd prefer a lecture, I've a few very catchy ones prepped...sin and hellfire... one has lepers.\n--Book" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_no_title_column_and_long_first_line_without_spaces( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"\n"8","whee","ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\nfoo"\n3,4,5'
# expect the long titles not to be truncated since there are no spaces
expected_notes = [
( "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" ),
( "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ", "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\nfoo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_no_title_column_and_blank_first_line( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","\n\n3.3"\n"8","whee","\nfoo"\n3,4,5'
expected_notes = [
( "3.3", "3.3" ), # ( title, contents )
( "foo", "foo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_no_title_column_and_empty_contents( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","\n\n\n \n"\n"8","whee","foo"\n3,4,5'
expected_notes = [
( "foo", "foo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result )
def test_import_csv_plaintext_content_as_html( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3" ), # ( title, contents )
( "whee", "hmm\nfoo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_title( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","wh ee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3" ), # ( title, contents )
( "wh ee", "hmm\nfoo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","3.3 "\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "whee", "hmm\nfoo" ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_without_title( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","3.3 "\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "3.3", "3.3 " ), # ( title, contents )
( "hmm", "hmm\nfoo" ),
( "5", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = None,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_link( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","3.3 "\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "whee", 'hmm\nfoo' ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_link_and_target( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff","3.3 "\n"8","whee","hmm\nfoo"\n3,4,5'
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "whee", 'hmm\nfoo' ),
( "4", "5" ),
]
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_internal_note_link( self ):
self.login()
# one of the imported notes contains a link to one of the other imported notes
note_url = "/notebooks/%s?note_id=%s" % ( self.notebook.object_id, "idthree" )
csv_data = '"label 1","label 2","label 3","note_id",\n5,"blah and stuff","3.3 ",idone\n"8","whee","hmm\nfoo",idtwo\n3,4,5,idthree' % note_url
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
notebook = self.database.select_one( Notebook, "select * from notebook where name = 'imported notebook' limit 1;" )
note = self.database.select_one( Note, notebook.sql_load_note_by_title( u"4" ) )
rewritten_note_url = "/notebooks/%s?note_id=%s" % ( notebook.object_id, note.object_id )
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "4", "5" ),
( "whee", 'hmm\nfoo' % rewritten_note_url ),
]
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_internal_note_link_with_full_protocol( self ):
self.login()
# one of the imported notes contains a link to one of the other imported notes
note_url = "http://localhost:8081/notebooks/%s?note_id=%s" % ( self.notebook.object_id, "idthree" )
csv_data = '"label 1","label 2","label 3","note_id",\n5,"blah and stuff","3.3 ",idone\n"8","whee","hmm\nfoo",idtwo\n3,4,5,idthree' % note_url
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
notebook = self.database.select_one( Notebook, "select * from notebook where name = 'imported notebook' limit 1;" )
note = self.database.select_one( Note, notebook.sql_load_note_by_title( u"4" ) )
rewritten_note_url = "/notebooks/%s?note_id=%s" % ( notebook.object_id, note.object_id )
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "4", "5" ),
( "whee", 'hmm\nfoo' % rewritten_note_url ),
]
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_internal_note_link_and_blank_note_id_value( self ):
self.login()
# one of the imported notes contains a link to one of the other imported notes
note_url = "/notebooks/%s?note_id=%s" % ( self.notebook.object_id, "idthree" )
csv_data = '"label 1","label 2","label 3","note_id",\n5,"blah and stuff","3.3 ",\n"8","whee","hmm\nfoo",idtwo\n3,4,5,idthree' % note_url
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
notebook = self.database.select_one( Notebook, "select * from notebook where name = 'imported notebook' limit 1;" )
note = self.database.select_one( Note, notebook.sql_load_note_by_title( u"4" ) )
rewritten_note_url = "/notebooks/%s?note_id=%s" % ( notebook.object_id, note.object_id )
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "4", "5" ),
( "whee", 'hmm\nfoo' % rewritten_note_url ),
]
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_internal_note_link_to_unknown_note( self ):
self.login()
# one of the imported notes contains a link to one of the other imported notes
note_url = "/notebooks/%s?note_id=%s" % ( self.notebook.object_id, "idunknown" )
csv_data = '"label 1","label 2","label 3","note_id",\n5,"blah and stuff","3.3 ",idone\n"8","whee","hmm\nfoo",idtwo\n3,4,5,idthree' % note_url
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "4", "5" ),
( "whee", 'hmm\nfoo' % note_url ), # the note url should not be rewritten
]
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_html_content_with_internal_note_link_without_note_id_column( self ):
self.login()
# one of the imported notes contains a link to one of the other imported notes
note_url = "/notebooks/%s?note_id=%s" % ( self.notebook.object_id, "idthree" )
csv_data = '"label 1","label 2","label 3",\n5,"blah and stuff","3.3 "\n"8","whee","hmm\nfoo"\n3,4,5' % note_url
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = False,
import_button = u"import",
), session_id = self.session_id )
expected_notes = [
( "blah and stuff", "3.3 " ), # ( title, contents )
( "whee", 'hmm\nfoo' % note_url ), # the note url should not be rewritten
( "4", "5" ),
]
self.__assert_imported_notebook( expected_notes, result, plaintext = False )
def test_import_csv_without_login( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
) )
assert u"access" in result[ u"error" ]
def test_import_csv_without_access( self ):
self.login()
self.make_extra_notebooks()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",3.3\n"8","whee","hmm\nfoo"\n3,4,5'
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook2.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
self.login2()
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
assert u"access" in result[ u"error" ]
def test_import_csv_invalid( self ):
self.login()
csv_data = '"label 1","label 2","label 3"\n5,"blah and stuff",,,,,,3.3\n"8","whee","hmm\nfoo"\n3,4,5'
self.http_upload(
"/files/upload?X-Progress-ID=%s" % self.file_id,
dict(
notebook_id = self.notebook.object_id,
note_id = self.note.object_id,
),
filename = self.filename,
file_data = csv_data,
content_type = self.content_type,
session_id = self.session_id,
)
result = self.http_post( "/notebooks/import_csv/", dict(
file_id = self.file_id,
content_column = 2,
title_column = 1,
plaintext = True,
import_button = u"import",
), session_id = self.session_id )
assert result[ u"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" ]
def login2( self ):
result = self.http_post( "/users/login", dict(
username = self.username2,
password = self.password2,
login_button = u"login",
) )
self.session_id = result[ u"session_id" ]