Additional unit tests.
This commit is contained in:
parent
3f5d5d2a89
commit
7b76d6371b
|
@ -152,7 +152,10 @@ class FieldStorage( cherrypy._cpcgifs.FieldStorage ):
|
|||
|
||||
# release the cherrypy session lock so that the user can issue other commands while the file is
|
||||
# uploading
|
||||
cherrypy.session.release_lock()
|
||||
try:
|
||||
cherrypy.session.release_lock()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# pluck the file id out of the query string. it would be preferable to grab it out of parsed
|
||||
# form variables instead, but at this point in the processing, all the form variables might not
|
||||
|
@ -246,7 +249,10 @@ class Files( object ):
|
|||
"""
|
||||
# release the session lock before beginning to stream the download. otherwise, if the
|
||||
# upload is cancelled before it's done, the lock won't be released
|
||||
cherrypy.session.release_lock()
|
||||
try:
|
||||
cherrypy.session.release_lock()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
db_file = self.__database.load( File, file_id )
|
||||
|
||||
|
@ -398,7 +404,10 @@ class Files( object ):
|
|||
"""
|
||||
# release the session lock before beginning to stream the upload report. otherwise, if the
|
||||
# upload is cancelled before it's done, the lock won't be released
|
||||
cherrypy.session.release_lock()
|
||||
try:
|
||||
cherrypy.session.release_lock()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# poll until the file is uploading (as determined by current_uploads) or completely uploaded (in
|
||||
# the database with a filename)
|
||||
|
|
|
@ -342,8 +342,15 @@ class Test_controller( object ):
|
|||
self.database = Stub_database()
|
||||
self.settings = {
|
||||
u"global": {
|
||||
u"server.environment": "production",
|
||||
u"session_filter.on": True,
|
||||
u"session_filter.storage_type": u"ram",
|
||||
u"session_filter.locking": "implicit",
|
||||
u"encoding_filter.on": True,
|
||||
u"encoding_filter.encoding": "utf-8",
|
||||
u"decoding_filter.on": True,
|
||||
u"decoding_filter.encoding": "utf-8",
|
||||
u"server.log_to_screen": False,
|
||||
u"luminotes.http_url" : u"http://luminotes.com",
|
||||
u"luminotes.https_url" : u"https://luminotes.com",
|
||||
u"luminotes.http_proxy_ip" : u"127.0.0.1",
|
||||
|
@ -377,8 +384,7 @@ class Test_controller( object ):
|
|||
}
|
||||
|
||||
cherrypy.root = Root( self.database, self.settings, suppress_exceptions = True )
|
||||
cherrypy.config.update( Common.settings )
|
||||
cherrypy.config.update( { u"server.log_to_screen": False } )
|
||||
cherrypy.config.update( self.settings )
|
||||
cherrypy.server.start( init_only = True, server_class = None )
|
||||
|
||||
# since we only want to test the controller, use the stub view for all exposed methods
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import types
|
||||
import cherrypy
|
||||
from StringIO import StringIO
|
||||
from Test_controller import Test_controller
|
||||
from model.Notebook import Notebook
|
||||
|
@ -27,16 +26,17 @@ class Test_files( Test_controller ):
|
|||
self.user2 = None
|
||||
self.anonymous = None
|
||||
self.session_id = None
|
||||
self.file_id = "22"
|
||||
self.filename = "file.png"
|
||||
self.file_data = "foobar\x07`-=[]\;',./~!@#$%^&*()_+{}|:\"<>?" * 100
|
||||
self.content_type = "image/png"
|
||||
|
||||
# make Upload_file deal in fake files rather than actually using the filesystem
|
||||
Upload_file.fake_files = {} # map of filename to fake file object
|
||||
Upload_file.fake_files = {} # map of file_id to fake file object
|
||||
|
||||
@staticmethod
|
||||
def open_file( file_id, mode = None ):
|
||||
fake_file = Upload_file.fake_files.get( Upload_file.make_server_filename( file_id ) )
|
||||
fake_file = Upload_file.fake_files.get( file_id )
|
||||
|
||||
if fake_file:
|
||||
return fake_file
|
||||
|
@ -50,12 +50,12 @@ class Test_files( Test_controller ):
|
|||
|
||||
@staticmethod
|
||||
def delete_file( file_id ):
|
||||
fake_file = Upload_file.fake_files.get( Upload_file.make_server_filename( file_id ) )
|
||||
fake_file = Upload_file.fake_files.get( file_id )
|
||||
|
||||
if fake_file is None:
|
||||
raise IOError()
|
||||
|
||||
del( fake_file[ file_id ] )
|
||||
del( Upload_file.fake_files[ file_id ] )
|
||||
|
||||
Upload_file.open_file = open_file
|
||||
Upload_file.delete_file = delete_file
|
||||
|
@ -118,10 +118,9 @@ class Test_files( Test_controller ):
|
|||
|
||||
def test_upload( self ):
|
||||
self.login()
|
||||
file_id = "22"
|
||||
|
||||
result = self.http_upload(
|
||||
"/files/upload?file_id=%s" % file_id,
|
||||
"/files/upload?file_id=%s" % self.file_id,
|
||||
dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
|
@ -136,7 +135,7 @@ class Test_files( Test_controller ):
|
|||
assert u"script" not in result
|
||||
|
||||
# assert that the file metadata was actually stored in the database
|
||||
db_file = self.database.load( File, file_id )
|
||||
db_file = self.database.load( File, self.file_id )
|
||||
assert db_file
|
||||
assert db_file.notebook_id == self.notebook.object_id
|
||||
assert db_file.note_id == self.note.object_id
|
||||
|
@ -145,37 +144,38 @@ class Test_files( Test_controller ):
|
|||
assert db_file.content_type == self.content_type
|
||||
|
||||
# assert that the file data was actually stored
|
||||
assert Upload_file.open_file( file_id ).read() == self.file_data
|
||||
assert Upload_file.open_file( self.file_id ).read() == self.file_data
|
||||
|
||||
def test_upload_without_login( self ):
|
||||
result = self.http_upload(
|
||||
"/files/upload",
|
||||
"/files/upload?file_id=%s" % self.file_id,
|
||||
dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
),
|
||||
filename = self.filename,
|
||||
file_data = self.file_data,
|
||||
session_id = self.session_id,
|
||||
content_type = self.content_type,
|
||||
)
|
||||
|
||||
assert u"access" in result.get( u"body" )[ 0 ]
|
||||
assert u"access" in result.get( u"script" )
|
||||
|
||||
def test_upload_without_access( self ):
|
||||
self.login2()
|
||||
|
||||
result = self.http_upload(
|
||||
"/files/upload",
|
||||
"/files/upload?file_id=%s" % self.file_id,
|
||||
dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
),
|
||||
filename = self.filename,
|
||||
file_data = self.file_data,
|
||||
session_id = self.session_id,
|
||||
content_type = self.content_type,
|
||||
session_id = self.session_id
|
||||
)
|
||||
|
||||
assert u"access" in result.get( u"body" )[ 0 ]
|
||||
assert u"access" in result.get( u"script" )
|
||||
|
||||
def assert_streaming_error( self, result ):
|
||||
gen = result[ u"body" ]
|
||||
|
|
|
@ -165,7 +165,7 @@ class Test_users( Test_controller ):
|
|||
|
||||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
def test_current_after_signup_with_invite_id( self ):
|
||||
# trick send_invites() into using a fake SMTP server
|
||||
|
@ -242,7 +242,7 @@ class Test_users( Test_controller ):
|
|||
|
||||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
def test_signup_with_different_passwords( self ):
|
||||
result = self.http_post( "/users/signup", dict(
|
||||
|
@ -305,7 +305,7 @@ class Test_users( Test_controller ):
|
|||
|
||||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
def test_current_after_demo_twice( self ):
|
||||
result = self.http_post( "/users/demo", dict() )
|
||||
|
@ -401,7 +401,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
def test_current_anonymous( self ):
|
||||
result = cherrypy.root.users.current( self.anonymous.object_id )
|
||||
|
@ -424,7 +424,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
def test_current_after_login_with_invite_id( self ):
|
||||
# trick send_invites() into using a fake SMTP server
|
||||
|
@ -613,7 +613,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
assert result[ u"notebook" ].object_id == self.anon_notebook.object_id
|
||||
assert len( result[ u"startup_notes" ] ) == 1
|
||||
|
@ -3252,7 +3252,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"extra super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 31337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 31337 * 10
|
||||
|
||||
assert result[ u"conversion" ] == u"subscribe_1"
|
||||
assert result[ u"notebook" ].object_id == self.anon_notebook.object_id
|
||||
|
@ -3291,7 +3291,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
assert result[ u"notebook" ].object_id == self.anon_notebook.object_id
|
||||
assert len( result[ u"startup_notes" ] ) == 1
|
||||
|
@ -3329,7 +3329,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
assert result[ u"notebook" ].object_id == self.anon_notebook.object_id
|
||||
assert len( result[ u"startup_notes" ] ) == 1
|
||||
|
@ -3367,7 +3367,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
assert result[ u"notebook" ].object_id == self.anon_notebook.object_id
|
||||
assert len( result[ u"startup_notes" ] ) == 1
|
||||
|
@ -3403,7 +3403,7 @@ class Test_users( Test_controller ):
|
|||
rate_plan = result[ u"rate_plan" ]
|
||||
assert rate_plan
|
||||
assert rate_plan[ u"name" ] == u"super"
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337
|
||||
assert rate_plan[ u"storage_quota_bytes" ] == 1337 * 10
|
||||
|
||||
assert result[ u"notebook" ].object_id == self.anon_notebook.object_id
|
||||
assert len( result[ u"startup_notes" ] ) == 1
|
||||
|
|
Reference in New Issue