From 4cd1e4239d233745408ec5310c61432252e69e0f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 20 Aug 2008 15:08:08 -0700 Subject: [PATCH] Modified Files.upload() to work even when the user's rate plan has no quota. --- controller/Files.py | 4 +++- controller/test/Test_files.py | 38 +++++++++++++++++++++++++++++++++++ luminotes.py | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/controller/Files.py b/controller/Files.py index 835686e..7ba0682 100644 --- a/controller/Files.py +++ b/controller/Files.py @@ -581,7 +581,9 @@ class Files( object ): # if the uploaded file's size would put the user over quota, bail and inform the user rate_plan = self.__users.rate_plan( user.rate_plan ) - if user.storage_bytes + uploaded_file.total_received_bytes > rate_plan.get( u"storage_quota_bytes", 0 ): + storage_quota_bytes = rate_plan.get( u"storage_quota_bytes" ) + + if storage_quota_bytes and user.storage_bytes + uploaded_file.total_received_bytes > storage_quota_bytes: uploaded_file.delete() return dict( script = quota_error_script ) diff --git a/controller/test/Test_files.py b/controller/test/Test_files.py index 0caf5a9..0af5955 100644 --- a/controller/test/Test_files.py +++ b/controller/test/Test_files.py @@ -1093,6 +1093,44 @@ class Test_files( Test_controller ): assert db_file is None assert not Upload_file.exists( self.file_id ) + def test_upload_no_quota( self ): + large_file_data = self.file_data * 5 + self.settings[ u"global" ][ u"luminotes.rate_plans" ][ 0 ][ u"storage_quota_bytes" ] = None + + self.login() + orig_storage_bytes = self.user.storage_bytes + + result = self.http_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 = large_file_data, + content_type = self.content_type, + session_id = self.session_id, + ) + + assert u"body" not in result + assert u"script" not in result + + # assert that the file metadata was actually stored in the database + 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 + assert db_file.filename == self.filename + assert db_file.size_bytes == len( large_file_data ) + assert db_file.content_type == self.content_type + + # assert that the file data was actually stored + assert Upload_file.open_file( self.file_id ).read() == large_file_data + + # assert that storage bytes increased + user = self.database.load( User, self.user.object_id ) + assert user.storage_bytes > orig_storage_bytes + def assert_streaming_error( self, result, error_string ): gen = result[ u"body" ] assert isinstance( gen, types.GeneratorType ) diff --git a/luminotes.py b/luminotes.py index 780ba88..4e8e161 100755 --- a/luminotes.py +++ b/luminotes.py @@ -44,7 +44,7 @@ def main( args ): if server_present is True: print "Luminotes server is already running. aborting" - if launch_browser: + if launch_browser is True: webbrowser.open_new( server_url ) sys.exit( 1 )