Best Python code snippet using localstack_python
test_error_injection.py
Source:test_error_injection.py
...31 dynamodb = aws_stack.connect_to_resource("dynamodb")32 # create table with stream forwarding config33 aws_stack.create_dynamodb_table(TEST_TABLE_NAME, partition_key=PARTITION_KEY)34 return dynamodb.Table(TEST_TABLE_NAME)35 def assert_zero_probability_read_error_injection(self, table, partition_key):36 # by default, no errors37 test_no_errors = table.get_item(Key={PARTITION_KEY: partition_key})38 assert test_no_errors["ResponseMetadata"]["HTTPStatusCode"] == 20039 def test_dynamodb_error_injection(self):40 table = self.get_dynamodb_table()41 partition_key = short_uid()42 self.assert_zero_probability_read_error_injection(table, partition_key)43 # with a probability of 1, always throw errors44 config.DYNAMODB_ERROR_PROBABILITY = 1.045 with self.assertRaises(ClientError):46 table.get_item(Key={PARTITION_KEY: partition_key})47 # reset probability to zero48 config.DYNAMODB_ERROR_PROBABILITY = 0.049 def test_dynamodb_read_error_injection(self):50 table = self.get_dynamodb_table()51 partition_key = short_uid()52 self.assert_zero_probability_read_error_injection(table, partition_key)53 # with a probability of 1, always throw errors54 config.DYNAMODB_READ_ERROR_PROBABILITY = 1.055 with self.assertRaises(ClientError):56 table.get_item(Key={PARTITION_KEY: partition_key})57 # reset probability to zero58 config.DYNAMODB_READ_ERROR_PROBABILITY = 0.059 def test_dynamodb_write_error_injection(self):60 table = self.get_dynamodb_table()61 # by default, no errors62 test_no_errors = table.put_item(Item={PARTITION_KEY: short_uid(), "data": "foobar123"})63 self.assertEqual(200, test_no_errors["ResponseMetadata"]["HTTPStatusCode"])64 # with a probability of 1, always throw errors65 config.DYNAMODB_WRITE_ERROR_PROBABILITY = 1.066 with self.assertRaises(ClientError):...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!