How to use delete_api_key method in localstack

Best Python code snippet using localstack_python

test_v1_auth_keys.py

Source:test_v1_auth_keys.py Github

copy

Full Screen

1import json2from jose import jws3from unittest.mock import patch, DEFAULT4from backend.corpora.common.auth0_manager import auth0_management_session5from tests.unit.backend.corpora.api_server.base_api_test import BaseAuthAPITest, get_cxguser_token6class TestKeys(BaseAuthAPITest):7 @classmethod8 def setUpClass(cls):9 auth0_management_session.domain = "localhost" # setting this so CorporaAuthConfig isn't used in the test10 super().setUpClass()11 cls.api_key_id = "auth0_generate_api_key_id"12 cls.user_name = "test_user_id"13 cls.email = "fake_user@email.com"14 cls.api_key_secret = "a secret_value"15 @patch.multiple(16 "backend.corpora.lambdas.api.v1.auth.keys.auth0_management_session",17 get_user_api_key_identity=DEFAULT,18 store_api_key=DEFAULT,19 link_api_key=DEFAULT,20 delete_api_key=DEFAULT,21 )22 @patch.multiple("backend.corpora.lambdas.api.v1.auth.keys", CorporaAuthConfig=DEFAULT, get_userinfo=DEFAULT)23 def test__create_key__201(24 self, CorporaAuthConfig, get_userinfo, get_user_api_key_identity, store_api_key, link_api_key, delete_api_key25 ):26 get_user_api_key_identity.return_value = None27 store_api_key.return_value = self.api_key_id28 link_api_key.return_value = None29 delete_api_key.return_value = None30 CorporaAuthConfig().api_key_secret = self.api_key_secret31 get_userinfo.return_value = {"email": "fake_user@email.com"}32 CorporaAuthConfig().days_to_live = 133 headers = {"host": "localhost", "Content-Type": "application/json", "Cookie": get_cxguser_token()}34 response = self.app.post("/dp/v1/auth/key", headers=headers)35 self.assertEqual(201, response.status_code)36 body = json.loads(response.data)37 key = body["key"]38 payload = jws.verify(key, self.api_key_secret, algorithms=["HS256"])39 payload = json.loads(payload.decode("utf-8"))40 self.assertEqual(self.user_name, payload["sub"])41 delete_api_key.assert_not_called()42 store_api_key.assert_called_once_with(key, self.email)43 link_api_key.assert_called_once_with(self.user_name, self.api_key_id)44 get_user_api_key_identity.assert_called_once_with(self.user_name)45 def test__create_key__401(self):46 headers = {"host": "localhost", "Content-Type": "application/json"}47 response = self.app.post("/dp/v1/auth/key", headers=headers)48 self.assertEqual(response.status_code, 401)49 @patch.multiple(50 "backend.corpora.lambdas.api.v1.auth.keys.auth0_management_session",51 get_user_api_key_identity=DEFAULT,52 store_api_key=DEFAULT,53 link_api_key=DEFAULT,54 delete_api_key=DEFAULT,55 )56 @patch.multiple("backend.corpora.lambdas.api.v1.auth.keys", CorporaAuthConfig=DEFAULT, get_userinfo=DEFAULT)57 def test__regenerate_key__201(58 self, CorporaAuthConfig, get_userinfo, get_user_api_key_identity, store_api_key, link_api_key, delete_api_key59 ):60 CorporaAuthConfig().api_key_secret = self.api_key_secret61 CorporaAuthConfig().days_to_live = 162 get_userinfo.return_value = {"email": "fake_user@email.com"}63 get_user_api_key_identity.return_value = {"user_id": self.api_key_id}64 delete_api_key.return_value = None65 store_api_key.return_value = self.api_key_id66 link_api_key.return_value = None67 headers = {"host": "localhost", "Content-Type": "application/json", "Cookie": get_cxguser_token()}68 response = self.app.post("/dp/v1/auth/key", headers=headers)69 self.assertEqual(201, response.status_code)70 body = json.loads(response.data)71 key = body["key"]72 payload = jws.verify(key, self.api_key_secret, algorithms=["HS256"])73 payload = json.loads(payload.decode("utf-8"))74 self.assertEqual(self.user_name, payload["sub"])75 get_user_api_key_identity.assert_called_once_with(self.user_name)76 delete_api_key.assert_called_once()77 store_api_key.assert_called_once_with(key, self.email)78 link_api_key.assert_called_once_with(self.user_name, self.api_key_id)79 @patch.multiple(80 "backend.corpora.lambdas.api.v1.auth.keys.auth0_management_session",81 get_user_api_key_identity=DEFAULT,82 delete_api_key=DEFAULT,83 )84 def test__delete_key__202(self, get_user_api_key_identity, delete_api_key):85 get_user_api_key_identity.return_value = {"user_id": self.api_key_id, "username": "ABCDEF"}86 delete_api_key.return_value = None87 headers = {"host": "localhost", "Content-Type": "application/json", "Cookie": get_cxguser_token()}88 response = self.app.delete("/dp/v1/auth/key", headers=headers)89 self.assertEqual(response.status_code, 202)90 def test__delete_key__401(self):91 headers = {"host": "localhost", "Content-Type": "application/json"}92 response = self.app.delete("/dp/v1/auth/key", headers=headers)93 self.assertEqual(response.status_code, 401)94 @patch("backend.corpora.lambdas.api.v1.auth.keys.auth0_management_session.get_user_api_key_identity")95 def test__delete_key__404(self, get_user_api_key_identity):96 get_user_api_key_identity.return_value = None97 headers = {"host": "localhost", "Content-Type": "application/json", "Cookie": get_cxguser_token()}98 response = self.app.delete("/dp/v1/auth/key", headers=headers)99 self.assertEqual(404, response.status_code)100 @patch("backend.corpora.lambdas.api.v1.auth.keys.auth0_management_session.get_user_api_key_identity")101 def test__get_key__200(self, get_user_api_key_identity):102 get_user_api_key_identity.return_value = {"user_id": self.api_key_id}103 headers = {"host": "localhost", "Content-Type": "application/json", "Cookie": get_cxguser_token()}104 response = self.app.get("/dp/v1/auth/key", headers=headers)105 self.assertEqual(200, response.status_code)106 get_user_api_key_identity.assert_called_once()107 def test__get_key__401(self):108 headers = {"host": "localhost", "Content-Type": "application/json"}109 response = self.app.get("/dp/v1/auth/key", headers=headers)110 self.assertEqual(response.status_code, 401)111 @patch("backend.corpora.lambdas.api.v1.auth.keys.auth0_management_session.get_user_api_key_identity")112 def test__get_key__404(self, get_user_api_key_identity):113 get_user_api_key_identity.return_value = None114 headers = {"host": "localhost", "Content-Type": "application/json", "Cookie": get_cxguser_token()}115 response = self.app.get("/dp/v1/auth/key", headers=headers)116 self.assertEqual(404, response.status_code)...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.urls import path2from django.contrib.auth.decorators import login_required3from .views import *4from django.views.generic import RedirectView5urlpatterns = [6 path('', login_required(HomeView.as_view()), name=''),7 path('dashboard', login_required(DashboardView.as_view()), name='dashboard'),8 path('data_bridges', login_required(DataBridgesView.as_view()), name='data_bridges'),9 path('save_bridge', login_required(save_bridge), name='save_bridge'),10 path('report_bridge', login_required(report_bridge), name='report_bridge'),11 path('power_bridge', login_required(power_bridge), name='power_bridge'),12 path('delete_bridge', login_required(delete_bridge), name='delete_bridge'),13 path('profile', login_required(ProfileView.as_view()), name='profile'),14 path('change_password', login_required(ChangePasswordView.as_view()), name='change_password'),15 path('user_api_mng', login_required(UserApiMngView.as_view()), name='user_api_mng'),16 path('save_api_key', login_required(save_api_key), name='save_api_key'),17 path('get_api_key', login_required(get_api_key), name='get_api_key'),18 path('delete_api_key', login_required(delete_api_key), name='delete_api_key'),19 path('user_api_ref', login_required(UserApiRefView.as_view()), name='user_api_ref'),20 path('user', login_required(UserView.as_view()), name='user'),21 path('edit_user_general/<int:param1>', login_required(EditUserGeneralView.as_view()), name='edit_user_general'),22 path('edit_user_account/<int:param1>', login_required(EditUserAccountView.as_view()), name='edit_user_account'),23 path('reset_password/<int:param1>', login_required(ResetPasswordView.as_view()), name='reset_password'),24 path('save_user', login_required(save_user), name='save_user'),25 path('update_user_balance', login_required(update_user_balance), name='update_user_balance'),26 path('delete_user', login_required(delete_user), name='delete_user'),27 path('setting_server', login_required(SettingServerView.as_view()), name='setting_server'),28 path('setting_price', login_required(SettingPriceView.as_view()), name='setting_price'),29 path('setting_smtp', login_required(SettingSMTPView.as_view()), name='setting_smtp'),30 path('test_smtp', login_required(test_smtp), name='test_smtp'),31 path('save_setting', login_required(save_setting), name='save_setting'),32 path('404_page', Page404View.as_view(), name='404_page'),...

Full Screen

Full Screen

api_key.py

Source:api_key.py Github

copy

Full Screen

...51@helper.delete52def delete(event, _):53 p = properties(event)54 key_id = p.physical_resource_id55 return delete_api_key(key_id)56def delete_api_key(key_id):57 try:58 apg.delete_api_key(59 apiKey=key_id60 )61 except apg.exceptions.NotFoundException:62 pass63 return key_id64def handler(event, context):65 logger.info('event: %s', event)...

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