How to use create_api_key method in localstack

Best Python code snippet using localstack_python

test_apikey.py

Source:test_apikey.py Github

copy

Full Screen

1from common_fixtures import * # NOQA2from gdapi import ApiError3def test_api_key_create(client):4 assert_required_fields(client.create_api_key)5 key = client.create_api_key()6 assert key.state == 'registering'7 assert key.publicValue is not None8 assert key.secretValue is not None9 key = client.wait_transitioning(key)10 assert key.state == 'active'11 assert key.publicValue is not None12 assert key.secretValue is None13def test_api_key_create_admin(super_client):14 assert_required_fields(super_client.create_api_key)15 key = super_client.create_api_key()16 assert key.state == 'registering'17 assert key.publicValue is not None18 assert key.secretValue is not None19 key = super_client.wait_transitioning(key)20 assert key.state == 'active'21 assert key.publicValue is not None22 assert key.secretValue is not None23def test_api_key_null_secret(super_client, context):24 public_value = random_str()25 key = super_client.create_api_key(accountId=context.project.id,26 publicValue=public_value,27 secretValue=None)28 assert key.state == 'registering'29 assert key.publicValue == public_value30 assert key.secretValue is None31 key = super_client.wait_transitioning(key)32 assert key.state == 'active'33 assert key.publicValue == public_value34 assert key.secretValue is None35def test_api_key_422_on_identical_keys(admin_user_client):36 public_value = random_str()37 secret_value = random_str()38 key = admin_user_client.create_api_key(publicValue=public_value,39 secretValue=secret_value)40 admin_user_client.wait_transitioning(key)41 with pytest.raises(ApiError) as e:42 admin_user_client.create_api_key(publicValue=public_value,43 secretValue=secret_value)44 assert e.value.error.status == 42245 public_value = random_str()46 secret_value = random_str()47 key = admin_user_client.create_api_key(publicValue=public_value,48 secretValue=secret_value)49 admin_user_client.wait_transitioning(key)50 with pytest.raises(ApiError) as e:51 admin_user_client.create_api_key(publicValue=public_value,52 secretValue=secret_value)53 assert e.value.error.status == 42254def test_identical_public_value_password(admin_user_client):55 public_value = random_str()56 secret_value = random_str()57 key = admin_user_client.create_password(publicValue=public_value,58 secretValue=secret_value)59 admin_user_client.wait_success(key)60 with pytest.raises(ApiError) as e:61 admin_user_client.create_password(publicValue=public_value,62 secretValue=secret_value)63 assert e.value.error.status == 42264 public_value = random_str()65 secret_value = random_str()66 admin_user_client.create_password(publicValue=public_value,67 secretValue=secret_value)68 with pytest.raises(ApiError) as e:69 admin_user_client.create_password(publicValue=public_value,70 secretValue=secret_value)71 assert e.value.error.status == 42272def test_identical_public_value_password_inactive_removed(admin_user_client):73 public_value = random_str() + random_str()74 secret_value = random_str()75 key = admin_user_client.create_password(publicValue=public_value,76 secretValue=secret_value)77 key = admin_user_client.wait_success(key)78 admin_user_client.wait_success(key.deactivate())79 with pytest.raises(ApiError) as e:80 admin_user_client.create_password(publicValue=public_value,81 secretValue=secret_value)82 assert e.value.error.status == 42283def test_identical_public_value_api_key_inactive_removed(admin_user_client):84 public_value = random_str() + random_str()85 secret_value = random_str()86 key = admin_user_client.create_api_key(publicValue=public_value,87 secretValue=secret_value)88 key = admin_user_client.wait_success(key)89 admin_user_client.wait_success(key.deactivate())90 with pytest.raises(ApiError) as e:91 admin_user_client.create_api_key(publicValue=public_value,92 secretValue=secret_value)...

Full Screen

Full Screen

test_embed.py

Source:test_embed.py Github

copy

Full Screen

...23# TODO: this should be applied to the new API endpoint24class TestPublicDashboard(BaseTestCase):25 def test_success(self):26 dashboard = self.factory.create_dashboard()27 api_key = self.factory.create_api_key(object=dashboard)28 res = self.make_request(29 "get",30 "/public/dashboards/{}".format(api_key.api_key),31 user=False,32 is_json=False,33 )34 self.assertEqual(res.status_code, 200)35 self.assertIn("frame-ancestors *", res.headers["Content-Security-Policy"])36 self.assertNotIn("X-Frame-Options", res.headers)37 def test_works_for_logged_in_user(self):38 dashboard = self.factory.create_dashboard()39 api_key = self.factory.create_api_key(object=dashboard)40 res = self.make_request(41 "get", "/public/dashboards/{}".format(api_key.api_key), is_json=False42 )43 self.assertEqual(res.status_code, 200)44 def test_bad_token(self):45 res = self.make_request(46 "get", "/public/dashboards/bad-token", user=False, is_json=False47 )48 self.assertEqual(res.status_code, 302)49 def test_inactive_token(self):50 dashboard = self.factory.create_dashboard()51 api_key = self.factory.create_api_key(object=dashboard, active=False)52 res = self.make_request(53 "get",54 "/public/dashboards/{}".format(api_key.api_key),55 user=False,56 is_json=False,57 )58 self.assertEqual(res.status_code, 302)59 # Not relevant for now, as tokens in api_keys table are only created for dashboards. Once this changes, we should60 # add this test.61 # def test_token_doesnt_belong_to_dashboard(self):62 # pass63class TestAPIPublicDashboard(BaseTestCase):64 def test_success(self):65 dashboard = self.factory.create_dashboard()66 api_key = self.factory.create_api_key(object=dashboard)67 res = self.make_request(68 "get",69 "/api/dashboards/public/{}".format(api_key.api_key),70 user=False,71 is_json=False,72 )73 self.assertEqual(res.status_code, 200)74 self.assertIn("frame-ancestors *", res.headers["Content-Security-Policy"])75 self.assertNotIn("X-Frame-Options", res.headers)76 def test_works_for_logged_in_user(self):77 dashboard = self.factory.create_dashboard()78 api_key = self.factory.create_api_key(object=dashboard)79 res = self.make_request(80 "get", "/api/dashboards/public/{}".format(api_key.api_key), is_json=False81 )82 self.assertEqual(res.status_code, 200)83 def test_bad_token(self):84 res = self.make_request(85 "get", "/api/dashboards/public/bad-token", user=False, is_json=False86 )87 self.assertEqual(res.status_code, 404)88 def test_inactive_token(self):89 dashboard = self.factory.create_dashboard()90 api_key = self.factory.create_api_key(object=dashboard, active=False)91 res = self.make_request(92 "get",93 "/api/dashboards/public/{}".format(api_key.api_key),94 user=False,95 is_json=False,96 )97 self.assertEqual(res.status_code, 404)98 # Not relevant for now, as tokens in api_keys table are only created for dashboards. Once this changes, we should99 # add this test.100 # def test_token_doesnt_belong_to_dashboard(self):...

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