summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2012-10-22 12:19:27 +0800
committerJeremy Kerr <jk@ozlabs.org>2012-10-22 13:56:46 +0800
commit5bbfb1fc8dc4c034416a9e951de8b9b27ff1d838 (patch)
tree89dfff5faa8cfe4edb4d88e6df4ce41953cae08d /apps
parentd38039cdedd1ffd7dd99e9c5cf2aa7679e27751c (diff)
downloadpatchwork-5bbfb1fc8dc4c034416a9e951de8b9b27ff1d838.tar.bz2
patchwork-5bbfb1fc8dc4c034416a9e951de8b9b27ff1d838.tar.xz
bundles: Add check for duplicate bundles
... rather than failing with an IntegrityError. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps')
-rw-r--r--apps/patchwork/tests/bundles.py32
-rw-r--r--apps/patchwork/utils.py4
2 files changed, 36 insertions, 0 deletions
diff --git a/apps/patchwork/tests/bundles.py b/apps/patchwork/tests/bundles.py
index 53eee25..e500b3e 100644
--- a/apps/patchwork/tests/bundles.py
+++ b/apps/patchwork/tests/bundles.py
@@ -179,6 +179,38 @@ class BundleCreateFromListTest(BundleTestBase):
# test that no new bundles are present
self.failUnlessEqual(n_bundles, Bundle.objects.count())
+ def testCreateDuplicateName(self):
+ newbundlename = 'testbundle-dup'
+ patch = self.patches[0]
+
+ params = {'form': 'patchlistform',
+ 'bundle_name': newbundlename,
+ 'action': 'Create',
+ 'project': defaults.project.id,
+ 'patch_id:%d' % patch.id: 'checked'}
+
+ response = self.client.post(
+ '/project/%s/list/' % defaults.project.linkname,
+ params)
+
+ n_bundles = Bundle.objects.count()
+ self.assertContains(response, 'Bundle %s created' % newbundlename)
+ self.assertContains(response, 'added to bundle %s' % newbundlename,
+ count = 1)
+
+ bundle = Bundle.objects.get(name = newbundlename)
+ self.failUnlessEqual(bundle.patches.count(), 1)
+ self.failUnlessEqual(bundle.patches.all()[0], patch)
+
+ response = self.client.post(
+ '/project/%s/list/' % defaults.project.linkname,
+ params)
+
+ self.assertNotContains(response, 'Bundle %s created' % newbundlename)
+ self.assertContains(response, 'You already have a bundle called')
+ self.assertEqual(Bundle.objects.count(), n_bundles)
+ self.assertEqual(bundle.patches.count(), 1)
+
class BundleCreateFromPatchTest(BundleTestBase):
def testCreateNonEmptyBundle(self):
newbundlename = 'testbundle-new'
diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py
index e7619c3..1771167 100644
--- a/apps/patchwork/utils.py
+++ b/apps/patchwork/utils.py
@@ -26,6 +26,7 @@ from django.contrib.sites.models import Site
from django.conf import settings
from django.core.mail import EmailMessage
from django.db.models import Max
+from django.db.utils import IntegrityError
from patchwork.forms import MultiplePatchForm
from patchwork.models import Bundle, Project, BundlePatch, UserProfile, \
PatchChangeNotification, EmailOptout
@@ -107,6 +108,9 @@ def set_bundle(user, project, action, data, patches, context):
if not bundle_name:
return ['No bundle name was specified']
+ if Bundle.objects.filter(owner = user, name = bundle_name).count() > 0:
+ return ['You already have a bundle called "%s"' % bundle_name]
+
bundle = Bundle(owner = user, project = project,
name = bundle_name)
bundle.save()