def test_annotate_diff_resource_vers_no_annotation(self, m_patch, m_count):
m_count.return_value = list(range(1, 5))
path = '/test'
annotations = {'a1': 'v1', 'a2': 'v2'}
annotating_resource_version = '123'
annotating_obj = {'metadata': {
'annotations': annotations,
'resourceVersion': annotating_resource_version}}
annotating_data = jsonutils.dumps(annotating_obj, sort_keys=True)
new_resource_version = '456'
new_obj = {'metadata': {
'resourceVersion': new_resource_version}}
resolution_obj = annotating_obj.copy()
resolution_obj['metadata']['resourceVersion'] = new_resource_version
resolution_data = jsonutils.dumps(resolution_obj, sort_keys=True)
m_resp_conflict = mock.MagicMock()
m_resp_conflict.ok = False
m_resp_conflict.status_code = requests.codes.conflict
m_resp_good = mock.MagicMock()
m_resp_good.ok = True
m_resp_good.json.return_value = resolution_obj
m_patch.side_effect = (m_resp_conflict, m_resp_good)
with mock.patch.object(self.client, 'get') as m_get:
m_get.return_value = new_obj
self.assertEqual(annotations, self.client.annotate(
path, annotations,
resource_version=annotating_resource_version))
m_patch.assert_has_calls([
mock.call(self.base_url + path,
data=annotating_data,
headers=mock.ANY,
cert=(None, None), verify=False),
mock.call(self.base_url + path,
data=resolution_data,
headers=mock.ANY,
cert=(None, None), verify=False)])
评论列表
文章目录