Ejemplo n.º 1
0
  def testQueryAttributes(self):
    q = query.Query(kind='Foo')
    self.assertEqual(q.kind, 'Foo')
    self.assertEqual(q.ancestor, None)
    self.assertEqual(q.filters, None)
    self.assertEqual(q.orders, None)

    key = model.Key('Barba', 'papa')
    q = query.Query(kind='Foo', ancestor=key)
    self.assertEqual(q.kind, 'Foo')
    self.assertEqual(q.ancestor, key)
    self.assertEqual(q.filters, None)
    self.assertEqual(q.orders, None)

    q = q.filter(Foo.rate == 1)
    self.assertEqual(q.kind, 'Foo')
    self.assertEqual(q.ancestor, key)
    self.assertEqual(q.filters, query.FilterNode('rate', '=', 1))
    self.assertEqual(q.orders, None)

    q = q.order(-Foo.name)
    self.assertEqual(q.kind, 'Foo')
    self.assertEqual(q.ancestor, key)
    self.assertEqual(q.filters, query.FilterNode('rate', '=', 1))
    expected_order = [('name', query.DESC)]
    self.assertEqual(query.orders_to_orderings(q.orders), expected_order)
Ejemplo n.º 2
0
 def testModernQuerySyntax(self):
   class Employee(model.Model):
     name = model.StringProperty()
     age = model.IntegerProperty('Age')
     rank = model.IntegerProperty()
     @classmethod
     def seniors(cls, min_age, min_rank):
       q = cls.query().filter(cls.age >= min_age, cls.rank <= min_rank)
       q = q.order(cls.name, -cls.age)
       return q
   q = Employee.seniors(42, 5)
   self.assertEqual(q.filters,
                    query.ConjunctionNode(
                      [query.FilterNode('Age', '>=', 42),
                       query.FilterNode('rank', '<=', 5)]))
   self.assertEqual(query.orders_to_orderings(q.orders),
                    [('name', query.ASC), ('Age', query.DESC)])
Ejemplo n.º 3
0
 def testGqlOrder(self):
   qry, options, bindings = query.parse_gql(
     'SELECT * FROM Kind ORDER BY prop1')
   self.assertEqual(query.orders_to_orderings(qry.orders),
                    [('prop1', query.ASC)])