本文整理汇总了Python中stacktach.dbapi.exists_send_status函数的典型用法代码示例。如果您正苦于以下问题:Python exists_send_status函数的具体用法?Python exists_send_status怎么用?Python exists_send_status使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exists_send_status函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_status_batch_multiple_results
def test_send_status_batch_multiple_results(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
messages = {
MESSAGE_ID_1: 200,
}
body_dict = {'messages': messages}
body = json.dumps(body_dict)
fake_request.body = body
self.mox.StubOutWithMock(transaction, 'commit_on_success')
trans_obj = self.mox.CreateMockAnything()
transaction.commit_on_success().AndReturn(trans_obj)
trans_obj.__enter__()
results = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results)
exception = models.InstanceExists.MultipleObjectsReturned()
results.get(message_id=MESSAGE_ID_1).AndRaise(exception)
trans_obj.__exit__(dbapi.APIException().__class__,
mox.IgnoreArg(),
mox.IgnoreArg())
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 500)
body = json.loads(resp.content)
self.assertEqual(body.get("status"), 500)
msg = "Multiple Exists records with message_id = '%s'"
msg = msg % MESSAGE_ID_1
self.assertEqual(body.get("message"), msg)
self.mox.VerifyAll()
示例2: test_send_status_batch
def test_send_status_batch(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
messages = {
MESSAGE_ID_1: 200,
MESSAGE_ID_2: 400
}
body_dict = {'messages': messages}
body = json.dumps(body_dict)
fake_request.body = body
results1 = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results1)
exists1 = self.mox.CreateMockAnything()
results1.get(message_id=MESSAGE_ID_2).AndReturn(exists1)
exists1.save()
results2 = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results2)
exists2 = self.mox.CreateMockAnything()
results2.get(message_id=MESSAGE_ID_1).AndReturn(exists2)
exists2.save()
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 200)
exists1.send_status = 200
self.mox.VerifyAll()
示例3: test_send_status_batch
def test_send_status_batch(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
messages = {
MESSAGE_ID_1: 200,
MESSAGE_ID_2: 400
}
body_dict = {'messages': messages}
body = json.dumps(body_dict)
fake_request.body = body
self.mox.StubOutWithMock(transaction, 'commit_on_success')
trans_obj = self.mox.CreateMockAnything()
transaction.commit_on_success().AndReturn(trans_obj)
trans_obj.__enter__()
results1 = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results1)
exists1 = self.mox.CreateMockAnything()
results1.get(message_id=MESSAGE_ID_2).AndReturn(exists1)
exists1.save()
results2 = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results2)
exists2 = self.mox.CreateMockAnything()
results2.get(message_id=MESSAGE_ID_1).AndReturn(exists2)
exists2.save()
trans_obj.__exit__(None, None, None)
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 200)
exists1.send_status = 200
self.mox.VerifyAll()
示例4: test_send_status
def test_send_status(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
body_dict = {'send_status': 200}
body = json.dumps(body_dict)
fake_request.body = body
exists = self.mox.CreateMockAnything()
result = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(result)
result.get(message_id=MESSAGE_ID_1).AndReturn(exists)
exists.save()
self.mox.ReplayAll()
dbapi.exists_send_status(fake_request, MESSAGE_ID_1)
self.assertEqual(exists.send_status, 200)
self.mox.VerifyAll()
示例5: test_send_status_batch_wrong_method
def test_send_status_batch_wrong_method(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'GET'
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 400)
body = json.loads(resp.content)
self.assertEqual(body.get('status'), 400)
self.assertEqual(body.get('message'), "Invalid method")
self.mox.VerifyAll()
示例6: test_send_status_batch_empty_body
def test_send_status_batch_empty_body(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
fake_request.body = ''
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 400)
body = json.loads(resp.content)
self.assertEqual(body.get('status'), 400)
self.assertEqual(body.get('message'), "Request body required")
self.mox.VerifyAll()
示例7: test_send_status_no_body
def test_send_status_no_body(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
fake_request.body = None
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, MESSAGE_ID_1)
self.assertEqual(resp.status_code, 400)
body = json.loads(resp.content)
self.assertEqual(body.get("status"), 400)
self.assertEqual(body.get("message"), "Request body required")
self.mox.VerifyAll()
示例8: test_send_status_batch_bad_body
def test_send_status_batch_bad_body(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
body_dict = {'bad': 'body'}
fake_request.body = json.dumps(body_dict)
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 400)
body = json.loads(resp.content)
self.assertEqual(body.get('status'), 400)
msg = "'messages' missing from request body"
self.assertEqual(body.get('message'), msg)
self.mox.VerifyAll()
示例9: test_send_status_batch_accepts_post_for_nova_and_glance_when_version_is_1
def test_send_status_batch_accepts_post_for_nova_and_glance_when_version_is_1(
self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'POST'
fake_request.GET = {'service': 'glance'}
messages = {
'nova': {MESSAGE_ID_3: 201},
'glance': {MESSAGE_ID_1: 201, MESSAGE_ID_2: 201}
}
body_dict = {'version': 1, 'messages': messages}
body = json.dumps(body_dict)
fake_request.body = body
self.mox.StubOutWithMock(transaction, 'commit_on_success')
trans_obj = self.mox.CreateMockAnything()
transaction.commit_on_success().AndReturn(trans_obj)
trans_obj.__enter__()
results1 = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results1)
exists1 = self.mox.CreateMockAnything()
results1.get(message_id=MESSAGE_ID_3).AndReturn(exists1)
exists1.save()
trans_obj.__exit__(None, None, None)
trans_obj = self.mox.CreateMockAnything()
transaction.commit_on_success().AndReturn(trans_obj)
trans_obj.__enter__()
results1 = self.mox.CreateMockAnything()
models.ImageExists.objects.select_for_update().AndReturn(results1)
exists1A = self.mox.CreateMockAnything()
exists1B = self.mox.CreateMockAnything()
results1.filter(message_id=MESSAGE_ID_2).AndReturn(
[exists1A, exists1B])
exists1A.save()
exists1B.save()
results2 = self.mox.CreateMockAnything()
models.ImageExists.objects.select_for_update().AndReturn(results2)
exists2A = self.mox.CreateMockAnything()
exists2B = self.mox.CreateMockAnything()
results2.filter(message_id=MESSAGE_ID_1).AndReturn(
[exists2A, exists2B])
exists2A.save()
exists2B.save()
trans_obj.__exit__(None, None, None)
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 200)
self.mox.VerifyAll()
示例10: test_send_status_multiple_results
def test_send_status_multiple_results(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
body_dict = {'send_status': 200}
body = json.dumps(body_dict)
fake_request.body = body
result = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(result)
exception = models.InstanceExists.MultipleObjectsReturned()
result.get(message_id=MESSAGE_ID_1).AndRaise(exception)
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, MESSAGE_ID_1)
self.assertEqual(resp.status_code, 500)
body = json.loads(resp.content)
self.assertEqual(body.get("status"), 500)
msg = "Multiple Exists records with message_id = '%s'"
msg = msg % MESSAGE_ID_1
self.assertEqual(body.get("message"), msg)
self.mox.VerifyAll()
示例11: test_send_status_batch_not_found
def test_send_status_batch_not_found(self):
fake_request = self.mox.CreateMockAnything()
fake_request.method = 'PUT'
messages = {
MESSAGE_ID_1: 200,
}
body_dict = {'messages': messages}
body = json.dumps(body_dict)
fake_request.body = body
results = self.mox.CreateMockAnything()
models.InstanceExists.objects.select_for_update().AndReturn(results)
exception = models.InstanceExists.DoesNotExist()
results.get(message_id=MESSAGE_ID_1).AndRaise(exception)
self.mox.ReplayAll()
resp = dbapi.exists_send_status(fake_request, 'batch')
self.assertEqual(resp.status_code, 404)
body = json.loads(resp.content)
self.assertEqual(body.get("status"), 404)
msg = "Could not find Exists record with message_id = '%s'"
msg = msg % MESSAGE_ID_1
self.assertEqual(body.get("message"), msg)
self.mox.VerifyAll()