示例#1
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)
示例#2
0
 def testExpands(self, mock_req):
     query.Query(TestModel).expand(TestModel.foo).execute(_TEST_CTX)
     mock_req.assert_called_once_with('GET',
                                      _TEST_API_ADDR + 'abcd?expand=foo',
                                      headers=mock.ANY,
                                      json=None,
                                      verify=mock.ANY,
                                      timeout=mock.ANY)
示例#3
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)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
0
 def testWrongModelClassExpand(self, _):
     with self.assertRaises(excs.QueryError):
         query.Query(TestModel).expand(TestModel.bar).execute(_TEST_CTX)
示例#9
0
 def testBadLimit(self, _):
     with self.assertRaises(excs.QueryError):
         query.Query(TestModel).limit(-1).execute(_TEST_CTX)
示例#10
0
 def testOrFilter_MismatchedOperators(self, _):
     with self.assertRaises(excs.QueryError):
         query.Query(TestModel).filter((TestModel.foo == 'a') | (
             TestModel.baz != 'b')).execute(_TEST_CTX)
示例#11
0
 def testBadFilter(self, _):
     with self.assertRaises(excs.QueryError):
         (query.Query(TestModel).filter(
             OtherTestModel.foo == 'a').execute(_TEST_CTX))
示例#12
0
 def testSort_BadObj(self, _):
     with self.assertRaises(excs.QueryError):
         query.Query(TestModel).order('garbage').execute(_TEST_CTX)
示例#13
0
    def query(cls):
        logging.info('Building %s query', cls.__name__)

        return query.Query(cls)