Unit tests for notebook printing.
This commit is contained in:
parent
c282570539
commit
73325f17fb
3
NEWS
3
NEWS
|
@ -1,5 +1,6 @@
|
|||
1.6.8: ?
|
||||
* Added a link to print your entire notebook.
|
||||
* You can now print your entire notebook. Just click the link on the left
|
||||
side of the page.
|
||||
* Changed the order of exported HTML and CSV notebooks so that after all the
|
||||
"startup" notes are included, the remaining notes are included in
|
||||
alphabetical order (instead of reverse chronological order).
|
||||
|
|
|
@ -4639,11 +4639,11 @@ class Test_notebooks( Test_controller ):
|
|||
self.login()
|
||||
|
||||
result = self.http_get(
|
||||
"/notebooks/export_html/%s" % self.unknown_notebook_id,
|
||||
"/notebooks/export?notebook_id=%s&format=html" % self.unknown_notebook_id,
|
||||
session_id = self.session_id,
|
||||
)
|
||||
|
||||
assert result.get( "error" )
|
||||
assert u"access" in result[ "body" ][ 0 ]
|
||||
|
||||
def test_export_csv( self ):
|
||||
self.login()
|
||||
|
@ -4733,6 +4733,74 @@ class Test_notebooks( Test_controller ):
|
|||
|
||||
assert u"access" in result[ u"body" ][ 0 ]
|
||||
|
||||
def test_export_print( self ):
|
||||
self.login()
|
||||
|
||||
note3 = Note.create( "55", u"<h3>blah</h3>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"<h3>blah</h3>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_create( self ):
|
||||
self.login()
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
import types
|
||||
import cherrypy
|
||||
from cStringIO import StringIO
|
||||
from pysqlite2 import dbapi2 as sqlite
|
||||
|
||||
from model.User import User
|
||||
from model.Note import Note
|
||||
from model.Notebook import Notebook
|
||||
from controller.Database import Database, Connection_wrapper
|
||||
from controller.test.Stub_cache import Stub_cache
|
||||
from plugins.Invoke import invoke
|
||||
|
||||
|
||||
class Test_export_html( object ):
|
||||
def setUp( self ):
|
||||
self.database = Database(
|
||||
Connection_wrapper( sqlite.connect( ":memory:", detect_types = sqlite.PARSE_DECLTYPES, check_same_thread = False ) ),
|
||||
cache = Stub_cache(),
|
||||
)
|
||||
self.database.execute_script( file( "model/schema.sqlite" ).read(), commit = True )
|
||||
|
||||
self.username = u"mulder"
|
||||
self.password = u"trustno1"
|
||||
self.email_address = u"outthere@example.com"
|
||||
self.user = User.create( self.database.next_id( User ), self.username, self.password, self.email_address )
|
||||
self.database.save( self.user, commit = False )
|
||||
|
||||
self.trash = Notebook.create( self.database.next_id( Notebook ), u"trash" )
|
||||
self.database.save( self.trash, commit = False )
|
||||
self.notebook = Notebook.create( self.database.next_id( Notebook ), u"notebook", self.trash.object_id, user_id = self.user.object_id )
|
||||
self.database.save( self.notebook, commit = False )
|
||||
|
||||
note_id = self.database.next_id( Note )
|
||||
self.note1 = Note.create( note_id, u"<h3>my title</h3>blah", notebook_id = self.notebook.object_id, startup = True, user_id = self.user.object_id )
|
||||
self.database.save( self.note1, commit = False )
|
||||
|
||||
note_id = self.database.next_id( Note )
|
||||
self.note2 = Note.create( note_id, u"<h3>other title</h3>whee", notebook_id = self.notebook.object_id, user_id = self.user.object_id )
|
||||
self.database.save( self.note2, commit = False )
|
||||
|
||||
def test_export_print( self ):
|
||||
note3 = Note.create( "55", u"<h3>blah</h3>foo", notebook_id = self.notebook.object_id )
|
||||
self.database.save( note3 )
|
||||
response_headers = {}
|
||||
expected_notes = ( self.note1, self.note2, note3 )
|
||||
|
||||
result = invoke(
|
||||
"export",
|
||||
"print",
|
||||
self.database,
|
||||
self.notebook,
|
||||
expected_notes,
|
||||
response_headers,
|
||||
)
|
||||
|
||||
# response headers should be unchanged
|
||||
assert response_headers == {}
|
||||
|
||||
notes = result.get( "notes" )
|
||||
assert len( notes ) == len( expected_notes )
|
||||
|
||||
# assert that the notes are in the expected order
|
||||
for ( note, expected_note ) in zip( notes, expected_notes ):
|
||||
assert note.object_id == expected_note.object_id
|
||||
assert note.revision == expected_note.revision
|
||||
assert note.title == expected_note.title
|
||||
assert note.contents == expected_note.contents
|
||||
assert note.notebook_id == expected_note.notebook_id
|
||||
assert note.startup == expected_note.startup
|
||||
assert note.deleted_from_id == expected_note.deleted_from_id
|
||||
assert note.rank == expected_note.rank
|
||||
assert note.user_id == expected_note.user_id
|
||||
assert note.creation == expected_note.creation
|
Reference in New Issue