Best Python code snippet using localstack_python
get_subscription_handlers.py
Source: get_subscription_handlers.py
1from aiogram.dispatcher import FSMContext2from dispatcher import dp3from aiogram.types import Message4from aiogram.dispatcher.filters import Text5from dispatcher import bot6from config.messages import message_texts7from config.keyboards import keyboards_texts8from keyboards.reply_keyboards import get_keyboard9from states.accept_terms import AcceptTerms10from states.get_subscsription import GetSubscriptionStates11from config.payments import PAYMENT_TOKEN, SUBSCRIPTION_IMAGE_URL, SUBSCRIPTION_IMAGE_HEIGHT, SUBSCRIPTION_IMAGE_WIDTH,\12 SUBSCRIPTION_PHOTO_SIZE, SUBSCRIPTION_PRICE13from utils.db.subscription import has_free_month, get_sub_days_left14from utils.channel.telegram_channel import subscribe_user15@dp.message_handler(Text(equals=keyboards_texts['start']['subscription']), state=AcceptTerms.terms_accepted)16async def get_subscription_confirm(message: Message):17 if has_free_month(message.from_user.id):18 approve_kb_markup = get_keyboard('confirm_subscription')19 await message.answer(message_texts['free_period_info'], reply_markup=approve_kb_markup)20 await GetSubscriptionStates.waiting_for_confirm_free.set()21 else:22 if (days_left := get_sub_days_left(message.from_user.id)) > 0:23 left_days_notice = message_texts['days_left_notification'].format(days_left=days_left)24 await message.answer(left_days_notice)25 approve_kb_markup = get_keyboard('confirm_subscription')26 await message.answer(message_texts['subscription_terms'], reply_markup=approve_kb_markup)27 await GetSubscriptionStates.waiting_for_confirm.set()28@dp.message_handler(Text(equals=keyboards_texts['confirm_subscription']['yes']),29 state=GetSubscriptionStates.waiting_for_confirm_free)30async def free_month_confirmed(message: Message, state: FSMContext):31 invite_text = await subscribe_user(message.from_user.id)32 choose_action_keyboard = get_keyboard('start')33 await message.answer(invite_text, reply_markup=choose_action_keyboard)34 await state.finish()35 await AcceptTerms.terms_accepted.set()36@dp.message_handler(Text(equals=keyboards_texts['confirm_subscription']['yes']),37 state=GetSubscriptionStates.waiting_for_confirm)38async def subscription_confirmed(message: Message):39 await GetSubscriptionStates.waiting_for_payment.set()40 if PAYMENT_TOKEN.split(":")[1] == "TEST":41 await message.answer(message_texts['test_payment'], reply_markup=get_keyboard('remove'))42 await bot.send_invoice(43 message.chat.id,44 title=message_texts['subscription_payment_title'],45 description=message_texts['subscription_description'],46 provider_token=PAYMENT_TOKEN,47 currency='rub',48 photo_url=SUBSCRIPTION_IMAGE_URL,49 photo_height=SUBSCRIPTION_IMAGE_HEIGHT,50 photo_width=SUBSCRIPTION_IMAGE_WIDTH,51 photo_size=SUBSCRIPTION_PHOTO_SIZE,52 is_flexible=False,53 prices=[SUBSCRIPTION_PRICE],54 start_parameter='channel-subscription',55 payload='subscription'56 )57@dp.message_handler(Text(equals=keyboards_texts['confirm_subscription']['no']),58 state=[GetSubscriptionStates.waiting_for_confirm,59 GetSubscriptionStates.waiting_for_confirm_free])60async def subscription_deny(message: Message, state: FSMContext):61 await state.finish()62 await AcceptTerms.terms_accepted.set()63 choose_action_keyboard = get_keyboard('start')...
test_confirmation.py
Source: test_confirmation.py
...19 self.assertDictEqual(20 self.testlist.pending_subscriptions(),21 {token: self.p2_name}22 )23 self.testlist.confirm_subscription(token)24 self.assertMembers([self.creator_name, self.p2_name])25 self.assertDictEqual(26 self.testlist.pending_subscriptions(),27 {}28 )29 def testToggleMembership(self):30 status, token = self.testlist.toggle_membership(self.p2_name)31 self.assertTrue(status)32 self.testlist.confirm_subscription(token)33 self.assertMembers([self.creator_name, self.p2_name])34 status, token = self.testlist.toggle_membership(self.p2_name)35 self.assertFalse(status)36 self.testlist.confirm_subscription(token)37 self.assertMembers([self.creator_name])38 def testCancelPendingAddition(self):39 token = self.testlist.add_member(self.p2_name)40 self.testlist.cancel_pending_subscription(token)41 self.assertMembers([self.creator_name])42 self.assertDictEqual(43 self.testlist.pending_subscriptions(),44 {}45 )46 def testNonExistentRequests(self):47 with self.assertRaises(exceptions.NoSuchRequestException):48 self.testlist.confirm_subscription('Does Not Exists')49 with self.assertRaises(exceptions.NoSuchRequestException):50 self.testlist.cancel_pending_subscription('Does Not Exists')51 def testNonSilentRemoval(self):52 self.testlist.add_member_silently(self.p2_name)53 token = self.testlist.remove_member(self.p2_name)54 self.assertMembers([self.creator_name, self.p2_name])55 ## Assertion removed, as of MailmanCore<3.3.3 pending dict will be empty56 # self.assertDictEqual(57 # self.testlist.pending_subscriptions(),58 # {token: self.p2_name}59 #)60 self.testlist.confirm_subscription(token)61 self.assertMembers([self.creator_name])62 self.assertDictEqual(63 self.testlist.pending_subscriptions(),64 {}65 )66 def testCancelOnReRequest(self):67 with settings.TemporarySettingsChange(RETRY_CANCELS_PENDING_SUBSCRIPTION=True):68 token = self.testlist.add_member(self.p2_name)69 self.assertMembers([self.creator_name])70 self.assertDictEqual(71 self.testlist.pending_subscriptions(),72 {token: self.p2_name}73 )74 token2 = self.testlist.add_member(self.p2_name)75 self.assertMembers([self.creator_name])76 self.assertDictEqual(77 self.testlist.pending_subscriptions(),78 {token2: self.p2_name}79 )80 self.testlist.confirm_subscription(token2)81 self.assertMembers([self.creator_name, self.p2_name])82 def testFailOnReRequest(self):83 with settings.TemporarySettingsChange(RETRY_CANCELS_PENDING_SUBSCRIPTION=False):84 token = self.testlist.add_member(self.p2_name)85 self.assertMembers([self.creator_name])86 self.assertDictEqual(87 self.testlist.pending_subscriptions(),88 {token: self.p2_name}89 )90 with self.assertRaisesRegex(urllib.error.HTTPError, 'already pending'):91 token2 = self.testlist.add_member(self.p2_name)92 self.assertDictEqual(93 self.testlist.pending_subscriptions(),94 {token: self.p2_name}...
urls.py
Source: urls.py
1from django.urls import path2from newsletter.views import (3 newsletter_page,4 newsletter_registered_user,5 confirm_subscription,6)7urlpatterns = [8 path("", newsletter_page, name="newsletter_page"),9 path(10 "registered_user/<pk>/",11 newsletter_registered_user,12 name="newsletter_registered_user",13 ),14 path(15 "confirm_subscription/<slug:uidb64>/",16 confirm_subscription,17 name="confirm_subscription",18 ),...
Check out the latest blogs from LambdaTest on this topic:
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Many theoretical descriptions explain the role of the Scrum Master as a vital member of the Scrum team. However, these descriptions do not provide an honest answer to the fundamental question: “What are the day-to-day activities of a Scrum Master?”
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!!