def testGridstore(self): """Get Store config from a grid """ #expct = {'store': store, columns = [ { 'name': 'birth_date', 'dateFormat': 'Y-m-d', 'format': 'Y-m-d', 'tooltip': u'birth date', 'header': 'birth_date', 'type': 'date', 'xtype': 'datecolumn' }, { 'header': 'name', 'name': 'name', 'tooltip': u'Name' }, { 'header': 'title', 'name': 'title', 'tooltip': u'title' }, ] ag = AuthorGrid() store = ag.to_store() expct = {'fields': columns} self.assertEqual(expct, store) store = ag.to_store(url="/test/blah") expct = {'fields': columns, 'url': '/test/blah'} self.assertEqual(expct, store)
def testGridstore(self): """Get Store config from a grid """ #expct = {'store': store, columns = [ {'name': 'birth_date', 'dateFormat': 'Y-m-d', 'format': 'Y-m-d', 'tooltip': u'birth date', 'header': 'birth_date', 'type': 'date','xtype': 'datecolumn'}, {'header': 'name', 'name': 'name', 'tooltip': u'Name'}, {'header': 'title', 'name': 'title', 'tooltip': u'title'}, ] ag = AuthorGrid() store = ag.to_store() expct = {'fields': columns} self.assertEqual(expct, store) store = ag.to_store(url="/test/blah") expct = {'fields': columns, 'url': '/test/blah'} self.assertEqual(expct, store)
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'])
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)
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)
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'])
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)
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)