def test_create(self): mock_response = mock.Mock() mock_response.status_code = 200 mock_response.headers = {} mock_response.json.return_value = EXAMPLE.copy() self.sess.post.return_value = mock_response key = { 'key_id': 'key', 'encryption_context': { 'a': 'b' }, 'datakey_length': 200, 'sequence': 'seq', } sot = _key.DataKey(**key) result = sot.create(self.sess, prepend_key=False) call_args = self.sess.post.call_args_list[0] self.assertEqual('/kms/create-datakey', call_args[0][0]) self.assertDictEqual(key, call_args[1]['json']) self.sess.post.assert_called_once() self.assertEqual(sot, result) self.assertEqual(EXAMPLE['key_id'], sot.key_id) self.assertEqual(EXAMPLE['plain_text'], sot.plain_text) self.assertEqual(EXAMPLE['cipher_text'], sot.cipher_text)
def test_basic(self): sot = _key.DataKey() self.assertEqual(None, sot.resource_key) self.assertEqual(None, sot.resources_key) self.assertEqual('/kms', sot.base_path) self.assertEqual('/kms/create-datakey', sot.create_path) self.assertFalse(sot.allow_list) self.assertTrue(sot.allow_create) self.assertFalse(sot.allow_get) self.assertTrue(sot.allow_update) self.assertFalse(sot.allow_delete)
def setUp(self): super(TestKey, self).setUp() self.sess = mock.Mock(spec=adapter.Adapter) self.sess.post = mock.Mock() self.sot = _key.DataKey()