[extensions-web] tests: Add tests for extension queries



commit 4e29a7923d575bb9f5e5e96f20ef6729a982d619
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Mar 2 19:50:03 2012 -0500

    tests: Add tests for extension queries

 sweettooth/extensions/tests.py |   41 ++++++++++++++++++++++++++++++++++++++++
 sweettooth/extensions/urls.py  |    2 +-
 2 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index 30c9fb2..6129052 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -354,3 +354,44 @@ class UpdateVersionTest(TestCase):
 
         response = self.grab_response(installed)
         self.assertEqual(self.full_expected, response)
+
+class QueryExtensionsTest(BasicUserTestCase, TestCase):
+    def get_response(self, params):
+        response = self.client.get(reverse('extensions-query'), params)
+        return json.loads(response.content)
+
+    def gather_uuids(self, params):
+        return sorted(details['uuid'] for details in self.get_response(params))
+
+    def create_extension(self, name):
+        return models.Extension.objects.create_from_metadata(dict(uuid=name + "@mecheye.net", name=name), creator=self.user)
+
+    def test_basic(self):
+        one = self.create_extension("one")
+        two = self.create_extension("two")
+
+        models.ExtensionVersion.objects.create(extension=one, status=models.STATUS_ACTIVE)
+        models.ExtensionVersion.objects.create(extension=two, status=models.STATUS_ACTIVE)
+
+        uuids = self.gather_uuids(dict(uuid=one.uuid))
+        self.assertEqual(uuids, [one.uuid])
+
+        uuids = self.gather_uuids(dict(uuid=[one.uuid, two.uuid]))
+        self.assertEqual(uuids, [one.uuid, two.uuid])
+
+    def test_basic_visibility(self):
+        one = self.create_extension("one")
+        two = self.create_extension("two")
+
+        models.ExtensionVersion.objects.create(extension=one, status=models.STATUS_ACTIVE)
+        models.ExtensionVersion.objects.create(extension=two, status=models.STATUS_NEW)
+
+        # Since two is new, it shouldn't be visible.
+        uuids = self.gather_uuids(dict(uuid=[one.uuid, two.uuid]))
+        self.assertEqual(uuids, [one.uuid])
+
+        models.ExtensionVersion.objects.create(extension=two, status=models.STATUS_ACTIVE)
+
+        # And now that we have a new version on two, we should have both...
+        uuids = self.gather_uuids(dict(uuid=[one.uuid, two.uuid]))
+        self.assertEqual(uuids, [one.uuid, two.uuid])
diff --git a/sweettooth/extensions/urls.py b/sweettooth/extensions/urls.py
index 88111b8..56f28db 100644
--- a/sweettooth/extensions/urls.py
+++ b/sweettooth/extensions/urls.py
@@ -20,7 +20,7 @@ ajax_patterns = patterns('',
 )
 
 shell_patterns = patterns('',
-    url(r'^extension-query/', views.ajax_query_view),
+    url(r'^extension-query/', views.ajax_query_view, name='extensions-query'),
 
     url(r'^extension-info/', views.ajax_details_view),
 



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