Commits

Sławek Ehlert committed 73f5011

fixes tests because of the new results format

  • Participants
  • Parent commits f805709
  • Branches result-refactor

Comments (0)

Files changed (1)

File selectable/tests/views.py

 
 
 class SelectableViewTest(PatchSettingsMixin, BaseSelectableTestCase):
-    
+
     def setUp(self):
         super(SelectableViewTest, self).setUp()
         self.url = ThingLookup.url()
     def test_response_keys(self):
         response = self.client.get(self.url)
         data = json.loads(response.content)
-        for result in data:
+        for result in data.get('data'):
             self.assertTrue('id' in result)
             self.assertTrue('value' in result)
             self.assertTrue('label' in result)
         data = {'term': self.thing.name}
         response = self.client.get(self.url, data)
         data = json.loads(response.content)
-        self.assertEqual(len(data), 1)
+        self.assertEqual(len(data), 2)
+        self.assertEqual(len(data.get('data')), 1)
 
     def test_unknown_lookup(self):
         unknown_url = reverse('selectable-lookup', args=["XXXXXXX"])
             self.create_thing(data={'name': 'Thing%s' % i})
         response = self.client.get(self.url)
         data = json.loads(response.content)
-        self.assertEqual(len(data), settings.SELECTABLE_MAX_LIMIT + 1)
-        last_item = data[-1]
-        self.assertTrue('page' in last_item)
+        self.assertEqual(len(data.get('data')), settings.SELECTABLE_MAX_LIMIT)
+        meta = data.get('meta')
+        self.assertTrue('next_page' in meta)
 
     def test_get_next_page(self):
         for i in range(settings.SELECTABLE_MAX_LIMIT * 2):
         data = {'term': 'Thing', 'page': 2}
         response = self.client.get(self.url, data)
         data = json.loads(response.content)
-        self.assertEqual(len(data), settings.SELECTABLE_MAX_LIMIT)
+        self.assertEqual(len(data.get('data')), settings.SELECTABLE_MAX_LIMIT)
         # No next page
-        last_item = data[-1]
-        self.assertFalse('page' in last_item)
+        meta = data.get('meta')
+        self.assertFalse('next_page' in meta)
 
     def test_request_more_than_max(self):
         for i in range(settings.SELECTABLE_MAX_LIMIT):
         data = {'term': '', 'limit': settings.SELECTABLE_MAX_LIMIT * 2}
         response = self.client.get(self.url)
         data = json.loads(response.content)
-        self.assertEqual(len(data), settings.SELECTABLE_MAX_LIMIT + 1)
+        self.assertEqual(len(data.get('data')), settings.SELECTABLE_MAX_LIMIT)
 
     def test_request_less_than_max(self):
         for i in range(settings.SELECTABLE_MAX_LIMIT):
         data = {'term': '', 'limit': new_limit}
         response = self.client.get(self.url, data)
         data = json.loads(response.content)
-        self.assertEqual(len(data), new_limit + 1)
-
+        self.assertEqual(len(data.get('data')), new_limit)