summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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()