[extensions-web] upload: Fix upload page



commit 7519b6bd5bb26b55c233525ca25150079068eadf
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Mar 4 12:43:31 2012 -0500

    upload: Fix upload page
    
    Obviously, the mistake that I made here was really silly, modifying
    the DB and not committing. I didn't catch it because transactions
    are monkey patched out during testcases because why not, Django!
    
    So I was sitting here thinking that my test cases were actually
    testing the code, when they were not. Turns out you need to use
    a TransactionTestCase, which is completely obvious. Thanks, Django!

 sweettooth/extensions/tests.py |    4 ++--
 sweettooth/extensions/views.py |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 3a02e75..7b3d74f 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -9,7 +9,7 @@ try:
 except ImportError:
     from StringIO import StringIO
 
-from django.test import TestCase
+from django.test import TestCase, TransactionTestCase
 from django.core.files.base import File
 from django.core.urlresolvers import reverse
 from django.utils import simplejson as json
@@ -174,7 +174,7 @@ class ReplaceMetadataTest(BasicUserTestCase, TestCase):
         old_zip.close()
         new_zip.close()
 
-class UploadTest(BasicUserTestCase, TestCase):
+class UploadTest(BasicUserTestCase, TransactionTestCase):
     def upload_file(self, zipfile):
         with get_test_zipfile(zipfile) as f:
             return self.client.post(reverse('extensions-upload-file'),
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 7e344f2..1d440bc 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -397,8 +397,6 @@ def upload_file(request):
                 extra_debug = repr(e)
                 transaction.rollback()
             else:
-                transaction.commit()
-
                 version = models.ExtensionVersion.objects.create(extension=extension,
                                                                  source=file_source,
                                                                  status=models.STATUS_NEW)
@@ -406,6 +404,8 @@ def upload_file(request):
                 version.replace_metadata_json()
                 version.save()
 
+                transaction.commit()
+
                 return redirect('extensions-version-detail',
                                 pk=version.pk,
                                 ext_pk=extension.pk,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]