Beispiel #1
0
 def test_query_filter_on_model_with_fk(self):
     """
     """
     wam1 = Whatamess.objects.create(name="dodo",
                                     title=1,
                                     number=1,
                                     text="d o d o",
                                     author=self.auth1,
                                     yesno=True,
                                     birth_date=date(2000, 1, 2))
     wam2 = Whatamess.objects.create(name="dada",
                                     title=1,
                                     number=2,
                                     text="d a d a",
                                     author=self.auth2,
                                     yesno=True,
                                     birth_date=date(2001, 2, 3))
     wam3 = Whatamess.objects.create(name="dudu",
                                     title=1,
                                     number=3,
                                     text="d u d u",
                                     author=self.auth4,
                                     yesno=True,
                                     birth_date=date(2002, 3, 4))
     self.request = HttpRequest()
     qr = Whatamess.objects.all()
     qrd = QueryDict('start=0&dir=ASC&atitle=D')
     self.request.REQUEST = qrd
     wg = WhatamessGrid()
     result_qr = wg.query_from_request(self.request, qr, fields=['atitle'])
     self.assertEqual(list(result_qr), [wam3])
Beispiel #2
0
 def testGridComplexFKnull(self):
     """test FK resolutions with FK null
     """
     # test FK
     self.wam3 = Whatamess.objects.create(name="didi",
                                          title=1,
                                          number=4,
                                          text="d i d i",
                                          yesno=True,
                                          birth_date=date(2003, 4, 5))
     qry = Whatamess.objects.all()
     wg = WhatamessGrid()
     expct_data = [
         {
             'atitle': 'MR',
             'atitle_display': "Mr."
         },
         {
             'atitle': 'MR',
             'atitle_display': "Mr."
         },
         {
             'atitle': 'MRS',
             'atitle_display': "Mrs."
         },
         {
             'atitle': None
         },
     ]
     expct = (expct_data, 4)
     result = wg.get_rows(qry, fields=[
         'atitle',
     ])
     self.assertEqual(expct, result)
Beispiel #3
0
 def testGridComplexFK(self):
     """test FK resolutions in ExtJSONEncoder
     """
     # test FK
     qry = Whatamess.objects.all()
     wg = WhatamessGrid()
     expct_data = [
         {
             'atitle': 'MR',
             'atitle_display': "Mr."
         },
         {
             'atitle': 'MR',
             'atitle_display': "Mr."
         },
         {
             'atitle': 'MRS',
             'atitle_display': "Mrs."
         },
     ]
     expct = (expct_data, 3)
     result = wg.get_rows(qry, fields=[
         'atitle',
     ])
     self.assertEqual(expct, result)
Beispiel #4
0
 def testGridComplex(self):
     """test FK resolutions in ExtJSONEncoder
     """
     qry = Whatamess.objects.all()
     import datetime
     # Use method
     expct_data = [
         {
             u'name': u"dodo",
             u'author': u'toto'
         },
         {
             u'name': u"dada",
             u'author': u'tata'
         },
         {
             u'name': u"dudu",
             u'author': u'tutu'
         },
     ]
     wg = WhatamessGrid()
     expct = {u"success": True, u"data": expct_data, u'results': 3}
     jsonresult = wg.get_rows_json(qry)
     result = simplejson.loads(jsonresult)
     self.assertEqual(expct, result)
Beispiel #5
0
 def test_query_filter_on_model_with_fk(self):
     """
     """
     wam1 = Whatamess.objects.create(name="dodo", title=1, number=1, text="d o d o", author=self.auth1, yesno=True, birth_date=date(2000,1,2))
     wam2 = Whatamess.objects.create(name="dada", title=1, number=2, text="d a d a", author=self.auth2, yesno=True, birth_date=date(2001,2,3))
     wam3 = Whatamess.objects.create(name="dudu", title=1, number=3, text="d u d u", author=self.auth4, yesno=True, birth_date=date(2002,3,4))
     self.request = HttpRequest()
     qr = Whatamess.objects.all()
     qrd = QueryDict('start=0&dir=ASC&atitle=D')
     self.request.REQUEST = qrd
     wg = WhatamessGrid()
     result_qr = wg.query_from_request(self.request, qr, fields=['atitle'])
     self.assertEqual(list(result_qr), [wam3])
Beispiel #6
0
 def testGridComplexFK(self):
     """test FK resolutions in ExtJSONEncoder
     """
     # test FK
     qry = Whatamess.objects.all()
     wg = WhatamessGrid()
     expct_data = [
         {'atitle': 'MR', 'atitle_display': "Mr."},
         {'atitle': 'MR', 'atitle_display': "Mr."},
         {'atitle': 'MRS', 'atitle_display': "Mrs."},
     ]
     expct = (expct_data, 3)
     result = wg.get_rows(qry, fields=['atitle',])
     self.assertEqual(expct, result)
Beispiel #7
0
 def testGridComplexFKnull(self):
     """test FK resolutions with FK null
     """
     # test FK
     self.wam3 = Whatamess.objects.create(name="didi", title=1, number=4, text="d i d i", yesno=True, birth_date=date(2003,4,5))
     qry = Whatamess.objects.all()
     wg = WhatamessGrid()
     expct_data = [
         {'atitle': 'MR', 'atitle_display': "Mr."},
         {'atitle': 'MR', 'atitle_display': "Mr."},
         {'atitle': 'MRS', 'atitle_display': "Mrs."},
         {'atitle': None},
     ]
     expct = (expct_data, 4)
     result = wg.get_rows(qry, fields=['atitle',])
     self.assertEqual(expct, result)
Beispiel #8
0
 def testGridComplex(self):
     """test FK resolutions in ExtJSONEncoder
     """
     qry = Whatamess.objects.all()
     import datetime
     # Use method
     expct_data = [
         {u'name': u"dodo", u'author': u'toto'},
         {u'name': u"dada", u'author': u'tata'},
         {u'name': u"dudu", u'author': u'tutu'},
     ]
     wg = WhatamessGrid()
     expct = {u"success": True, u"data": expct_data, u'results': 3}
     jsonresult = wg.get_rows_json(qry)
     result = simplejson.loads(jsonresult)
     self.assertEqual(expct, result)