How to use describe_key method in localstack

Best Python code snippet using localstack_python

test_kms_key.py

Source:test_kms_key.py Github

copy

Full Screen

1from botocore.exceptions import ClientError2from spacel.security.kms_key import KmsKeyFactory3from test.security import BaseKmsTest, KEY_ARN, CLIENT_ERROR4ALIAS = 'alias/test-orbit-test-app'5KEY_METADATA = {6 'KeyMetadata': {7 'Arn': KEY_ARN,8 'Enabled': True9 }10}11class TestKmsKeyFactory(BaseKmsTest):12 def setUp(self):13 super(TestKmsKeyFactory, self).setUp()14 self.kms_factory = KmsKeyFactory(self.clients)15 def test_get_key_alias(self):16 alias = self.kms_factory.get_key_alias(self.app_region)17 self.assertEquals(ALIAS, alias)18 def test_get_key_exists(self):19 self.kms.describe_key.return_value = KEY_METADATA20 key = self.kms_factory.get_key(self.app_region)21 self.assertEquals(KEY_ARN, key)22 self.kms.describe_key.assert_called_with(KeyId=ALIAS)23 self.kms.create_key.assert_not_called()24 def test_get_key_exists_disabled(self):25 key_metadata = KEY_METADATA.copy()26 key_metadata['KeyMetadata']['Enabled'] = False27 self.kms.describe_key.return_value = key_metadata28 key = self.kms_factory.get_key(self.app_region)29 self.assertIsNone(key)30 self.kms.describe_key.assert_called_with(KeyId=ALIAS)31 def test_get_key_not_found(self):32 self._key_not_found()33 self.kms_factory.get_key(self.app_region, create=False)34 self.kms.create_key.assert_not_called()35 def test_get_key_not_found_create(self):36 self._key_not_found()37 self.kms_factory.get_key(self.app_region)38 # Key is created:39 self.kms.create_key.assert_called_once_with()40 def test_get_key_exception(self):41 self.kms.describe_key.side_effect = CLIENT_ERROR42 self.assertRaises(ClientError, self.kms_factory.get_key,43 self.app_region)44 def test_create_key(self):45 self.kms.create_key.return_value = KEY_METADATA46 key = self.kms_factory.create_key(self.app_region)47 self.assertEquals(KEY_ARN, key)48 self.kms.describe_key.assert_not_called()49 self.kms.create_key.assert_called_once_with()50 self.kms.create_alias.assert_called_with(AliasName=ALIAS,51 TargetKeyId=KEY_ARN)52 self.kms.schedule_key_deletion.assert_not_called()53 def test_create_key_exception(self):54 self.kms.create_key.return_value = KEY_METADATA55 self.kms.create_alias.side_effect = CLIENT_ERROR56 self.assertRaises(ClientError, self.kms_factory.create_key,57 self.app_region)58 self.kms.schedule_key_deletion.assert_called_with(59 KeyId=KEY_ARN,60 PendingWindowInDays=761 )62 def _key_not_found(self):63 self.kms.describe_key.side_effect = ClientError({64 'Error': {65 'Message': 'Invalid keyId %s' % ALIAS66 }...

Full Screen

Full Screen

kms_barrel.py

Source:kms_barrel.py Github

copy

Full Screen

...28 }29 def __init__(self, oil, **kwargs):30 super().__init__(oil, **kwargs)31 self.cache = {}32 def describe_key(self):33 items_by_region = {}34 for region, client in self.clients.items():35 items_by_region[region] = {}36 for key in self.tap('list_keys')[region]:37 key_id = key['KeyId']38 response = client.describe_key(39 KeyId=key_id40 )41 items_by_region[region][key_id] = response['KeyMetadata']42 self.cache['describe_key'] = items_by_region43 return items_by_region44 def get_key_rotation_status(self):45 items_by_region = {}46 for region, client in self.clients.items():47 items_by_region[region] = {}48 for key in self.tap('list_keys')[region]:49 key_id = key['KeyId']50 response = client.get_key_rotation_status(51 KeyId=key_id52 )...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful