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)
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)
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)
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)
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)
def testWrongModelClassExpand(self, _): with self.assertRaises(excs.QueryError): query.Query(TestModel).expand(TestModel.bar).execute(_TEST_CTX)
def testBadLimit(self, _): with self.assertRaises(excs.QueryError): query.Query(TestModel).limit(-1).execute(_TEST_CTX)
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)
def testOrFilter_MismatchedOperators(self, _): with self.assertRaises(excs.QueryError): query.Query(TestModel).filter( (TestModel.foo == 'a') | (TestModel.baz != 'b')).execute(_TEST_CTX)
def testBadFilter(self, _): with self.assertRaises(excs.QueryError): (query.Query(TestModel) .filter(OtherTestModel.foo == 'a') .execute(_TEST_CTX))
def testSort_BadObj(self, _): with self.assertRaises(excs.QueryError): query.Query(TestModel).order('garbage').execute(_TEST_CTX)
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)
def query(cls): logging.info('Building %s query', cls.__name__) return query.Query(cls)