Best Python code snippet using Airtest
emails.py
Source:emails.py  
...19        return receivers.filter(get_notifications=True)20    return [user for user in receivers if user.get_notifications]21class NotifyCreatorEmail(Email):22    template_name = 'a4_candy_notifications/emails/notify_creator'23    def get_receivers(self):24        action = self.object25        if hasattr(action.target, 'creator'):26            receivers = [action.target.creator]27            receivers = _exclude_notifications_disabled(receivers)28            receivers = _exclude_actor(receivers, action.actor)29            receivers = _exclude_moderators(receivers, action)30            return receivers31        return []32class NotifyCreatorOnModeratorFeedback(Email):33    template_name = \34        'a4_candy_notifications/emails/notify_creator_on_moderator_feedback'35    def get_receivers(self):36        receivers = [self.object.creator]37        receivers = _exclude_notifications_disabled(receivers)38        return receivers39    def get_context(self):40        context = super().get_context()41        context['object'] = self.object42        return context43class NotifyModeratorsEmail(Email):44    template_name = 'a4_candy_notifications/emails/notify_moderator'45    def get_receivers(self):46        action = self.object47        receivers = action.project.moderators.all()48        receivers = _exclude_actor(receivers, action.actor)49        receivers = _exclude_notifications_disabled(receivers)50        return receivers51class NotifyInitiatorsOnProjectCreatedEmail(Email):52    template_name = \53        'a4_candy_notifications/emails/notify_initiators_project_created'54    def get_receivers(self):55        project = self.object56        creator = User.objects.get(pk=self.kwargs['creator_pk'])57        receivers = project.organisation.initiators.all()58        receivers = _exclude_actor(receivers, creator)59        receivers = _exclude_notifications_disabled(receivers)60        return receivers61    def get_context(self):62        context = super().get_context()63        creator = User.objects.get(pk=self.kwargs['creator_pk'])64        context['creator'] = creator65        context['project'] = self.object66        return context67class NotifyFollowersOnPhaseStartedEmail(Email):68    template_name = 'a4_candy_notifications/emails' \69                    '/notify_followers_phase_started'70    def get_receivers(self):71        action = self.object72        receivers = User.objects.filter(73            follow__project=action.project,74            follow__enabled=True,75        )76        receivers = _exclude_notifications_disabled(receivers)77        return receivers78class NotifyFollowersOnPhaseIsOverSoonEmail(Email):79    template_name = 'a4_candy_notifications/emails' \80                    '/notify_followers_phase_over_soon'81    def get_receivers(self):82        action = self.object83        receivers = User.objects.filter(84            follow__project=action.project,85            follow__enabled=True,86        )87        receivers = _exclude_notifications_disabled(receivers)88        return receivers89class NotifyFollowersOnUpcommingEventEmail(Email):90    template_name = 'a4_candy_notifications/emails' \91                    '/notify_followers_event_upcomming'92    def get_receivers(self):93        action = self.object94        receivers = User.objects.filter(95            follow__project=action.project,96            follow__enabled=True,97        )98        receivers = _exclude_notifications_disabled(receivers)...test_config.py
Source:test_config.py  
...37                name='form.detailed_report').value)38        self.assertEqual(config.interval, 'daily')39        self.assertEqual(self.browser.getControl(name='form.interval').value,40                         ['daily'])41        self.assertEqual(config.get_receivers(), [])42        self.assertEqual(self.browser.getControl(name='form.receivers').value,43                         '')44    def test_save_with_defaults(self):45        self.browser.open(self.config_url)46        self.assertEqual(47            self.browser.getControl(name='form.receivers').value, '')48        self.browser.getControl('Save').click()49    def test_change_configuration(self):50        self.browser.open(self.config_url)51        self.browser.getControl(name='form.enabled').value = True52        self.browser.getControl(name='form.detailed_report').value = True53        self.browser.getControl(name='form.interval').value = ('weekly',)54        self.browser.getControl(name='form.receivers').value = '\n'.join((55            'my@test.local',56            'foo@bar.com'))57        self.browser.getControl('Save').click()58        self.assertEqual(self.browser.url, self.config_url)59        self.assertIn('Updated on', self.browser.contents)60        config = INotifierConfigurationSchema(self.portal)61        self.assertTrue(config.enabled)62        self.assertTrue(config.detailed_report)63        self.assertEqual(config.interval, 'weekly')64        self.assertEqual(config.get_receivers(), [65                'my@test.local', 'foo@bar.com'])66    def test_receiver_mail_validation(self):67        self.assertEqual(68            INotifierConfigurationSchema(self.portal).get_receivers(), [])69        self.browser.open(self.config_url)70        self.browser.getControl(name='form.receivers').value = 'not an email'71        self.browser.getControl('Save').click()72        self.assertEqual(self.browser.url, self.config_url)73        self.assertNotIn('Updated on', self.browser.contents)74        self.assertIn('At least one of the defined addresses are not valid.',75                      self.browser.contents)76        self.assertEqual(77            INotifierConfigurationSchema(self.portal).get_receivers(), [])78    def test_cancel_form_redirects_to_publisher_config(self):79        self.browser.open(self.config_url)80        self.assertEqual(self.browser.url, self.config_url)81        self.browser.getControl('Cancel').click()...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!!
