David Wolever committed 38a6513

Adding a unique constraint on queue_name, url

Comments (0)

Files changed (2)

     enqueued = DateTimeField(
     dequeued = DateTimeField(default=None, null=True)
+    class Meta:
+        unique_together = (('queue_name', 'url'), )
     def dequeue(cls, queue_name):
         """ Dequeue the next URL in the given queue and mark it dequeued.
 from django.test import TestCase, Client
+from django.db import IntegrityError
-from import assert_equal, assert_not_equal
+from import assert_equal, assert_not_equal, assert_raises
 from datetime import datetime
 from models import QueuedUrl
-def new_queued_url(queue_name="default", url="http://url/",
+_id = 0
+def next_id():
+    global _id
+    _id += 1
+    return str(_id)
+def new_queued_url(queue_name="default", url=None,
                    title="", enqueued=100, dequeued=None):
     u = QueuedUrl()
     u.queue_name = queue_name
-    u.url = url
+    u.url = url or "http://url" + next_id()
     u.title = title
     u.enqueued = enqueued and datetime.fromtimestamp(enqueued)
     u.dequeued = dequeued and datetime.fromtimestamp(dequeued)
         url = QueuedUrl.dequeue("empty_queue")
         assert_equal(url, None)
+    def test_queue_name_and_url_unique(self):
+        queue_props = {
+            'queue_name': "queue",
+            'url': 'http://foo',
+        }
+        new_queued_url(**queue_props)
+        # Creating a new queue with the same values should be an error
+        assert_raises(IntegrityError, new_queued_url, **queue_props)
 class TestViews(TestCase):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.