How to use _invoke_s3_via_edge_multipart_form method in localstack

Best Python code snippet using localstack_python

test_edge.py

Source:test_edge.py Github

copy

Full Screen

...14 edge_port = config.EDGE_PORT_HTTP or config.EDGE_PORT15 edge_url = '%s:/​/​localhost:%s' % (get_service_protocol(), edge_port)16 if is_api_enabled('s3'):17 self._invoke_s3_via_edge(edge_url)18 self._invoke_s3_via_edge_multipart_form(edge_url)19 if is_api_enabled('kinesis'):20 self._invoke_kinesis_via_edge(edge_url)21 if is_api_enabled('dynamodbstreams'):22 self._invoke_dynamodbstreams_via_edge(edge_url)23 if is_api_enabled('firehose'):24 self._invoke_firehose_via_edge(edge_url)25 if is_api_enabled('stepfunctions'):26 self._invoke_stepfunctions_via_edge(edge_url)27 def _invoke_kinesis_via_edge(self, edge_url):28 client = aws_stack.connect_to_service('kinesis', endpoint_url=edge_url)29 result = client.list_streams()30 self.assertIn('StreamNames', result)31 def _invoke_dynamodbstreams_via_edge(self, edge_url):32 client = aws_stack.connect_to_service('dynamodbstreams', endpoint_url=edge_url)33 result = client.list_streams()34 self.assertIn('Streams', result)35 def _invoke_firehose_via_edge(self, edge_url):36 client = aws_stack.connect_to_service('firehose', endpoint_url=edge_url)37 result = client.list_delivery_streams()38 self.assertIn('DeliveryStreamNames', result)39 def _invoke_stepfunctions_via_edge(self, edge_url):40 client = aws_stack.connect_to_service('stepfunctions', endpoint_url=edge_url)41 result = client.list_state_machines()42 self.assertIn('stateMachines', result)43 def _invoke_s3_via_edge(self, edge_url):44 client = aws_stack.connect_to_service('s3', endpoint_url=edge_url)45 bucket_name = 'edge-%s' % short_uid()46 client.create_bucket(Bucket=bucket_name)47 result = client.head_bucket(Bucket=bucket_name)48 self.assertEqual(result['ResponseMetadata']['HTTPStatusCode'], 200)49 client.delete_bucket(Bucket=bucket_name)50 bucket_name = 'edge-%s' % short_uid()51 object_name = 'testobject'52 bucket_url = '%s/​%s' % (edge_url, bucket_name)53 result = requests.put(bucket_url, verify=False)54 self.assertEqual(result.status_code, 200)55 result = client.head_bucket(Bucket=bucket_name)56 self.assertEqual(result['ResponseMetadata']['HTTPStatusCode'], 200)57 headers = {'Content-Type': 'application/​x-www-form-urlencoded'}58 result = requests.post(bucket_url, data='key=%s&file=file_content_123' % object_name,59 headers=headers, verify=False)60 self.assertEqual(result.status_code, 204)61 bucket_url = '%s/​example' % (bucket_url)62 result = requests.put(bucket_url, data='hello', verify=False)63 self.assertEqual(result.status_code, 200)64 result = io.BytesIO()65 client.download_fileobj(bucket_name, object_name, result)66 self.assertEqual('file_content_123', to_str(result.getvalue()))67 def _invoke_s3_via_edge_multipart_form(self, edge_url):68 client = aws_stack.connect_to_service('s3', endpoint_url=edge_url)69 bucket_name = 'edge-%s' % short_uid()70 object_name = 'testobject'71 object_data = b'testdata'72 client.create_bucket(Bucket=bucket_name)73 presigned_post = client.generate_presigned_post(bucket_name, object_name)74 files = {'file': object_data}75 r = requests.post(presigned_post['url'], data=presigned_post['fields'], files=files, verify=False)76 self.assertEqual(r.status_code, 204)77 result = io.BytesIO()78 client.download_fileobj(bucket_name, object_name, result)79 self.assertEqual(to_str(object_data), to_str(result.getvalue()))80 client.delete_object(Bucket=bucket_name, Key=object_name)81 client.delete_bucket(Bucket=bucket_name)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Putting Together a Testing Team

As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

A Complete Guide To CSS Container Queries

In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.

Considering Agile Principles from a different angle

In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.

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