def test_to_one_item_dict(self):
     # GIVEN list with one dictionary
     # WHEN to_dict is called 
     # THEN a dict with name, value pairs is returned
     self.assertEquals(to_dict([{'test': 1,
                                 'two': 'foo'}],
                       'test', 'two'),
                       {1: 'foo'})
 def test_to_one_item_dict(self):
     # GIVEN list with one dictionary
     # WHEN to_dict is called
     # THEN a dict with name, value pairs is returned
     self.assertEquals(to_dict([{
         'test': 1,
         'two': 'foo'
     }], 'test', 'two'), {1: 'foo'})
 def test_to_item_dict(self):
     # GIVEN list of dictionaries
     # WHEN to_dict is called
     # THEN a dict with name, value pairs is returned
     self.assertEquals(to_dict([{'test': 1,
                                 'two': 'foo'},
                                {'test': 2,
                                 'two': 'bar'}],
                       'test', 'two'),
                       {1: 'foo',
                        2: 'bar',
                        })
Example #4
0
 def render(self, obj=None, media_type=None):
     """
     Renders *obj* using the :attr:`template` specified on the class.
     """
     if obj is None:
         return ''
     listobj = obj
     if not isinstance(listobj, list):
         listobj = [obj]
     # create the dict format with the key and value
     key = self.view.request.GET.get('key')
     value = self.view.request.GET.get('value')
     dl = to_dict(obj, key, value)
     data = JSONRenderer(self.view).render(dl)
     return data
 def test_to_item_dict(self):
     # GIVEN list of dictionaries
     # WHEN to_dict is called
     # THEN a dict with name, value pairs is returned
     self.assertEquals(
         to_dict([{
             'test': 1,
             'two': 'foo'
         }, {
             'test': 2,
             'two': 'bar'
         }], 'test', 'two'), {
             1: 'foo',
             2: 'bar',
         })
Example #6
0
 def render(self, obj=None, media_type=None):
     """
     Renders *obj* using the :attr:`template` specified on the class.
     """
     if obj is None:
         return ''
     listobj = obj
     if not isinstance(listobj, list):
         listobj = [obj]
     # create the dict format with the key and value
     key = self.view.request.GET.get('key')
     value = self.view.request.GET.get('value')
     dl = to_dict(obj, key, value)
     data = JSONRenderer(self.view).render(dl)
     return data