Commits

Mark Lavin  committed e08b8fe

Fix error with json.loads not accepting bytes and a new division bug. Test suite is currently passing on Python 3.2

  • Participants
  • Parent commits 8e9430f

Comments (0)

Files changed (2)

File selectable/base.py

             meta['next_page'] = page_data.next_page_number()
         if page_data and page_data.has_previous():
             meta['prev_page'] = page_data.previous_page_number()
-        results['data'] = map(self.format_item, page_data.object_list)
+        results['data'] = [self.format_item(item) for item in page_data.object_list]
         results['meta'] = meta
         return results
 

File selectable/tests/views.py

+from __future__ import division
+
 import json
 
 from django.conf import settings
 
     def test_response_keys(self):
         response = self.client.get(self.url)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         for result in data.get('data'):
             self.assertTrue('id' in result)
             self.assertTrue('value' in result)
     def test_no_term_lookup(self):
         data = {}
         response = self.client.get(self.url, data)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         self.assertEqual(len(data), 2)
 
     def test_simple_term_lookup(self):
         data = {'term': self.thing.name}
         response = self.client.get(self.url, data)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         self.assertEqual(len(data), 2)
         self.assertEqual(len(data.get('data')), 1)
 
         for i in range(settings.SELECTABLE_MAX_LIMIT):
             self.create_thing(data={'name': 'Thing%s' % i})
         response = self.client.get(self.url)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         self.assertEqual(len(data.get('data')), settings.SELECTABLE_MAX_LIMIT)
         meta = data.get('meta')
         self.assertTrue('next_page' in meta)
             self.create_thing(data={'name': 'Thing%s' % i})
         data = {'term': 'Thing', 'page': 2}
         response = self.client.get(self.url, data)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         self.assertEqual(len(data.get('data')), settings.SELECTABLE_MAX_LIMIT)
         # No next page
         meta = data.get('meta')
             self.create_thing(data={'name': 'Thing%s' % i})
         data = {'term': '', 'limit': settings.SELECTABLE_MAX_LIMIT * 2}
         response = self.client.get(self.url)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         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):
             self.create_thing(data={'name': 'Thing%s' % i})
-        new_limit = settings.SELECTABLE_MAX_LIMIT / 2
+        new_limit = settings.SELECTABLE_MAX_LIMIT // 2
         data = {'term': '', 'limit': new_limit}
         response = self.client.get(self.url, data)
-        data = json.loads(response.content)
+        data = json.loads(response.content.decode('utf-8'))
         self.assertEqual(len(data.get('data')), new_limit)