Exemplo n.º 1
0
 def testOrFilter(self, mock_req):
   query.Query(TestModel).filter(
       (TestModel.foo == 'a') |
       (TestModel.foo == 'b')).execute(_TEST_CTX)
   mock_req.assert_called_once_with(
       'GET', _TEST_API_ADDR + 'abcd?q=foo:a|b', headers=mock.ANY,
       json=None, verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 2
0
 def testMultipleExpands(self, mock_req):
   (query.Query(TestModel)
    .expand(TestModel.foo)
    .expand(TestModel.baz)
    .execute(_TEST_CTX))
   mock_req.assert_called_once_with(
       'GET', _TEST_API_ADDR + 'abcd?expand=baz&expand=foo', headers=mock.ANY,
       json=None, verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 3
0
  def testCount(self, mock_req):
    mock_req.return_value = test_utils.GetTestResponse(data={'count': 1})

    response = query.Query(TestModel).count(_TEST_CTX)

    self.assertEqual(1, response)
    mock_req.assert_called_once_with(
        'GET', _TEST_API_ADDR + 'abcd?limit=-1', headers=mock.ANY, json=None,
        verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 4
0
 def testEverything(self, mock_req):
   (query.Query(TestModel)
    .filter(TestModel.foo == 'a', TestModel.baz == 'b')
    .order(TestModel.foo)
    .expand(TestModel.foo)
    .limit(3)
    .execute(_TEST_CTX))
   mock_req.assert_called_once_with(
       'GET',
       _TEST_API_ADDR + 'abcd?q=baz:b&q=foo:a&sort=foo ASC&limit=3&expand=foo',
       headers=mock.ANY, json=None, verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 5
0
 def testSort_RawProperty(self, mock_req):
   query.Query(TestModel).order(TestModel.foo).execute(_TEST_CTX)
   mock_req.assert_called_once_with(
       'GET', _TEST_API_ADDR + 'abcd?sort=foo ASC', headers=mock.ANY,
       json=None, verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 6
0
 def testWrongModelClassExpand(self, _):
   with self.assertRaises(excs.QueryError):
     query.Query(TestModel).expand(TestModel.bar).execute(_TEST_CTX)
Exemplo n.º 7
0
 def testBadLimit(self, _):
   with self.assertRaises(excs.QueryError):
     query.Query(TestModel).limit(-1).execute(_TEST_CTX)
Exemplo n.º 8
0
 def testLimit(self, mock_req):
   query.Query(TestModel).limit(10).execute(_TEST_CTX)
   mock_req.assert_called_once_with(
       'GET', _TEST_API_ADDR + 'abcd?limit=10', headers=mock.ANY, json=None,
       verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 9
0
 def testOrFilter_MismatchedOperators(self, _):
   with self.assertRaises(excs.QueryError):
     query.Query(TestModel).filter(
         (TestModel.foo == 'a') |
         (TestModel.baz != 'b')).execute(_TEST_CTX)
Exemplo n.º 10
0
 def testBadFilter(self, _):
   with self.assertRaises(excs.QueryError):
     (query.Query(TestModel)
      .filter(OtherTestModel.foo == 'a')
      .execute(_TEST_CTX))
Exemplo n.º 11
0
 def testSort_BadObj(self, _):
   with self.assertRaises(excs.QueryError):
     query.Query(TestModel).order('garbage').execute(_TEST_CTX)
Exemplo n.º 12
0
 def testSort_WithNode(self, mock_req):
   query.Query(TestModel).order(-TestModel.baz).execute(_TEST_CTX)
   mock_req.assert_called_once_with(
       'GET', _TEST_API_ADDR + 'abcd?sort=baz DESC', headers=mock.ANY,
       json=None, verify=mock.ANY, timeout=mock.ANY)
Exemplo n.º 13
0
    def query(cls):
        logging.info('Building %s query', cls.__name__)

        return query.Query(cls)