cubicweb/web/test/unittest_views_json.py
changeset 12567 26744ad37953
parent 11057 0b59724cb3f2
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    15 # details.
    15 # details.
    16 #
    16 #
    17 # You should have received a copy of the GNU Lesser General Public License along
    17 # You should have received a copy of the GNU Lesser General Public License along
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    19 from six import binary_type
       
    20 
    19 
    21 from cubicweb.devtools.testlib import CubicWebTC
    20 from cubicweb.devtools.testlib import CubicWebTC
    22 
    21 
    23 
    22 
    24 class JsonViewsTC(CubicWebTC):
    23 class JsonViewsTC(CubicWebTC):
    48         with self.admin_access.web_request() as req:
    47         with self.admin_access.web_request() as req:
    49             req.form.update({'callback': u'foo',
    48             req.form.update({'callback': u'foo',
    50                              'rql': u'Any GN,COUNT(X) GROUPBY GN ORDERBY GN '
    49                              'rql': u'Any GN,COUNT(X) GROUPBY GN ORDERBY GN '
    51                              'WHERE X in_group G, G name GN'})
    50                              'WHERE X in_group G, G name GN'})
    52             data = self.ctrl_publish(req, ctrl='jsonp')
    51             data = self.ctrl_publish(req, ctrl='jsonp')
    53             self.assertIsInstance(data, binary_type)
    52             self.assertIsInstance(data, bytes)
    54             self.assertEqual(req.headers_out.getRawHeaders('content-type'),
    53             self.assertEqual(req.headers_out.getRawHeaders('content-type'),
    55                              ['application/javascript'])
    54                              ['application/javascript'])
    56             # because jsonp anonymizes data, only 'guests' group should be found
    55             # because jsonp anonymizes data, only 'guests' group should be found
    57             self.assertEqual(data, b'foo(' + self.res_jsonp_data + b')')
    56             self.assertEqual(data, b'foo(' + self.res_jsonp_data + b')')
    58 
    57