Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a uniqueness constraint to the denormalised fullname model field.

BACKWARDS INCOMPATIBLE CHANGE.
If were using an earlier version of this code, you will need to change
the fullname field in the acacia_topic table to have a unique constraint
(previously, it was indexed, but not required to contain unique values,
which was an error in the design).
  • Loading branch information...
commit 009f73b46c5c05b113a034e67441eab44e3574e5 1 parent 36a0315
Malcolm Tredinnick authored
Showing with 14 additions and 2 deletions.
  1. +1 −1  acacia/models.py
  2. +13 −1 acacia/tests.py
View
2  acacia/models.py
@@ -49,7 +49,7 @@ class AbstractTopic(treebeard_mods.MP_Node):
"""
name = models.CharField(max_length=50)
# Denormalise things a bit so that full name lookups are fast.
- full_name = models.CharField(max_length=512, db_index=True)
+ full_name = models.CharField(max_length=512, unique=True)
node_order_by = ["name"]
separator = "/"
View
14 acacia/tests.py
@@ -2,7 +2,7 @@
Tests for both the local treebeard overrides and the whole hierarchical topic
structure.
"""
-from django import test
+from django import db, test
import models
@@ -150,6 +150,18 @@ def test_change_parent(self):
self.assertRaises(models.Topic.DoesNotExist,
models.Topic.objects.get_by_full_name, "a/x/c")
+ def test_create_duplicate_entry(self):
+ """
+ Tests that an appropriate error is raised if the tree is manipulated in
+ such a way that a duplicate full name would be created.
+ """
+ target = models.Topic.objects.get_by_full_name("a")
+ node = models.Topic.objects.get_by_full_name("x")
+ # Attempting to move "x" under "a" raises an error at the database
+ # level because we already have an "a/x" node.
+ self.assertRaises(db.IntegrityError, node.move, target,
+ "sorted-child")
+
class TreebeardTests(BaseTestSetup, test.TestCase):
"""
Tests for my local modification/overrides to the default treebeard
Please sign in to comment.
Something went wrong with that request. Please try again.