本文整理汇总了Python中stacktach.dbapi.get_db_objects函数的典型用法代码示例。如果您正苦于以下问题:Python get_db_objects函数的具体用法?Python get_db_objects怎么用?Python get_db_objects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_db_objects函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_usage_exists_no_custom_filters
def test_list_usage_exists_no_custom_filters(self):
fake_request = self.mox.CreateMockAnything()
fake_request.GET = {}
self.mox.StubOutWithMock(dbapi, 'get_db_objects')
objects = self.mox.CreateMockAnything()
dbapi.get_db_objects(models.InstanceExists, fake_request, 'id',
custom_filters={}).AndReturn(objects)
self.mox.StubOutWithMock(dbapi, '_convert_model_list')
dbapi._convert_model_list(objects, dbapi._exists_extra_values)
self.mox.ReplayAll()
resp = dbapi.list_usage_exists(fake_request)
self.assertEqual(resp.status_code, 200)
self.mox.VerifyAll()
示例2: test_list_usage_exists_with_received_max
def test_list_usage_exists_with_received_max(self):
fake_request = self.mox.CreateMockAnything()
date = str(datetime.datetime.utcnow())
fake_request.GET = {'received_max': date}
self.mox.StubOutWithMock(dbapi, 'get_db_objects')
unix_date = stacktach_utils.str_time_to_unix(date)
custom_filters = {'received_max': {'raw__when__lte': unix_date}}
objects = self.mox.CreateMockAnything()
dbapi.get_db_objects(models.InstanceExists, fake_request, 'id',
custom_filters=custom_filters).AndReturn(objects)
self.mox.StubOutWithMock(dbapi, '_convert_model_list')
dbapi._convert_model_list(objects, dbapi._exists_extra_values)
self.mox.ReplayAll()
resp = dbapi.list_usage_exists(fake_request)
self.assertEqual(resp.status_code, 200)
self.mox.VerifyAll()
示例3: test_get_db_objects_with_custom_filter
def test_get_db_objects_with_custom_filter(self):
fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything()
filters = {'instance': INSTANCE_ID_1}
custom_filters = {'raw': {'raw__id': 1}}
fake_request.GET = filters
self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request,
custom_filters=custom_filters).AndReturn(filters)
self.mox.StubOutWithMock(dbapi, '_check_has_field')
dbapi._check_has_field(fake_model, 'id')
result = self.mox.CreateMockAnything()
all_filters = {}
all_filters.update(filters)
all_filters.update(custom_filters['raw'])
fake_model.objects.filter(**all_filters).AndReturn(result)
result.order_by('-id').AndReturn(result)
s = slice(None, dbapi.DEFAULT_LIMIT, None)
result.__getitem__(s).AndReturn(result)
self.mox.ReplayAll()
query_result = dbapi.get_db_objects(fake_model, fake_request, 'id',
custom_filters=custom_filters)
self.assertEquals(query_result, result)
self.mox.VerifyAll()
示例4: test_list_usage_deletes_for_glance
def test_list_usage_deletes_for_glance(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'GET'
fake_request.GET = {}
self.mox.StubOutWithMock(dbapi, 'get_db_objects')
mock_objects = self.mox.CreateMockAnything()
deletes = {'a': 1}
self.mox.StubOutWithMock(dbapi, '_convert_model_list')
dbapi._convert_model_list(mock_objects).AndReturn(deletes)
dbapi.get_db_objects(models.ImageDeletes, fake_request, 'deleted_at').AndReturn(mock_objects)
self.mox.ReplayAll()
resp = dbapi.list_usage_deletes_glance(fake_request)
self.assertEqual(resp.status_code, 200)
self.assertEqual(json.loads(resp.content), {'deletes': deletes})
self.mox.VerifyAll()
示例5: test_list_usage_launches_without_service
def test_list_usage_launches_without_service(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'GET'
fake_request.GET = {}
self.mox.StubOutWithMock(dbapi, 'get_db_objects')
mock_objects = self.mox.CreateMockAnything()
launches = {'a': 1}
self.mox.StubOutWithMock(dbapi, '_convert_model_list')
dbapi._convert_model_list(mock_objects).AndReturn(launches)
dbapi.get_db_objects(models.InstanceUsage, fake_request, 'launched_at').AndReturn(mock_objects)
self.mox.ReplayAll()
resp = dbapi.list_usage_launches(fake_request)
self.assertEqual(resp.status_code, 200)
self.assertEqual(json.loads(resp.content), {'launches': launches})
self.mox.VerifyAll()
示例6: test_get_db_objects_offset_and_limit
def test_get_db_objects_offset_and_limit(self):
fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything()
fake_request.GET = {'offset': 2, 'limit': 2}
self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn({})
self.mox.StubOutWithMock(dbapi, '_check_has_field')
dbapi._check_has_field(fake_model, 'id')
result = self.mox.CreateMockAnything()
fake_model.objects.all().AndReturn(result)
result.order_by('-id').AndReturn(result)
result.__getslice__(2, 4).AndReturn(result)
self.mox.ReplayAll()
query_result = dbapi.get_db_objects(fake_model, fake_request, 'id')
self.assertEquals(query_result, result)
self.mox.VerifyAll()
示例7: test_get_db_objects_desc
def test_get_db_objects_desc(self):
fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything()
fake_request.GET = {'direction': 'desc'}
self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn({})
self.mox.StubOutWithMock(dbapi, '_check_has_field')
dbapi._check_has_field(fake_model, 'id')
result = self.mox.CreateMockAnything()
fake_model.objects.all().AndReturn(result)
result.order_by('-id').AndReturn(result)
result.__getitem__(slice(None, None, None)).AndReturn(result)
self.mox.ReplayAll()
query_result = dbapi.get_db_objects(fake_model, fake_request, 'id')
self.assertEquals(query_result, result)
self.mox.VerifyAll()
示例8: test_get_db_objects_with_filter
def test_get_db_objects_with_filter(self):
fake_model = self.make_fake_model()
fake_request = self.mox.CreateMockAnything()
filters = {'instance': INSTANCE_ID_1}
fake_request.GET = filters
self.mox.StubOutWithMock(dbapi, '_get_filter_args')
dbapi._get_filter_args(fake_model, fake_request,
custom_filters=None).AndReturn(filters)
self.mox.StubOutWithMock(dbapi, '_check_has_field')
dbapi._check_has_field(fake_model, 'id')
result = self.mox.CreateMockAnything()
fake_model.objects.filter(**filters).AndReturn(result)
result.order_by('id').AndReturn(result)
result.__getitem__(slice(None, None, None)).AndReturn(result)
self.mox.ReplayAll()
query_result = dbapi.get_db_objects(fake_model, fake_request, 'id')
self.assertEquals(query_result, result)
self.mox.VerifyAll()