Ejemplo n.º 1
0
 def testGridError(self):
     """Get a error with a query from a GridModel
     """
     qry = Author.objects.all()
     ag = AuthorGrid()
     # And now get result in JSONResponse
     expct_data = [
         {'title': u"MR", 'title_display': "Mr.", 'birth_date': u"2000-01-02", 'name': u"toto"},
         {'title': u"MR", 'title_display': "Mr.", 'birth_date': u"2001-02-03", 'name': u"tata"},
         {'title': u"MRS", 'title_display': "Mrs.", 'birth_date': u"2002-03-04", 'name': u"tutu"},
     ]
     expct = {u"success": False, u"message": "Error : No mapped field 'titl'"}
     jsonresult = ag.get_rows_json(qry, fields=['titl', 'birth_date', 'name'], jsonerror=True)
     result = simplejson.loads(jsonresult)
     self.assertEqual(expct, result)
     # Without jsonerror we get normal Django's exception
     self.assertRaises(AttributeError, ag.get_rows_json, qry, fields=['titl', 'birth_date', 'name'])
Ejemplo n.º 2
0
    def testGridbasic_utf8(self):
        """Get a query from a GridModel with utf8
        """
        # adds utf8 record
        from datetime import date
        self.auth4 = Author.objects.create(name="tété",
                                           title="TéTé",
                                           birth_date=date(2000, 1, 2))
        qry = Author.objects.all()

        # And now get result in JSONResponse
        expct_data = [
            {
                'title': u"MR",
                'title_display': "Mr.",
                'birth_date': u"2000-01-02",
                'his_name': u"toto"
            },
            {
                'title': u"MR",
                'title_display': "Mr.",
                'birth_date': u"2001-02-03",
                'his_name': u"tata"
            },
            {
                'title': u"MRS",
                'title_display': "Mrs.",
                'birth_date': u"2002-03-04",
                'his_name': u"tutu"
            },
            {
                'title': u"TéTé",
                'title_display': u"TéTé",
                'birth_date': u"2000-01-02",
                'his_name': u"tété"
            },
        ]
        ag = AuthorGrid()
        expct = {u"success": True, u"data": expct_data, u'results': 4}
        jsonresult = ag.get_rows_json(
            qry, fields=['title', 'birth_date', 'his_name'])
        result = simplejson.loads(jsonresult)
        self.assertEqual(expct, result)
Ejemplo n.º 3
0
    def testGridbasic_utf8(self):
        """Get a query from a GridModel with utf8
        """
        # adds utf8 record
        from datetime import date
        self.auth4 = Author.objects.create(name="tété", title="TéTé", birth_date=date(2000,1,2))
        qry = Author.objects.all()

        # And now get result in JSONResponse
        expct_data = [
            {'title': u"MR", 'title_display': "Mr.", 'birth_date': u"2000-01-02", 'his_name': u"toto"},
            {'title': u"MR", 'title_display': "Mr.", 'birth_date': u"2001-02-03", 'his_name': u"tata"},
            {'title': u"MRS", 'title_display': "Mrs.", 'birth_date': u"2002-03-04", 'his_name': u"tutu"},
            {'title': u"TéTé", 'title_display': u"TéTé", 'birth_date': u"2000-01-02", 'his_name': u"tété"},
        ]
        ag = AuthorGrid()
        expct = {u"success": True, u"data": expct_data, u'results': 4}
        jsonresult = ag.get_rows_json(qry, fields=['title', 'birth_date', 'his_name'])
        result = simplejson.loads(jsonresult)
        self.assertEqual(expct, result)
Ejemplo n.º 4
0
 def testGridError(self):
     """Get a error with a query from a GridModel
     """
     qry = Author.objects.all()
     ag = AuthorGrid()
     # And now get result in JSONResponse
     expct_data = [
         {
             'title': u"MR",
             'title_display': "Mr.",
             'birth_date': u"2000-01-02",
             'name': u"toto"
         },
         {
             'title': u"MR",
             'title_display': "Mr.",
             'birth_date': u"2001-02-03",
             'name': u"tata"
         },
         {
             'title': u"MRS",
             'title_display': "Mrs.",
             'birth_date': u"2002-03-04",
             'name': u"tutu"
         },
     ]
     expct = {
         u"success": False,
         u"message": "Error : No mapped field 'titl'"
     }
     jsonresult = ag.get_rows_json(qry,
                                   fields=['titl', 'birth_date', 'name'],
                                   jsonerror=True)
     result = simplejson.loads(jsonresult)
     self.assertEqual(expct, result)
     # Without jsonerror we get normal Django's exception
     self.assertRaises(AttributeError,
                       ag.get_rows_json,
                       qry,
                       fields=['titl', 'birth_date', 'name'])
Ejemplo n.º 5
0
    def testGridbasic(self):
        """Get a query from a GridModel
        """
        qry = Author.objects.all()
        import datetime
        expct_data = [
            {'his_name': u"toto", 'title': u"MR", 'title_display': "Mr.", 'birth_date': datetime.date(2000, 1, 2)},
            {'his_name': u"tata", 'title': u"MR", 'title_display': "Mr.", 'birth_date': datetime.date(2001, 2, 3)},
            {'his_name': u"tutu", 'title': u"MRS", 'title_display': "Mrs.", 'birth_date': datetime.date(2002, 3, 4)},
        ]
        ag = AuthorGrid()
        raw_result, length = ag.get_rows(qry,)
        self.assertEqual(expct_data, raw_result)
        self.assertEqual(length, 3)

        # And now get result in JSONResponse
        expct_data = [
            {'title': u"MR", 'title_display': "Mr.", 'birth_date': u"2000-01-02", 'his_name': u"toto"},
            {'title': u"MR", 'title_display': "Mr.", 'birth_date': u"2001-02-03", 'his_name': u"tata"},
            {'title': u"MRS", 'title_display': "Mrs.", 'birth_date': u"2002-03-04", 'his_name': u"tutu"},
        ]
        expct = {u"success": True, u"data": expct_data, u'results': 3}
        jsonresult = ag.get_rows_json(qry, fields=['title', 'birth_date', 'his_name'])
        result = simplejson.loads(jsonresult)
        self.assertEqual(expct, result)

        # use pre-configured View
        response = self.client.get("/api/author/getjson")
        result = simplejson.loads(response.content)
        expct_data = [
            {'his_name': "toto", 'title': "MR", 'title_display': "Mr.", 'birth_date': "2000-01-02"},
            {'his_name': "tata", 'title': "MR", 'title_display': "Mr.", 'birth_date': "2001-02-03"},
            {'his_name': "tutu", 'title': "MRS", 'title_display': "Mrs.", 'birth_date': "2002-03-04"},
        ]
        expct = {"success": True, "data": expct_data, 'results': 3}
        self.assertEqual(expct, result)
Ejemplo n.º 6
0
    def testGridbasic(self):
        """Get a query from a GridModel
        """
        qry = Author.objects.all()
        import datetime
        expct_data = [
            {
                'his_name': u"toto",
                'title': u"MR",
                'title_display': "Mr.",
                'birth_date': datetime.date(2000, 1, 2)
            },
            {
                'his_name': u"tata",
                'title': u"MR",
                'title_display': "Mr.",
                'birth_date': datetime.date(2001, 2, 3)
            },
            {
                'his_name': u"tutu",
                'title': u"MRS",
                'title_display': "Mrs.",
                'birth_date': datetime.date(2002, 3, 4)
            },
        ]
        ag = AuthorGrid()
        raw_result, length = ag.get_rows(qry, )
        self.assertEqual(expct_data, raw_result)
        self.assertEqual(length, 3)

        # And now get result in JSONResponse
        expct_data = [
            {
                'title': u"MR",
                'title_display': "Mr.",
                'birth_date': u"2000-01-02",
                'his_name': u"toto"
            },
            {
                'title': u"MR",
                'title_display': "Mr.",
                'birth_date': u"2001-02-03",
                'his_name': u"tata"
            },
            {
                'title': u"MRS",
                'title_display': "Mrs.",
                'birth_date': u"2002-03-04",
                'his_name': u"tutu"
            },
        ]
        expct = {u"success": True, u"data": expct_data, u'results': 3}
        jsonresult = ag.get_rows_json(
            qry, fields=['title', 'birth_date', 'his_name'])
        result = simplejson.loads(jsonresult)
        self.assertEqual(expct, result)

        # use pre-configured View
        response = self.client.get("/api/author/getjson")
        result = simplejson.loads(response.content)
        expct_data = [
            {
                'his_name': "toto",
                'title': "MR",
                'title_display': "Mr.",
                'birth_date': "2000-01-02"
            },
            {
                'his_name': "tata",
                'title': "MR",
                'title_display': "Mr.",
                'birth_date': "2001-02-03"
            },
            {
                'his_name': "tutu",
                'title': "MRS",
                'title_display': "Mrs.",
                'birth_date': "2002-03-04"
            },
        ]
        expct = {"success": True, "data": expct_data, 'results': 3}
        self.assertEqual(expct, result)