Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_constructor_with_query_skip_limit(self):
"""
Test instantiating a QueryResult when query callable already has
skip and/or limit
"""
query = Query(self.db, skip=10, limit=10)
result = QueryResult(query)
self.assertIsInstance(result, QueryResult)
self.assertDictEqual(result.options, {'skip': 10, 'limit': 10})
self.assertEqual(result._ref, query)
def create_result(self, selector={'_id': {'$gt': 0}},
fields=['_id', 'name', 'age'], **kwargs):
if kwargs.get('q_parms', None):
query = Query(self.db, **kwargs['q_parms'])
else:
query = Query(self.db)
if kwargs.get('qr_parms', None):
return QueryResult(query, selector=selector, fields=fields, **kwargs['qr_parms'])
else:
return QueryResult(query, selector=selector, fields=fields)
def test_constructor_without_kwargs(self):
"""
Test instantiating a Query without parameters
"""
query = Query(self.db)
self.assertIsInstance(query, Query)
self.assertIsInstance(query.result, QueryResult)
self.assertEqual(query, {})
def test_constructor_with_options(self):
"""
Test instantiating a QueryResult by passing in query parameters
"""
query = Query(self.db)
result = QueryResult(query, foo='bar', page_size=10)
self.assertIsInstance(result, QueryResult)
self.assertEqual(result.options, {'foo': 'bar'})
self.assertEqual(result._ref, query)
self.assertEqual(result._page_size, 10)
def test_constructor_with_kwargs(self):
"""
Test instantiating a Query by passing in query parameters
"""
query = Query(self.db, foo={'bar': 'baz'})
self.assertIsInstance(query, Query)
self.assertIsInstance(query.result, QueryResult)
self.assertEqual(query, {'foo': {'bar': 'baz'}})
def create_result(self, selector={'_id': {'$gt': 0}},
fields=['_id', 'name', 'age'], **kwargs):
if kwargs.get('q_parms', None):
query = Query(self.db, **kwargs['q_parms'])
else:
query = Query(self.db)
if kwargs.get('qr_parms', None):
return QueryResult(query, selector=selector, fields=fields, **kwargs['qr_parms'])
else:
return QueryResult(query, selector=selector, fields=fields)
def test_constructor_without_options(self):
"""
Test instantiating a Query without parameters
"""
query = Query(self.db)
result = QueryResult(query)
self.assertIsInstance(result, QueryResult)
self.assertEqual(result.options, {})
self.assertEqual(result._ref, query)
self.assertEqual(result._page_size, 100)